Changeset 1466 for trunk/sources
- Timestamp:
- 03/30/09 15:06:13 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence.Test/NewSerializationTest.cs
r1463 r1466 166 166 r.dict.Add("three", 3); 167 167 r.myEnum = TestEnum.va1; 168 XmlGenerator.Serialize(r, "test ");169 object o = XmlParser.DeSerialize("test ");168 XmlGenerator.Serialize(r, "test.zip"); 169 object o = XmlParser.DeSerialize("test.zip"); 170 170 Console.Out.WriteLine(Util.AutoFormat(o, true)); 171 171 Console.WriteLine(ViewOnlyGenerator.Serialize(r)); … … 180 180 c.allCs = cs; 181 181 c.kvpList = new KeyValuePair<List<C>, C>(new List<C> { c }, c); 182 XmlGenerator.Serialize(cs, "test3 ");183 object o = XmlParser.DeSerialize("test3 ");182 XmlGenerator.Serialize(cs, "test3.zip"); 183 object o = XmlParser.DeSerialize("test3.zip"); 184 184 Console.Out.WriteLine(Util.AutoFormat(o, true)); 185 185 Console.WriteLine(ViewOnlyGenerator.Serialize(cs)); … … 201 201 new[] { 1, 2 }, new[] { 3, 4 }); 202 202 arrayListArray[2].Add(a); 203 XmlGenerator.Serialize(arrayListArray, "test4 ");204 object o = XmlParser.DeSerialize("test4 ");203 XmlGenerator.Serialize(arrayListArray, "test4.zip"); 204 object o = XmlParser.DeSerialize("test4.zip"); 205 205 Console.Out.WriteLine(Util.AutoFormat(o, true)); 206 206 Console.WriteLine(ViewOnlyGenerator.Serialize(arrayListArray)); … … 210 210 public static void Test2() { 211 211 Manager m = new Manager(); 212 Serializer s = new Serializer(m, 213 ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance)); 214 XmlGenerator xmlGenerator = new XmlGenerator(); 215 StreamWriter writer = new StreamWriter("test2.xml"); 216 foreach (ISerializationToken token in s) { 217 string line = xmlGenerator.Format(token); 218 writer.Write(line); 219 Console.Out.Write(line); 220 } 221 writer.Close(); 222 XmlParser parser = new XmlParser(new StreamReader("test2.xml")); 223 DeSerializer deSerializer = new DeSerializer( 224 XmlParser.ParseTypeCache(new StreamReader("test-types.xml"))); 225 object o = deSerializer.DeSerialize(parser); 212 XmlGenerator.Serialize(m, "test2.zip"); 213 object o = XmlParser.DeSerialize("test2.zip"); 226 214 Console.Out.WriteLine(Util.AutoFormat(o, true)); 227 215 } -
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 } -
trunk/sources/HeuristicLab.Persistence/HeuristicLab.Persistence.csproj
r1456 r1466 44 44 --> 45 45 <ItemGroup> 46 <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.4.369, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL"> 47 <SpecificVersion>False</SpecificVersion> 48 <HintPath>..\HeuristicLab.PluginInfrastructure.GUI\ICSharpCode.SharpZipLib.dll</HintPath> 49 </Reference> 46 50 <Reference Include="System" /> 47 51 <Reference Include="System.configuration" />
Note: See TracChangeset
for help on using the changeset viewer.