- Timestamp:
- 09/12/11 10:12:50 (13 years ago)
- Location:
- branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/DebugString/DebugStringGenerator.cs
r5445 r6737 169 169 } 170 170 171 protected override string Format(SerializerToken serializerToken) { 172 return string.Empty; 173 } 174 171 175 /// <summary> 172 176 /// Serializes the specified object. -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/EasyXmlGenerator.cs
r5489 r6737 58 58 /// <returns>The token in serialized form.</returns> 59 59 protected override string Format(EndToken endToken) { 60 return CreateNodeEnd( typeCache[endToken.TypeId]);60 return CreateNodeEnd("END"); 61 61 } 62 62 … … 154 154 File.Copy(tempfile, filename, true); 155 155 File.Delete(tempfile); 156 } 157 catch (Exception) { 156 } catch (Exception) { 158 157 Logger.Warn("Exception caught, no data has been written."); 159 158 throw; … … 190 189 writer.Flush(); 191 190 } 192 } 193 catch (PersistenceException) { 191 } catch (PersistenceException) { 194 192 throw; 195 } 196 catch (Exception e) { 193 } catch (Exception e) { 197 194 throw new PersistenceException("Unexpected exception during Serialization.", e); 198 195 } -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r6211 r6737 157 157 AddTypeInfo(beginToken.TypeId, dict); 158 158 return CreateNodeStart(XmlStringConstants.COMPOSITE, dict); 159 160 159 } 161 160 … … 164 163 if (typeId == lastTypeToken.Id) { 165 164 dict.Add("typeName", lastTypeToken.TypeName); 166 dict.Add("serializer", lastTypeToken.Serializer);167 165 lastTypeToken = null; 168 166 } else { 169 167 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(); 170 176 } 171 177 } … … 238 244 239 245 protected TypeToken lastTypeToken; 246 protected SerializerToken lastSerializerToken; 240 247 /// <summary> 241 248 /// Formats the specified token. … … 245 252 protected override string Format(TypeToken token) { 246 253 lastTypeToken = token; 254 return ""; 255 } 256 257 protected override string Format(SerializerToken token) { 258 lastSerializerToken = token; 247 259 return ""; 248 260 } … … 255 267 new Dictionary<string, string> { 256 268 {"id", lastTypeToken.Id.ToString()}, 257 {"typeName", lastTypeToken.TypeName }, 258 {"serializer", lastTypeToken.Serializer }}); 269 {"typeName", lastTypeToken.TypeName }}); 259 270 } finally { 260 271 lastTypeToken = null; … … 262 273 } 263 274 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 264 288 /// <summary> 265 289 /// Formats the specified type cache. … … 267 291 /// <param name="typeCache">The type cache.</param> 268 292 /// <returns>An enumerable of formatted type cache tags.</returns> 269 public IEnumerable<string> Format( List<TypeMapping>typeCache) {293 public IEnumerable<string> Format(TypeCache typeCache) { 270 294 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 } 275 306 yield return CreateNodeEnd(XmlStringConstants.TYPECACHE); 276 307 } … … 342 373 writer.Flush(); 343 374 if (includeAssemblies) { 344 foreach (string name in serializer. RequiredFiles) {375 foreach (string name in serializer.GetRequiredFiles()) { 345 376 Uri uri = new Uri(name); 346 377 if (!uri.IsFile) { -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r6211 r6737 26 26 using System.IO.Compression; 27 27 using System.Xml; 28 using HeuristicLab.Persistence.Auxiliary; 28 29 using HeuristicLab.Persistence.Core; 29 30 using HeuristicLab.Persistence.Core.Tokens; … … 58 59 {XmlStringConstants.METAINFO, ParseMetaInfo}, 59 60 {XmlStringConstants.TYPE, ParseTypeInfo}, 61 {XmlStringConstants.SERIALIZER, ParseSerializer}, 60 62 }; 61 63 } … … 106 108 string serializer = reader.GetAttribute("serializer"); 107 109 if (typeName != null) 108 yield return new TypeToken(typeId, typeName, serializer); 110 yield return new TypeToken(typeId, typeName); 111 if (serializer != null) 112 yield return new SerializerToken(typeId, serializer); 109 113 XmlReader inner = reader.ReadSubtree(); 110 114 inner.Read(); … … 124 128 string serializer = reader.GetAttribute("serializer"); 125 129 if (typeName != null) 126 yield return new TypeToken(typeId, typeName, serializer); 130 yield return new TypeToken(typeId, typeName); 131 if (serializer != null) 132 yield return new SerializerToken(typeId, serializer); 127 133 yield return new BeginToken(name, typeId, id); 128 134 IEnumerator<ISerializationToken> iterator = GetEnumerator(); 129 135 while (iterator.MoveNext()) 130 136 yield return iterator.Current; 131 yield return new EndToken( name, typeId, id);137 yield return new EndToken(); 132 138 } 133 139 … … 151 157 152 158 private IEnumerator<ISerializationToken> ParseTypeInfo() { 153 yield return new TypeToken( 154 int.Parse(reader.GetAttribute("id")), 155 reader.GetAttribute("typeName"), 156 reader.GetAttribute("serializer")); 159 int id = int.Parse(reader.GetAttribute("id")); 160 string typeName = reader.GetAttribute("typeName"); 161 yield return new TypeToken(id, typeName); 162 string serializer = reader.GetAttribute("serializer"); 163 if (serializer != null) 164 yield return new SerializerToken(id, serializer); 165 } 166 167 private IEnumerator<ISerializationToken> ParseSerializer() { 168 int id = int.Parse(reader.GetAttribute("id")); 169 string serializer = reader.GetAttribute("serializer"); 170 yield return new SerializerToken(id, serializer); 157 171 } 158 172 … … 162 176 /// <param name="reader">The reader.</param> 163 177 /// <returns>A list of type mapping entries.</returns> 164 public static List<TypeMapping>ParseTypeCache(TextReader reader) {165 try {166 var typeCache = new List<TypeMapping>();178 public static ReverseTypeCache ParseTypeCache(TextReader reader) { 179 ReverseTypeCache typeCache = new ReverseTypeCache(); 180 try { 167 181 XmlReader xmlReader = XmlReader.Create(reader); 168 182 while (xmlReader.Read()) { 169 183 if (xmlReader.Name == XmlStringConstants.TYPE) { 170 typeCache.Add(new TypeMapping( 184 int id = int.Parse(xmlReader.GetAttribute("id")); 185 typeCache.AddType(id, TypeLoader.Load(xmlReader.GetAttribute("typeName"))); 186 string serializer = xmlReader.GetAttribute("serializer"); 187 if (serializer != null) 188 typeCache.AddSerializer(id, TypeLoader.Load(serializer)); 189 } else if (xmlReader.Name == XmlStringConstants.SERIALIZER) { 190 typeCache.AddSerializer( 171 191 int.Parse(xmlReader.GetAttribute("id")), 172 xmlReader.GetAttribute("typeName"), 173 xmlReader.GetAttribute("serializer"))); 192 TypeLoader.Load(xmlReader.GetAttribute("serializer"))); 174 193 } 175 194 } … … 221 240 using (StreamReader reader = new StreamReader(new GZipStream(stream, CompressionMode.Decompress))) { 222 241 XmlParser parser = new XmlParser(reader); 223 Deserializer deserializer = new Deserializer(new TypeMapping[] { });242 Deserializer deserializer = new Deserializer(new ReverseTypeCache()); 224 243 return deserializer.Deserialize(new AsyncBuffer<ISerializationToken>(parser)); 225 244 } -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/XmlStringConstants.cs
r5445 r6737 30 30 public const string TYPECACHE = "TYPECACHE"; 31 31 public const string TYPE = "TYPE"; 32 public const string SERIALIZER = "SERIALIZER"; 32 33 public const string METAINFO = "METAINFO"; 33 34 }
Note: See TracChangeset
for help on using the changeset viewer.