Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/12/11 10:12:50 (13 years ago)
Author:
epitzer
Message:

#1530 Split type and serializer tokens and include special handling for CachedTypeSerializer (this should also fix #1527)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs

    r6211 r6737  
    157157      AddTypeInfo(beginToken.TypeId, dict);
    158158      return CreateNodeStart(XmlStringConstants.COMPOSITE, dict);
    159 
    160159    }
    161160
     
    164163        if (typeId == lastTypeToken.Id) {
    165164          dict.Add("typeName", lastTypeToken.TypeName);
    166           dict.Add("serializer", lastTypeToken.Serializer);
    167165          lastTypeToken = null;
    168166        } else {
    169167          FlushTypeToken();
     168        }
     169      }
     170      if (lastSerializerToken != null) {
     171        if (typeId == lastSerializerToken.Id) {
     172          dict.Add("serializer", lastSerializerToken.Serializer);
     173          lastSerializerToken = null;
     174        } else {
     175          FlushSerializerToken();
    170176        }
    171177      }
     
    238244
    239245    protected TypeToken lastTypeToken;
     246    protected SerializerToken lastSerializerToken;
    240247    /// <summary>
    241248    /// Formats the specified token.
     
    245252    protected override string Format(TypeToken token) {
    246253      lastTypeToken = token;
     254      return "";
     255    }
     256
     257    protected override string Format(SerializerToken token) {
     258      lastSerializerToken = token;
    247259      return "";
    248260    }
     
    255267          new Dictionary<string, string> {
    256268          {"id", lastTypeToken.Id.ToString()},
    257           {"typeName", lastTypeToken.TypeName },
    258           {"serializer", lastTypeToken.Serializer }});
     269          {"typeName", lastTypeToken.TypeName }});
    259270      } finally {
    260271        lastTypeToken = null;
     
    262273    }
    263274
     275    protected string FlushSerializerToken() {
     276      if (lastSerializerToken == null)
     277        return "";
     278      try {
     279        return CreateNode(XmlStringConstants.SERIALIZER,
     280          new Dictionary<string, string> {
     281          {"id", lastSerializerToken.Id.ToString()},
     282          {"serializer", lastSerializerToken.Serializer }});
     283      } finally {
     284        lastTypeToken = null;
     285      }
     286    }
     287
    264288    /// <summary>
    265289    /// Formats the specified type cache.
     
    267291    /// <param name="typeCache">The type cache.</param>
    268292    /// <returns>An enumerable of formatted type cache tags.</returns>
    269     public IEnumerable<string> Format(List<TypeMapping> typeCache) {
     293    public IEnumerable<string> Format(TypeCache typeCache) {
    270294      yield return CreateNodeStart(XmlStringConstants.TYPECACHE);
    271       foreach (var mapping in typeCache)
    272         yield return CreateNode(
    273           XmlStringConstants.TYPE,
    274           mapping.GetDict());
     295      foreach (var type in typeCache.Types) {
     296        int id = typeCache.GetOrCreateId(type);
     297        var dict = new Dictionary<string, string> {
     298          {"id", id.ToString()},
     299          {"typeName", type.AssemblyQualifiedName},
     300        };
     301        Type serializer = typeCache.GetSerializer(id);
     302        if (serializer != null)
     303          dict.Add("serializer", serializer.AssemblyQualifiedName);
     304        yield return CreateNode(XmlStringConstants.TYPE, dict);
     305      }
    275306      yield return CreateNodeEnd(XmlStringConstants.TYPECACHE);
    276307    }
     
    342373            writer.Flush();
    343374            if (includeAssemblies) {
    344               foreach (string name in serializer.RequiredFiles) {
     375              foreach (string name in serializer.GetRequiredFiles()) {
    345376                Uri uri = new Uri(name);
    346377                if (!uri.IsFile) {
Note: See TracChangeset for help on using the changeset viewer.