Changeset 1363
- Timestamp:
- 03/19/09 14:19:58 (16 years ago)
- Location:
- branches/New Persistence Exploration/Persistence
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/Default/Xml/XmlGenerator.cs
r1362 r1363 4 4 using HeuristicLab.Persistence.Interfaces; 5 5 using HeuristicLab.Persistence.Core; 6 using System.IO; 6 7 7 8 namespace HeuristicLab.Persistence.Default.Xml { … … 36 37 private enum NodeType { Start, End, Inline } ; 37 38 38 private static string FormatNode(string name, Dictionary<string, object> attributes, NodeType type) { 39 private static string FormatNode(string name, 40 Dictionary<string, object> attributes, 41 NodeType type) { 42 return FormatNode(name, attributes, type, " "); 43 } 44 45 private static string FormatNode(string name, 46 Dictionary<string, object> attributes, 47 NodeType type, string space) { 39 48 StringBuilder sb = new StringBuilder(); 40 49 sb.Append('<'); … … 44 53 foreach (var attribute in attributes) { 45 54 if (attribute.Value != null && !string.IsNullOrEmpty(attribute.Value.ToString())) { 46 sb.Append( ' ');55 sb.Append(space); 47 56 sb.Append(attribute.Key); 48 57 sb.Append("=\""); … … 112 121 yield return "<" + XmlStrings.TYPECACHE + ">"; 113 122 foreach (var mapping in typeCache) 114 yield return FormatNode(XmlStrings.TYPE, mapping.GetDict(), NodeType.Inline); 123 yield return " " + FormatNode( 124 XmlStrings.TYPE, 125 mapping.GetDict(), 126 NodeType.Inline, 127 "\n "); 115 128 yield return "</" + XmlStrings.TYPECACHE + ">"; 116 129 } 130 131 public static void Serialize(object o, string basename) { 132 Serialize(o, basename, ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance)); 133 } 134 135 public static void Serialize(object o, string basename, Configuration configuration) { 136 Serializer s = new Serializer(o, configuration); 137 XmlGenerator xmlGenerator = new XmlGenerator(); 138 StreamWriter writer = new StreamWriter(basename + ".xml"); 139 foreach (ISerializationToken token in s) { 140 string line = xmlGenerator.Format(token); 141 writer.Write(line); 142 Console.Out.Write(line); 143 } 144 writer.Close(); 145 writer = new StreamWriter(basename + "-types.xml"); 146 foreach (string line in xmlGenerator.Format(s.TypeCache)) { 147 writer.WriteLine(line); 148 Console.Out.WriteLine(line); 149 } 150 writer.Close(); 151 } 152 117 153 } 118 154 } -
branches/New Persistence Exploration/Persistence/Persistence/Default/Xml/XmlParser.cs
r1362 r1363 104 104 return typeCache; 105 105 } 106 107 public static object DeSerialize(string basename) { 108 DeSerializer deSerializer = new DeSerializer( 109 ParseTypeCache(new StreamReader(basename + "-types.xml"))); 110 XmlParser parser = new XmlParser(new StreamReader("test.xml")); 111 return deSerializer.DeSerialize(parser); 112 } 106 113 } 107 114 } -
branches/New Persistence Exploration/Persistence/Persistence/HeuristicLab.Persistence.csproj
r1361 r1363 9 9 <OutputType>Library</OutputType> 10 10 <AppDesignerFolder>Properties</AppDesignerFolder> 11 <RootNamespace> Persistence</RootNamespace>12 <AssemblyName> Persistence</AssemblyName>11 <RootNamespace>HeuristicLab.Persistence</RootNamespace> 12 <AssemblyName>HeuristicLab.Persistence</AssemblyName> 13 13 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 14 14 <FileAlignment>512</FileAlignment> -
branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs
r1362 r1363 154 154 r.dict.Add("two", 2); 155 155 r.dict.Add("three", 3); 156 Serializer s = new Serializer(r, ConfigurationService.Instance.GetDefaultConfig(XmlFormat.Instance)); 157 XmlGenerator xmlGenerator = new XmlGenerator(); 158 StreamWriter writer = new StreamWriter("test.xml"); 159 foreach (ISerializationToken token in s) { 160 string line = xmlGenerator.Format(token); 161 writer.Write(line); 162 Console.Out.Write(line); 163 } 164 writer.Close(); 165 writer = new StreamWriter("test-types.xml"); 166 foreach (string line in xmlGenerator.Format(s.TypeCache)) { 167 writer.WriteLine(line); 168 Console.Out.WriteLine(line); 169 } 170 writer.Close(); 171 172 XmlParser parser = new XmlParser(new StreamReader("test.xml")); 173 DeSerializer deSerializer = new DeSerializer( 174 XmlParser.ParseTypeCache(new StreamReader("test-types.xml"))); 175 object o = deSerializer.DeSerialize(parser); 156 XmlGenerator.Serialize(r, "test"); 157 object o = XmlParser.DeSerialize("test"); 176 158 Console.Out.WriteLine(Util.AutoFormat(o, true)); 177 159 }
Note: See TracChangeset
for help on using the changeset viewer.