Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/02/19 16:07:07 (6 years ago)
Author:
gkronber
Message:

#2520: use new persistence in ContentManager (with fallback), ClipBoard (with fallback), as well as for deep-cloning in Scripting and for Hive Persistence (without fallback & incomplete)

Location:
branches/2520_PersistenceReintegration
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2520_PersistenceReintegration/HeuristicLab.Clients.Hive/3.3/Util/PersistenceUtil.cs

    r16453 r16480  
    2323using System.Collections.Generic;
    2424using System.IO;
    25 using HeuristicLab.Persistence.Core;
    26 using HeuristicLab.Persistence.Default.Xml;
     25using HEAL.Fossil;
    2726
    2827namespace HeuristicLab.Clients.Hive {
     
    3029    public static byte[] Serialize(object obj, out IEnumerable<Type> types) {
    3130      using (MemoryStream memStream = new MemoryStream()) {
    32         XmlGenerator.Serialize(obj, memStream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types);
    33         byte[] jobByteArray = memStream.ToArray();
    34         return jobByteArray;
     31        throw new NotImplementedException("Not supported by HEAL.Fossil yet."); // TODO
     32        // XmlGenerator.Serialize(obj, memStream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types);
     33        // byte[] jobByteArray = memStream.ToArray();
     34        // return jobByteArray;
    3535      }
    3636    }
    3737
    3838    public static byte[] Serialize(object obj) {
    39       using (MemoryStream memStream = new MemoryStream()) {
    40         XmlGenerator.Serialize(obj, memStream);
    41         byte[] jobByteArray = memStream.ToArray();
    42         return jobByteArray;
    43       }
     39      var ser = new ProtoBufSerializer();
     40      return ser.Serialize(obj);
    4441    }
    4542
    4643    public static T Deserialize<T>(byte[] sjob) {
    47       using (MemoryStream memStream = new MemoryStream(sjob)) {
    48         T job = XmlParser.Deserialize<T>(memStream);
    49         return job;
    50       }
     44      var ser = new ProtoBufSerializer();
     45      return (T)ser.Deserialize(sjob);
    5146    }
    5247  }
  • branches/2520_PersistenceReintegration/HeuristicLab.Core.Views/3.3/Clipboard.cs

    r16453 r16480  
    2828using System.Threading;
    2929using System.Windows.Forms;
     30using HEAL.Fossil;
    3031using HeuristicLab.Common;
    3132using HeuristicLab.MainForm;
     
    156157      foreach (string filename in items) {
    157158        try {
    158           T item = XmlParser.Deserialize<T>(filename);
     159          var ser = new ProtoBufSerializer();
     160          T item = (T)ser.Deserialize(filename);
    159161          OnItemLoaded(item, progressBar.Maximum / items.Length);
    160         }
    161         catch (Exception) { }
     162        } catch (Exception) {
     163          try {
     164            // try old format if protobuf deserialization fails
     165            T item = XmlParser.Deserialize<T>(filename);
     166            OnItemLoaded(item, progressBar.Maximum / items.Length);
     167          } catch (Exception) { }
     168        }
    162169      }
    163170      OnAllItemsLoaded();
     
    199206          i++;
    200207          SetEnabledStateOfContentViews(item, false);
    201           XmlGenerator.Serialize(item, ItemsPath + Path.DirectorySeparatorChar + i.ToString("00000000") + ".hl", CompressionLevel.Optimal);
     208          var ser = new ProtoBufSerializer();
     209          ser.Serialize(item, ItemsPath + Path.DirectorySeparatorChar + i.ToString("00000000") + ".hl");
    202210          OnItemSaved(item, progressBar.Maximum / listView.Items.Count);
    203211        }
  • branches/2520_PersistenceReintegration/HeuristicLab.Core/3.3/PersistenceContentManager.cs

    r16474 r16480  
    3232
    3333    protected override IStorableContent LoadContent(string filename) {
    34       return XmlParser.Deserialize<IStorableContent>(filename);
     34      // first try to load using the new persistence format
     35      try {
     36        var ser = new ProtoBufSerializer();
     37        return (IStorableContent)ser.Deserialize(filename);
     38      } catch (PersistenceException e) {
     39        // try old format if new format fails
     40        return XmlParser.Deserialize<IStorableContent>(filename);
     41      }
    3542    }
    3643
    3744    protected override void SaveContent(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken) {
    38       XmlGenerator.Serialize(content, filename, compressed ? CompressionLevel.Optimal : CompressionLevel.NoCompression, cancellationToken);
     45      // XmlGenerator.Serialize(content, filename, compressed ? CompressionLevel.Optimal : CompressionLevel.NoCompression, cancellationToken);
     46      // store files with the new persistence format
     47      var ser = new ProtoBufSerializer();
     48      ser.Serialize(content, filename); // TODO: support cancellation
    3949    }
    4050  }
  • branches/2520_PersistenceReintegration/HeuristicLab.Scripting/3.3/VariableStore.cs

    r16462 r16480  
    8181    protected T CloneByPersistence<T>(T value) {
    8282      using (var serializerStream = new MemoryStream()) {
    83         XmlGenerator.Serialize(value, serializerStream);
     83        var serializer = new ProtoBufSerializer();
     84        serializer.Serialize(value, serializerStream, disposeStream: false);
    8485        var bytes = serializerStream.GetBuffer();
    8586        using (var deserializerStream = new MemoryStream(bytes)) {
    86           return XmlParser.Deserialize<T>(deserializerStream);
     87          return (T)serializer.Deserialize(deserializerStream);
    8788        }
    8889      }
Note: See TracChangeset for help on using the changeset viewer.