Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/11/10 15:50:50 (14 years ago)
Author:
epitzer
Message:

add support for type information interleaving and subsequently true streaming (#548)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs

    r3004 r3005  
    7777      parentStack = new Stack<Midwife>();
    7878      typeIds = new Dictionary<int, Type>();
    79       serializerMapping = CreateSerializers(typeCache);
    80     }
    81 
    82     private Dictionary<Type, object> CreateSerializers(IEnumerable<TypeMapping> typeCache) {
    83       Dictionary<Type, object> serializerInstances = new Dictionary<Type, object>();
     79      serializerMapping = new Dictionary<Type, object>();
     80      foreach (var typeMapping in typeCache) {
     81        AddTypeInfo(typeMapping);
     82      }
     83    }
     84
     85    private Dictionary<Type, object> serializerInstances = new Dictionary<Type, object>();   
     86
     87    public void AddTypeInfo(TypeMapping typeMapping) {
     88      if (typeIds.ContainsKey(typeMapping.Id))
     89        return;
    8490      try {
    85         var map = new Dictionary<Type, object>();
    86         foreach (var typeMapping in typeCache) {
    87           Type type = TypeLoader.Load(typeMapping.TypeName);
    88           typeIds.Add(typeMapping.Id, type);
    89           Type serializerType = TypeLoader.Load(typeMapping.Serializer);
    90           object serializer;
    91           if (serializerInstances.ContainsKey(serializerType))
    92             serializer = serializerInstances[serializerType];
    93           else
    94             serializer = Activator.CreateInstance(serializerType, true);
    95           map.Add(type, serializer);
    96         }
    97         return map;
     91        Type type = TypeLoader.Load(typeMapping.TypeName);
     92        typeIds.Add(typeMapping.Id, type);
     93        Type serializerType = TypeLoader.Load(typeMapping.Serializer);
     94        object serializer;
     95        if (serializerInstances.ContainsKey(serializerType))
     96          serializer = serializerInstances[serializerType];
     97        else
     98          serializer = Activator.CreateInstance(serializerType, true);
     99        serializerMapping.Add(type, serializer);
    98100      } catch (PersistenceException) {
    99101        throw;
    100102      } catch (Exception e) {
    101         throw new PersistenceException(
    102           "The serialization type cache could not be loaded.\r\n" +
    103           "This usualy happens when you are missing an Assembly or Plugin.", e);
     103        throw new PersistenceException(string.Format(
     104          "Could not add type info for {0} ({1})",
     105          typeMapping.TypeName, typeMapping.Serializer), e);
    104106      }
    105107    }
     
    125127        } else if (t == typeof(MetaInfoEndToken)) {
    126128          MetaInfoEnd((MetaInfoEndToken)token);
     129        } else if (t == typeof(TypeToken)) {
     130          Type((TypeToken)token);
    127131        } else {
    128132          throw new PersistenceException("invalid token type");
     
    138142      if (!m.MetaMode && m.Obj == null)
    139143        CreateInstance(m);
     144    }
     145
     146    private void Type(TypeToken token) {
     147      AddTypeInfo(new TypeMapping(token.Id, token.TypeName, token.Serializer));
    140148    }
    141149
Note: See TracChangeset for help on using the changeset viewer.