Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/24/19 19:22:44 (6 years ago)
Author:
gkronber
Message:

#2520 for Hive serialization: added collection of serialized types and fall-back to old persistence format on deserialization. ITask must be a StorableType

File:
1 edited

Legend:

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

    r16480 r16553  
    2424using System.IO;
    2525using HEAL.Fossil;
     26using HeuristicLab.Persistence.Default.Xml;
    2627
    2728namespace HeuristicLab.Clients.Hive {
    2829  public static class PersistenceUtil {
    2930    public static byte[] Serialize(object obj, out IEnumerable<Type> types) {
    30       using (MemoryStream memStream = new MemoryStream()) {
    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;
    35       }
     31      var ser = new ProtoBufSerializer();
     32      return ser.Serialize(obj, out types);
    3633    }
    3734
     
    4340    public static T Deserialize<T>(byte[] sjob) {
    4441      var ser = new ProtoBufSerializer();
    45       return (T)ser.Deserialize(sjob);
     42      try {
     43        return (T)ser.Deserialize(sjob);
     44      } catch (Exception) {
     45        // retry with old persistence
     46        using (MemoryStream memStream = new MemoryStream(sjob)) {
     47          return XmlParser.Deserialize<T>(memStream);
     48        }
     49      }
    4650    }
    4751  }
Note: See TracChangeset for help on using the changeset viewer.