- Timestamp:
- 04/23/09 14:22:29 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r1616 r1625 42 42 iterator = handlers[reader.Name].Invoke(); 43 43 } catch (KeyNotFoundException) { 44 throw new InvalidOperationException(String.Format(45 " No handler for XML tag \"{0}\" installed",44 throw new PersistenceException(String.Format( 45 "Invalid XML tag \"{0}\" in persistence file.", 46 46 reader.Name)); 47 47 } … … 103 103 104 104 public static List<TypeMapping> ParseTypeCache(TextReader reader) { 105 var typeCache = new List<TypeMapping>(); 106 XmlReader xmlReader = XmlReader.Create(reader); 107 while (xmlReader.Read()) { 108 if (xmlReader.Name == XmlStringConstants.TYPE) { 109 typeCache.Add(new TypeMapping( 110 int.Parse(xmlReader.GetAttribute("id")), 111 xmlReader.GetAttribute("typeName"), 112 xmlReader.GetAttribute("serializer"))); 105 try { 106 var typeCache = new List<TypeMapping>(); 107 XmlReader xmlReader = XmlReader.Create(reader); 108 while (xmlReader.Read()) { 109 if (xmlReader.Name == XmlStringConstants.TYPE) { 110 typeCache.Add(new TypeMapping( 111 int.Parse(xmlReader.GetAttribute("id")), 112 xmlReader.GetAttribute("typeName"), 113 xmlReader.GetAttribute("serializer"))); 114 } 113 115 } 116 return typeCache; 117 } catch (PersistenceException e) { 118 throw; 119 } catch (Exception e) { 120 throw new PersistenceException("Unexpected exception during type cache parsing.", e); 114 121 } 115 return typeCache;116 122 } 117 123 118 124 public static object DeSerialize(string filename) { 119 ZipFile zipFile = new ZipFile(filename); 120 Deserializer deSerializer = new Deserializer( 121 ParseTypeCache( 122 new StreamReader( 123 zipFile.GetInputStream(zipFile.GetEntry("typecache.xml"))))); 124 XmlParser parser = new XmlParser( 125 new StreamReader(zipFile.GetInputStream(zipFile.GetEntry("data.xml")))); 126 object result = deSerializer.Deserialize(parser); 127 zipFile.Close(); 128 return result; 125 try { 126 ZipFile zipFile = new ZipFile(filename); 127 Deserializer deSerializer = new Deserializer( 128 ParseTypeCache( 129 new StreamReader( 130 zipFile.GetInputStream(zipFile.GetEntry("typecache.xml"))))); 131 XmlParser parser = new XmlParser( 132 new StreamReader(zipFile.GetInputStream(zipFile.GetEntry("data.xml")))); 133 object result = deSerializer.Deserialize(parser); 134 zipFile.Close(); 135 return result; 136 } catch (PersistenceException e) { 137 throw; 138 } catch (Exception e) { 139 throw new PersistenceException("Unexpected exception during deserialization", e); 140 } 129 141 } 130 142 }
Note: See TracChangeset
for help on using the changeset viewer.