Changeset 14771 for branches/PersistenceOverhaul/HeuristicLab.Persistence
- Timestamp:
- 03/20/17 15:56:55 (8 years ago)
- 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 37 37 38 38 public Guid Guid { get; private set; } 39 public bool Released{ get; set; }39 public uint Version { get; set; } 40 40 41 41 /// <summary> … … 43 43 /// </summary> 44 44 /// <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) { 46 46 MemberSelection = memberSelection; 47 47 Guid = new Guid(guid); 48 Released = false;48 Version = version; 49 49 } 50 50 51 public StorableTypeAttribute(string guid ) {51 public StorableTypeAttribute(string guid, uint version = 1) { 52 52 Guid = new Guid(guid); 53 Released = false;53 Version = version; 54 54 } 55 55 -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Core/Mapper.cs
r14711 r14771 95 95 } 96 96 97 public Box GetBox(uint boxId) { 98 return boxId2Box[boxId]; 99 } 97 100 public uint GetBoxId(object o) { 98 101 uint boxId; -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/HeuristicLab.Persistence-4.0.csproj
r14537 r14771 55 55 <Compile Include="Core\Serializer.cs" /> 56 56 <Compile Include="Core\Transformer.cs" /> 57 <Compile Include="Core\StorableConversionAttribute.cs" /> 57 58 <Compile Include="Core\TransformerAttribute.cs" /> 58 59 <Compile Include="Core\TypeInfo.cs" /> -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Protos/PersistenceMessages.proto
r14537 r14771 11 11 message Box { 12 12 optional uint32 transformer_id = 1; 13 optional uint32 type_id = 2; 13 optional uint32 type_id = 2; 14 14 15 15 extensions 100 to max; … … 177 177 required TypeBox type = 250; 178 178 } 179 repeated uint32 generic_type_ids = 1 [packed = true]; 179 optional uint32 version = 1; 180 repeated uint32 generic_type_ids = 2 [packed = true]; 180 181 } 181 182 -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StorableClassTransformer.cs
r14713 r14771 70 70 var type = obj.GetType(); 71 71 var typeInfo = Mapper.StaticCache.GetTypeInfo(type); 72 var typeBox = mapper.GetBox(box.TypeId).GetExtension(TypeBox.Type); 73 var version = typeBox.HasVersion ? typeBox.Version : 1; 72 74 73 75 var components = new Dictionary<uint, uint>(); … … 76 78 } 77 79 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 78 97 foreach (var componentInfo in typeInfo.Fields) { 79 98 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); 82 101 if (found) 83 field.SetValue(obj, mapper.GetObject(componentId));102 field.SetValue(obj, val); 84 103 else if (componentInfo.StorableAttribute.DefaultValue != null) 85 104 field.SetValue(obj, componentInfo.StorableAttribute.DefaultValue); … … 88 107 foreach (var componentInfo in typeInfo.Properties.Where(x => x.Writeable)) { 89 108 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); 92 111 if (found) 93 property.SetValue(obj, mapper.GetObject(componentId), null);112 property.SetValue(obj, val, null); 94 113 else if (componentInfo.StorableAttribute.DefaultValue != null) 95 114 property.SetValue(obj, componentInfo.StorableAttribute.DefaultValue, null); -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/Transformers.cs
r14711 r14771 299 299 box.TypeId = mapper.GetTypeId(type); 300 300 } 301 302 if (StorableTypeAttribute.IsStorableType(type)) 303 typeBox.Version = StorableTypeAttribute.GetStorableTypeAttribute(type).Version; 301 304 box.SetExtension(TypeBox.Type, typeBox.Build()); 302 305 }
Note: See TracChangeset
for help on using the changeset viewer.