Changeset 2143 for trunk/sources/HeuristicLab.Core/3.2
- Timestamp:
- 07/07/09 02:24:34 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Core/3.2
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.2/EditorBase.cs
r1529 r2143 27 27 using System.Text; 28 28 using System.Windows.Forms; 29 using System.Threading; 29 30 30 31 namespace HeuristicLab.Core { … … 57 58 58 59 /// <summary> 60 /// Saves the contained item to a file. 61 /// </summary> 62 /// <remarks> 63 /// The filename to save the contained item to is given by <see cref="Filename"/>. 64 /// Save is an asynchronous method. After saving the contained item is finished, the 65 /// <see cref="SaveFinished"/> event is fired. 66 /// </remarks> 67 public void Save() { 68 Enabled = false; 69 ThreadPool.QueueUserWorkItem((o) => { 70 try { 71 PersistenceManager.Save(Item, Filename); 72 } 73 catch (Exception e) { 74 MessageBox.Show(String.Format( 75 "Sorry couldn't save file \"{0}\".\n The following exception occurred: {1}", 76 Filename, e.ToString()), 77 "Writer Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 78 } 79 finally { 80 Invoke(new Action(() => Enabled = true)); 81 OnSaveFinished(); 82 } 83 }); 84 } 85 86 /// <summary> 59 87 /// Updates all controls with the latest data of the model. 60 88 /// </summary> … … 79 107 FilenameChanged(this, new EventArgs()); 80 108 } 109 /// <summary> 110 /// Occurs when the filename was changed. 111 /// </summary> 112 public event EventHandler SaveFinished; 113 /// <summary> 114 /// Fires the <see cref="SaveFinished"/> event. 115 /// </summary> 116 protected virtual void OnSaveFinished() { 117 if (SaveFinished != null) 118 SaveFinished(this, new EventArgs()); 119 } 81 120 } 82 121 } -
trunk/sources/HeuristicLab.Core/3.2/HeuristicLab.Core-3.2.csproj
r1534 r2143 32 32 <UseApplicationTrust>false</UseApplicationTrust> 33 33 <BootstrapperEnabled>true</BootstrapperEnabled> 34 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 34 35 </PropertyGroup> 35 36 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> … … 90 91 <ItemGroup> 91 92 <Reference Include="System" /> 93 <Reference Include="System.Core"> 94 <RequiredTargetFramework>3.5</RequiredTargetFramework> 95 </Reference> 92 96 <Reference Include="System.Data" /> 93 97 <Reference Include="System.Drawing" /> -
trunk/sources/HeuristicLab.Core/3.2/Interfaces/IEditor.cs
r776 r2143 36 36 37 37 /// <summary> 38 /// Saves the contained item to a file. 39 /// </summary> 40 /// <remarks> 41 /// The filename to save the contained item to is given by <see cref="Filename"/>. 42 /// Save is an asynchronous method. After saving the contained item is finished, the 43 /// <see cref="SaveFinished"/> event is fired. 44 /// </remarks> 45 void Save(); 46 47 /// <summary> 38 48 /// Occurs when the filename was changed. 39 49 /// </summary> 40 50 event EventHandler FilenameChanged; 51 /// <summary> 52 /// Occurs after saving the contained object is finished. 53 /// </summary> 54 event EventHandler SaveFinished; 41 55 } 42 56 } -
trunk/sources/HeuristicLab.Core/3.2/PersistenceManager.cs
r1722 r2143 108 108 /// <param name="filename">The name of the file where the <paramref name="object"/> should be saved.</param> 109 109 public static void Save(IStorable instance, string filename) { 110 using(FileStream stream = File.Create(filename)) { 110 string tempfile = Path.GetTempFileName(); 111 using (FileStream stream = File.Create(tempfile)) { 111 112 Save(instance, stream); 112 113 stream.Close(); 113 114 } 115 File.Copy(tempfile, filename, true); 116 File.Delete(tempfile); 114 117 } 115 118 /// <summary>
Note: See TracChangeset
for help on using the changeset viewer.