Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/18/19 23:17:19 (5 years ago)
Author:
mkommend
Message:

#2520: Changed samples to attic format and adapted startpage to load the samples with attic without the creation of temporary files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Optimizer/3.3/StartPage.cs

    r16992 r17022  
    2323using System.Collections.Generic;
    2424using System.IO;
     25using System.IO.Compression;
    2526using System.Linq;
    2627using System.Reflection;
    2728using System.Threading;
    2829using System.Windows.Forms;
     30using HEAL.Attic;
    2931using HeuristicLab.Common;
    3032using HeuristicLab.Core;
     
    116118
    117119    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);
    123125          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 file
    129126        }
    130127      }
     
    198195      Properties.Settings.Default.Save();
    199196    }
    200 
    201     #region Helpers
    202     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     #endregion
    208197  }
    209198}
Note: See TracChangeset for help on using the changeset viewer.