Changeset 17022 for trunk/HeuristicLab.Optimizer/3.3/StartPage.cs
- Timestamp:
- 06/18/19 23:17:19 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Optimizer/3.3/StartPage.cs
r16992 r17022 23 23 using System.Collections.Generic; 24 24 using System.IO; 25 using System.IO.Compression; 25 26 using System.Linq; 26 27 using System.Reflection; 27 28 using System.Threading; 28 29 using System.Windows.Forms; 30 using HEAL.Attic; 29 31 using HeuristicLab.Common; 30 32 using HeuristicLab.Core; … … 116 118 117 119 private void LoadSample(string name, Assembly assembly, ListViewGroup group, int count) { 118 string path = Path.GetTempFileName();119 try {120 using (var stream = assembly.GetManifestResourceStream(name)) {121 WriteStreamToTempFile(stream, path); // create a file in a temporary folder (persistence cannot load these files directly from the stream)122 var item = ( INamedItem)ContentManager.Load(path);120 using (var stream = assembly.GetManifestResourceStream(name)) { 121 var serializer = new ProtoBufSerializer(); 122 // TODO remove deflateStream with next release of HEAL.Attic 123 using (var deflateStream = new DeflateStream(stream, CompressionMode.Decompress, true)) { 124 var item = (NamedItem)serializer.Deserialize(deflateStream, false); 123 125 OnSampleLoaded(item, group, 1.0 / count); 124 }125 } catch (Exception) {126 } finally {127 if (File.Exists(path)) {128 File.Delete(path); // make sure we remove the temporary file129 126 } 130 127 } … … 198 195 Properties.Settings.Default.Save(); 199 196 } 200 201 #region Helpers202 private void WriteStreamToTempFile(Stream stream, string path) {203 using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write)) {204 stream.CopyTo(output);205 }206 }207 #endregion208 197 } 209 198 }
Note: See TracChangeset
for help on using the changeset viewer.