Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/27/09 18:12:38 (15 years ago)
Author:
epitzer
Message:

Refactor saving into IEditor and provide choice of compressed and uncompressed HeuristicLab archives during saving (#646)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/EditorBase.cs

    r1529 r1921  
    2626using System.Data;
    2727using System.Text;
     28using System.Threading;
    2829using System.Windows.Forms;
    2930
     
    4950
    5051    /// <summary>
     52    /// Gets or sets, if the contained item should be compressed.
     53    /// </summary>
     54    public bool Compressed { get; set; }
     55
     56    /// <summary>
    5157    /// Initializes a new instance of <see cref="EditorBase"/> with the caption "Editor".
    5258    /// </summary>
     
    5460      InitializeComponent();
    5561      Caption = "Editor";
     62    }
     63
     64    /// <summary>
     65    /// Asynchronously saves the contained object to a file.
     66    /// </summary>
     67    /// <remarks>The filename to save the contained item to is given by <see cref="Filename"/>.</remarks>
     68    public void Save() {
     69      Enabled = false;
     70      ThreadPool.QueueUserWorkItem((o) => {
     71        try {
     72          if (Compressed)
     73            PersistenceManager.SaveCompressed(Item, Filename);
     74          else
     75            PersistenceManager.Save(Item, Filename);
     76        } catch (Exception e) {
     77          MessageBox.Show(String.Format(
     78            "Sorry couldn't save file \"{0}\".\n The following exception occurred: {1}",
     79            Filename, e.ToString()),
     80            "Reader Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     81        } finally {
     82          Invoke(new Action(() => Enabled = true));
     83          OnSaveFinished();
     84        }
     85      });
    5686    }
    5787
     
    79109        FilenameChanged(this, new EventArgs());
    80110    }
     111
     112    /// <summary>
     113    /// Occurs after a save operation is finished.
     114    /// </summary>
     115    public event EventHandler SaveFinished;
     116
     117    /// <summary>
     118    /// Fires a new <c>SaveFinished</c> event.
     119    /// </summary>
     120    protected virtual void OnSaveFinished() {
     121      SaveFinished(this, new EventArgs());
     122    }
    81123  }
    82124}
Note: See TracChangeset for help on using the changeset viewer.