Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/20/17 15:56:55 (8 years ago)
Author:
gkronber
Message:

#2520 added versions to storable types and implemented conversion unit test

Location:
branches/PersistenceOverhaul/HeuristicLab.Persistence
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableTypeAttribute.cs

    r14711 r14771  
    3737
    3838    public Guid Guid { get; private set; }
    39     public bool Released { get; set; }
     39    public uint Version { get; set; }
    4040
    4141    /// <summary>
     
    4343    /// </summary>
    4444    /// <param name="memberSelection">The storable class memberSelection.</param>
    45     public StorableTypeAttribute(StorableMemberSelection memberSelection, string guid) {
     45    public StorableTypeAttribute(StorableMemberSelection memberSelection, string guid, uint version = 1) {
    4646      MemberSelection = memberSelection;
    4747      Guid = new Guid(guid);
    48       Released = false;
     48      Version = version;
    4949    }
    5050
    51     public StorableTypeAttribute(string guid) {
     51    public StorableTypeAttribute(string guid, uint version = 1) {
    5252      Guid = new Guid(guid);
    53       Released = false;
     53      Version = version;
    5454    }
    5555
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Mapper.cs

    r14711 r14771  
    9595    }
    9696
     97    public Box GetBox(uint boxId) {
     98      return boxId2Box[boxId];
     99    }
    97100    public uint GetBoxId(object o) {
    98101      uint boxId;
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/HeuristicLab.Persistence-4.0.csproj

    r14537 r14771  
    5555    <Compile Include="Core\Serializer.cs" />
    5656    <Compile Include="Core\Transformer.cs" />
     57    <Compile Include="Core\StorableConversionAttribute.cs" />
    5758    <Compile Include="Core\TransformerAttribute.cs" />
    5859    <Compile Include="Core\TypeInfo.cs" />
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/PersistenceMessages.proto

    r14537 r14771  
    1111message Box {
    1212  optional uint32 transformer_id = 1;
    13   optional uint32 type_id = 2;
     13  optional uint32 type_id = 2; 
    1414
    1515  extensions 100 to max;
     
    177177    required TypeBox type = 250;
    178178  }
    179   repeated uint32 generic_type_ids = 1 [packed = true];
     179  optional uint32 version = 1;
     180  repeated uint32 generic_type_ids = 2 [packed = true];
    180181}
    181182
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StorableClassTransformer.cs

    r14713 r14771  
    7070      var type = obj.GetType();
    7171      var typeInfo = Mapper.StaticCache.GetTypeInfo(type);
     72      var typeBox = mapper.GetBox(box.TypeId).GetExtension(TypeBox.Type);
     73      var version = typeBox.HasVersion ? typeBox.Version : 1;
    7274
    7375      var components = new Dictionary<uint, uint>();
     
    7678      }
    7779
     80      var conversionMethods =
     81        type.GetMethods(BindingFlags.NonPublic | BindingFlags.Static)
     82          .Where(StorableConversionAttribute.IsStorableConversionMethod)
     83          .Where(mi => StorableConversionAttribute.GetVersion(mi) >= version)
     84          .OrderBy(StorableConversionAttribute.GetVersion);
     85
     86      // put all objects into dictionary for optional conversion
     87      var dict = new Dictionary<string, object>();
     88      foreach (var component in components) {
     89        dict.Add(mapper.GetString(component.Key), mapper.GetObject(component.Value));
     90      }
     91     
     92      // TODO: check that all entries in the dictionary can be mapped to a field or property
     93      foreach (var convMeth in conversionMethods) {
     94        dict = (Dictionary<string, object>)convMeth.Invoke(null, new object[] { dict });
     95      }
     96
    7897      foreach (var componentInfo in typeInfo.Fields) {
    7998        var field = (FieldInfo)componentInfo.MemberInfo;
    80         uint componentId;
    81         bool found = components.TryGetValue(mapper.GetStringId(componentInfo.Name), out componentId);
     99        object val = null;
     100        bool found = dict.TryGetValue(componentInfo.Name, out val);
    82101        if (found)
    83           field.SetValue(obj, mapper.GetObject(componentId));
     102          field.SetValue(obj, val);
    84103        else if (componentInfo.StorableAttribute.DefaultValue != null)
    85104          field.SetValue(obj, componentInfo.StorableAttribute.DefaultValue);
     
    88107      foreach (var componentInfo in typeInfo.Properties.Where(x => x.Writeable)) {
    89108        var property = (PropertyInfo)componentInfo.MemberInfo;
    90         uint componentId;
    91         bool found = components.TryGetValue(mapper.GetStringId(componentInfo.Name), out componentId);
     109        object val = null;
     110        bool found = dict.TryGetValue(componentInfo.Name, out val);
    92111        if (found)
    93           property.SetValue(obj, mapper.GetObject(componentId), null);
     112          property.SetValue(obj, val, null);
    94113        else if (componentInfo.StorableAttribute.DefaultValue != null)
    95114          property.SetValue(obj, componentInfo.StorableAttribute.DefaultValue, null);
  • branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/Transformers.cs

    r14711 r14771  
    299299        box.TypeId = mapper.GetTypeId(type);
    300300      }
     301
     302      if (StorableTypeAttribute.IsStorableType(type))
     303        typeBox.Version = StorableTypeAttribute.GetStorableTypeAttribute(type).Version;
    301304      box.SetExtension(TypeBox.Type, typeBox.Build());
    302305    }
Note: See TracChangeset for help on using the changeset viewer.