Changeset 1566 for trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml
- Timestamp:
- 04/16/09 12:58:14 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleArray2XmlFormatters.cs
r1564 r1566 4 4 5 5 namespace HeuristicLab.Persistence.Default.Xml.Compact { 6 6 7 7 public abstract class DoubleArray2XmlFormatterBase<T> : NumberArray2XmlFormatterBase<T> { 8 8 9 9 protected override string FormatValue(object o) { 10 10 return ((double)o).ToString("r", CultureInfo.InvariantCulture); … … 24 24 25 25 [EmptyStorableClass] 26 public class Double3DArray2XmlFormatter : DoubleArray2XmlFormatterBase<double[, ,]> { }27 26 public class Double3DArray2XmlFormatter : DoubleArray2XmlFormatterBase<double[, ,]> { } 27 28 28 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleList2XmlFormatter.cs
r1564 r1566 8 8 9 9 [EmptyStorableClass] 10 public class DoubleList2XmlFormatter : NumberEnumeration2XmlFormatterBase<List<double>> { 10 public class DoubleList2XmlFormatter : NumberEnumeration2XmlFormatterBase<List<double>> { 11 11 12 12 protected override void Add(IEnumerable enumeration, object o) { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/IntArray2XmlFormatters.cs
r1564 r1566 3 3 4 4 namespace HeuristicLab.Persistence.Default.Xml.Compact { 5 6 public abstract class IntArray2XmlFormatterBase<T> : NumberArray2XmlFormatterBase<T> { 5 6 public abstract class IntArray2XmlFormatterBase<T> : NumberArray2XmlFormatterBase<T> { 7 7 8 8 protected override string FormatValue(object o) { … … 22 22 23 23 [EmptyStorableClass] 24 public class Int3DArray2XmlFormatter : IntArray2XmlFormatterBase<int[, ,]> { }25 24 public class Int3DArray2XmlFormatter : IntArray2XmlFormatterBase<int[, ,]> { } 25 26 26 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/IntList2XmlFormatter.cs
r1564 r1566 8 8 [EmptyStorableClass] 9 9 public class IntList2XmlFormatter : NumberEnumeration2XmlFormatterBase<List<int>> { 10 10 11 11 protected override void Add(IEnumerable enumeration, object o) { 12 12 ((List<int>)enumeration).Add((int)o); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberArray2XmlFormatterBase.cs
r1564 r1566 5 5 6 6 namespace HeuristicLab.Persistence.Default.Xml.Compact { 7 7 8 8 public abstract class NumberArray2XmlFormatterBase<T> : FormatterBase<T, XmlString> { 9 9 … … 30 30 } 31 31 int[] positions = (int[])lowerBounds.Clone(); 32 while (positions[a.Rank - 1] < lengths[a.Rank - 1] + lowerBounds[a.Rank - 1]) { 32 while (positions[a.Rank - 1] < lengths[a.Rank - 1] + lowerBounds[a.Rank - 1]) { 33 33 sb.Append(Separator); 34 34 sb.Append(FormatValue(a.GetValue(positions))); … … 42 42 } 43 43 } 44 } 44 } 45 45 return new XmlString(sb.ToString()); 46 46 } … … 80 80 } 81 81 } 82 82 83 83 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberEnumeration2XmlFormatterBase.cs
r1564 r1566 5 5 6 6 namespace HeuristicLab.Persistence.Default.Xml.Compact { 7 7 8 8 public abstract class NumberEnumeration2XmlFormatterBase<T> : FormatterBase<T, XmlString> where T : IEnumerable { 9 9 … … 32 32 } 33 33 } 34 34 35 35 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Bool2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Bool2XmlFormatter : SimpleNumber2XmlFormatterBase<bool> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Byte2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Byte2XmlFormatter : SimpleNumber2XmlFormatterBase<byte> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DateTime2XmlFormatter.cs
r1564 r1566 6 6 7 7 [EmptyStorableClass] 8 public class DateTime2XmlFormatter : FormatterBase<DateTime, XmlString> { 9 8 public class DateTime2XmlFormatter : FormatterBase<DateTime, XmlString> { 9 10 10 public override XmlString Format(DateTime dt) { 11 return new XmlString(dt.Ticks.ToString()); 11 return new XmlString(dt.Ticks.ToString()); 12 12 } 13 13 … … 18 18 } 19 19 20 20 21 21 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Decimal2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Decimal2XmlFormatter : DecimalNumber2XmlFormatterBase<decimal> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DecimalNumber2XmlFormatterBase.cs
r1564 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 public abstract class DecimalNumber2XmlFormatterBase<T> : FormatterBase<T, XmlString> { 10 10 11 11 private static MethodInfo ToStringMethod = typeof(T) 12 12 .GetMethod( … … 30 30 return new XmlString((string)ToStringMethod.Invoke(t, new object[] { "r", CultureInfo.InvariantCulture })); 31 31 } 32 public override T Parse(XmlString x) { 32 public override T Parse(XmlString x) { 33 33 return (T)ParseMethod.Invoke(null, new object[] { x.Data, CultureInfo.InvariantCulture }); 34 34 } 35 } 35 } 36 36 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Double2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Double2XmlFormatter : DecimalNumber2XmlFormatterBase<double> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Float2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Float2XmlFormatter : DecimalNumber2XmlFormatterBase<float> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Int2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 8 9 9 [EmptyStorableClass] 10 10 public class Int2XmlFormatter : SimpleNumber2XmlFormatterBase<int> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Long2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 8 9 9 [EmptyStorableClass] 10 10 public class Long2XmlFormatter : SimpleNumber2XmlFormatterBase<long> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/SByte2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Sbyte2XmlFormatter : SimpleNumber2XmlFormatterBase<sbyte> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Short2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class Short2XmlFormatter : SimpleNumber2XmlFormatterBase<short> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/SimpleNumber2XmlFormatterBase.cs
r1564 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 8 9 9 public abstract class SimpleNumber2XmlFormatterBase<T> : FormatterBase<T, XmlString> { … … 22 22 } 23 23 public override T Parse(XmlString x) { 24 return (T)ParseMethod.Invoke(null, new[] { x.Data }); 24 return (T)ParseMethod.Invoke(null, new[] { x.Data }); 25 25 } 26 } 26 } 27 27 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlFormatter.cs
r1564 r1566 9 9 [EmptyStorableClass] 10 10 public class String2XmlFormatter : FormatterBase<string, XmlString> { 11 11 12 12 public override XmlString Format(string s) { 13 13 StringBuilder sb = new StringBuilder(); … … 15 15 sb.Append(s.Replace("]]>", "]]]]><![CDATA[>")); 16 16 sb.Append("]]>"); 17 return new XmlString(sb.ToString()); 17 return new XmlString(sb.ToString()); 18 18 } 19 19 … … 22 22 public override string Parse(XmlString x) { 23 23 StringBuilder sb = new StringBuilder(); 24 foreach (string s in x.Data.Split(separators, 24 foreach (string s in x.Data.Split(separators, 25 25 StringSplitOptions.RemoveEmptyEntries)) { 26 26 sb.Append(s); … … 28 28 return sb.ToString(); 29 29 } 30 } 30 } 31 31 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/UInt2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class UInt2XmlFormatter : SimpleNumber2XmlFormatterBase<uint> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/ULong2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 public class ULong2XmlFormatter : SimpleNumber2XmlFormatterBase<ulong> { } 11 10 public class ULong2XmlFormatter : SimpleNumber2XmlFormatterBase<ulong> { } 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/UShort2XmlFormatter.cs
r1554 r1566 5 5 using System.Globalization; 6 6 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 7 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 8 9 9 [EmptyStorableClass] 10 10 public class UShort2XmlFormatter : SimpleNumber2XmlFormatterBase<ushort> { } 11 11 12 12 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlFormat.cs
r1564 r1566 6 6 [EmptyStorableClass] 7 7 public class XmlFormat : FormatBase<XmlString> { 8 public override string Name { get { return "XML"; } } 8 public override string Name { get { return "XML"; } } 9 9 } 10 10 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r1564 r1566 21 21 public const string METAINFO = "METAINFO"; 22 22 } 23 23 24 24 public class XmlGenerator : GeneratorBase<string> { 25 25 26 26 private int depth; 27 27 … … 45 45 if (type == NodeType.End) 46 46 sb.Append('/'); 47 sb.Append(name); 47 sb.Append(name); 48 48 foreach (var attribute in attributes) { 49 49 if (attribute.Value != null && !string.IsNullOrEmpty(attribute.Value.ToString())) { … … 58 58 sb.Append('/'); 59 59 sb.Append(">"); 60 return sb.ToString(); 60 return sb.ToString(); 61 61 } 62 62 … … 65 65 } 66 66 67 protected override string Format(BeginToken beginToken) { 67 protected override string Format(BeginToken beginToken) { 68 68 var attributes = new Dictionary<string, object> { 69 69 {"name", beginToken.Name}, … … 76 76 } 77 77 78 protected override string Format(EndToken endToken) { 78 protected override string Format(EndToken endToken) { 79 79 depth -= 1; 80 80 return Prefix + "</" + XmlStrings.COMPOSITE + ">\r\n"; 81 81 } 82 82 83 protected override string Format(PrimitiveToken dataToken) { 83 protected override string Format(PrimitiveToken dataToken) { 84 84 var attributes = 85 85 new Dictionary<string, object> { … … 89 89 return Prefix + 90 90 FormatNode(XmlStrings.PRIMITIVE, attributes, NodeType.Start) + 91 ((XmlString)dataToken.SerialData).Data + "</" + XmlStrings.PRIMITIVE + ">\r\n"; 91 ((XmlString)dataToken.SerialData).Data + "</" + XmlStrings.PRIMITIVE + ">\r\n"; 92 92 } 93 93 94 protected override string Format(ReferenceToken refToken) { 94 protected override string Format(ReferenceToken refToken) { 95 95 var attributes = new Dictionary<string, object> { 96 96 {"ref", refToken.Id}, 97 {"name", refToken.Name}}; 98 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\r\n"; 97 {"name", refToken.Name}}; 98 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\r\n"; 99 99 } 100 100 101 protected override string Format(NullReferenceToken nullRefToken) { 101 protected override string Format(NullReferenceToken nullRefToken) { 102 102 var attributes = new Dictionary<string, object>{ 103 {"name", nullRefToken.Name}}; 103 {"name", nullRefToken.Name}}; 104 104 return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\r\n"; 105 105 } … … 127 127 } 128 128 129 public static void Serialize(object o, string filename) { 129 public static void Serialize(object o, string filename) { 130 130 Serialize(o, filename, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat())); 131 131 } … … 135 135 XmlGenerator generator = new XmlGenerator(); 136 136 ZipOutputStream zipStream = new ZipOutputStream(File.Create(filename)); 137 zipStream.SetLevel(9); 138 zipStream.PutNextEntry(new ZipEntry("data.xml")); 137 zipStream.SetLevel(9); 138 zipStream.PutNextEntry(new ZipEntry("data.xml")); 139 139 StreamWriter writer = new StreamWriter(zipStream); 140 ILog logger = Logger.GetDefaultLogger(); 140 ILog logger = Logger.GetDefaultLogger(); 141 141 foreach (ISerializationToken token in serializer) { 142 142 string line = generator.Format(token); … … 151 151 logger.Debug(line); 152 152 } 153 writer.Flush(); 154 zipStream.Close(); 153 writer.Flush(); 154 zipStream.Close(); 155 155 } 156 156 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r1564 r1566 19 19 public XmlParser(TextReader input) { 20 20 XmlReaderSettings settings = new XmlReaderSettings { 21 22 23 24 21 ConformanceLevel = ConformanceLevel.Document, 22 IgnoreWhitespace = true, 23 IgnoreComments = true 24 }; 25 25 reader = XmlReader.Create(input, settings); 26 26 handlers = new Dictionary<string, Handler> { … … 66 66 67 67 private IEnumerator<ISerializationToken> ParseComposite() { 68 string name = reader.GetAttribute("name"); 68 string name = reader.GetAttribute("name"); 69 69 string idString = reader.GetAttribute("id"); 70 70 int? id = null; … … 104 104 var typeCache = new List<TypeMapping>(); 105 105 XmlReader xmlReader = XmlReader.Create(reader); 106 while ( xmlReader.Read()) {106 while (xmlReader.Read()) { 107 107 if (xmlReader.Name == XmlStrings.TYPE) { 108 108 typeCache.Add(new TypeMapping( … … 116 116 117 117 public static object DeSerialize(string filename) { 118 ZipFile zipFile = new ZipFile(filename); 118 ZipFile zipFile = new ZipFile(filename); 119 119 Deserializer deSerializer = new Deserializer( 120 120 ParseTypeCache( … … 123 123 XmlParser parser = new XmlParser( 124 124 new StreamReader(zipFile.GetInputStream(zipFile.GetEntry("data.xml")))); 125 return deSerializer.Deserialize(parser); 125 return deSerializer.Deserialize(parser); 126 126 } 127 } 127 } 128 128 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlString.cs
r1564 r1566 3 3 4 4 namespace HeuristicLab.Persistence.Default.Xml { 5 5 6 6 public class XmlString : ISerialData { 7 7
Note: See TracChangeset
for help on using the changeset viewer.