Changeset 1466 for trunk/sources/HeuristicLab.Persistence/Default/Xml
- Timestamp:
- 03/30/09 15:06:13 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/Default/Xml
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/Default/Xml/XmlGenerator.cs
r1454 r1466 5 5 using HeuristicLab.Persistence.Core; 6 6 using System.IO; 7 using ICSharpCode.SharpZipLib.Zip; 7 8 8 9 namespace HeuristicLab.Persistence.Default.Xml { … … 88 89 {"id", beginToken.Id}}; 89 90 string result = Prefix + 90 FormatNode(XmlStrings.COMPOSITE, attributes, NodeType.Start) + "\ n";91 FormatNode(XmlStrings.COMPOSITE, attributes, NodeType.Start) + "\r\n"; 91 92 depth += 1; 92 93 return result; … … 95 96 protected override string Format(EndToken endToken) { 96 97 depth -= 1; 97 return Prefix + "</" + XmlStrings.COMPOSITE + ">\ n";98 return Prefix + "</" + XmlStrings.COMPOSITE + ">\r\n"; 98 99 } 99 100 … … 106 107 return Prefix + 107 108 FormatNode(XmlStrings.PRIMITIVE, attributes, NodeType.Start) + 108 dataToken.SerialData + "</" + XmlStrings.PRIMITIVE + ">\ n";109 dataToken.SerialData + "</" + XmlStrings.PRIMITIVE + ">\r\n"; 109 110 } 110 111 … … 113 114 {"ref", refToken.Id}, 114 115 {"name", refToken.Name}}; 115 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\ n";116 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\r\n"; 116 117 } 117 118 … … 119 120 var attributes = new Dictionary<string, object>{ 120 121 {"name", nullRefToken.Name}}; 121 return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\ n";122 return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\r\n"; 122 123 } 123 124 … … 129 130 mapping.GetDict(), 130 131 NodeType.Inline, 131 "\ n ");132 "\r\n "); 132 133 yield return "</" + XmlStrings.TYPECACHE + ">"; 133 134 } … … 137 138 } 138 139 139 public static void Serialize(object o, string basename, Configuration configuration) { 140 Serializer s = new Serializer(o, configuration); 141 XmlGenerator xmlGenerator = new XmlGenerator(); 142 StreamWriter writer = new StreamWriter(basename + ".xml"); 143 foreach (ISerializationToken token in s) { 144 string line = xmlGenerator.Format(token); 145 writer.Write(line); 146 Console.Out.Write(line); 147 } 148 writer.Close(); 149 writer = new StreamWriter(basename + "-types.xml"); 150 foreach (string line in xmlGenerator.Format(s.TypeCache)) { 140 public static void Serialize(object obj, string filename, Configuration config) { 141 Serializer serializer = new Serializer(obj, config); 142 XmlGenerator generator = new XmlGenerator(); 143 ZipOutputStream zipStream = new ZipOutputStream(File.Create(filename)); 144 zipStream.SetLevel(9); 145 zipStream.PutNextEntry(new ZipEntry("data.xml")); 146 StreamWriter writer = new StreamWriter(zipStream); 147 foreach ( ISerializationToken token in serializer ) 148 writer.Write(generator.Format(token)); 149 writer.Flush(); 150 zipStream.PutNextEntry(new ZipEntry("typecache.xml")); 151 writer = new StreamWriter(zipStream); 152 foreach ( string line in generator.Format(serializer.TypeCache)) 151 153 writer.WriteLine(line); 152 Console.Out.WriteLine(line); 153 } 154 writer.Close(); 154 writer.Flush(); 155 zipStream.Close(); 155 156 } 156 157 -
trunk/sources/HeuristicLab.Persistence/Default/Xml/XmlParser.cs
r1454 r1466 6 6 using HeuristicLab.Persistence.Core; 7 7 using HeuristicLab.Persistence.Interfaces; 8 using ICSharpCode.SharpZipLib.Zip; 8 9 9 10 namespace HeuristicLab.Persistence.Default.Xml { … … 105 106 } 106 107 107 public static object DeSerialize(string basename) { 108 public static object DeSerialize(string filename) { 109 ZipFile zipFile = new ZipFile(filename); 108 110 DeSerializer deSerializer = new DeSerializer( 109 ParseTypeCache(new StreamReader(basename + "-types.xml"))); 110 XmlParser parser = new XmlParser(new StreamReader(basename + ".xml")); 111 ParseTypeCache( 112 new StreamReader( 113 zipFile.GetInputStream(zipFile.GetEntry("typecache.xml"))))); 114 XmlParser parser = new XmlParser( 115 new StreamReader(zipFile.GetInputStream(zipFile.GetEntry("data.xml")))); 111 116 return deSerializer.DeSerialize(parser); 112 117 }
Note: See TracChangeset
for help on using the changeset viewer.