Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1466 for trunk/sources


Ignore:
Timestamp:
03/30/09 15:06:13 (16 years ago)
Author:
epitzer
Message:

Produce only a single (zipped) file that contains data and type cache and normalize line breaks. (#562)

Location:
trunk/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence.Test/NewSerializationTest.cs

    r1463 r1466  
    166166      r.dict.Add("three", 3);
    167167      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");
    170170      Console.Out.WriteLine(Util.AutoFormat(o, true));
    171171      Console.WriteLine(ViewOnlyGenerator.Serialize(r));
     
    180180      c.allCs = cs;
    181181      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");
    184184      Console.Out.WriteLine(Util.AutoFormat(o, true));
    185185      Console.WriteLine(ViewOnlyGenerator.Serialize(cs));
     
    201201                              new[] { 1, 2 }, new[] { 3, 4 });
    202202      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");
    205205      Console.Out.WriteLine(Util.AutoFormat(o, true));
    206206      Console.WriteLine(ViewOnlyGenerator.Serialize(arrayListArray));
     
    210210    public static void Test2() {
    211211      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");
    226214      Console.Out.WriteLine(Util.AutoFormat(o, true));     
    227215    }   
  • trunk/sources/HeuristicLab.Persistence/Default/Xml/XmlGenerator.cs

    r1454 r1466  
    55using HeuristicLab.Persistence.Core;
    66using System.IO;
     7using ICSharpCode.SharpZipLib.Zip;
    78
    89namespace HeuristicLab.Persistence.Default.Xml {
     
    8889        {"id", beginToken.Id}};
    8990      string result = Prefix +
    90                       FormatNode(XmlStrings.COMPOSITE, attributes, NodeType.Start) + "\n";
     91                      FormatNode(XmlStrings.COMPOSITE, attributes, NodeType.Start) + "\r\n";
    9192      depth += 1;
    9293      return result;
     
    9596    protected override string Format(EndToken endToken) {     
    9697      depth -= 1;
    97       return Prefix + "</" + XmlStrings.COMPOSITE + ">\n";
     98      return Prefix + "</" + XmlStrings.COMPOSITE + ">\r\n";
    9899    }
    99100
     
    106107      return Prefix +
    107108        FormatNode(XmlStrings.PRIMITIVE, attributes, NodeType.Start) +
    108         dataToken.SerialData + "</" + XmlStrings.PRIMITIVE + ">\n";     
     109        dataToken.SerialData + "</" + XmlStrings.PRIMITIVE + ">\r\n";     
    109110    }
    110111
     
    113114        {"ref", refToken.Id},
    114115        {"name", refToken.Name}};                                       
    115       return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\n"; 
     116      return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\r\n"; 
    116117    }
    117118
     
    119120      var attributes = new Dictionary<string, object>{
    120121        {"name", nullRefToken.Name}};     
    121       return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\n";
     122      return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\r\n";
    122123    }
    123124
     
    129130          mapping.GetDict(),
    130131          NodeType.Inline,
    131           "\n    ");
     132          "\r\n    ");
    132133      yield return "</" + XmlStrings.TYPECACHE + ">";
    133134    }
     
    137138    }
    138139
    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))
    151153        writer.WriteLine(line);
    152         Console.Out.WriteLine(line);
    153       }
    154       writer.Close();     
     154      writer.Flush();           
     155      zipStream.Close();     
    155156    }
    156157
  • trunk/sources/HeuristicLab.Persistence/Default/Xml/XmlParser.cs

    r1454 r1466  
    66using HeuristicLab.Persistence.Core;
    77using HeuristicLab.Persistence.Interfaces;
     8using ICSharpCode.SharpZipLib.Zip;
    89
    910namespace HeuristicLab.Persistence.Default.Xml {
     
    105106    }
    106107
    107     public static object DeSerialize(string basename) {
     108    public static object DeSerialize(string filename) {
     109      ZipFile zipFile = new ZipFile(filename);     
    108110      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"))));
    111116      return deSerializer.DeSerialize(parser);     
    112117    }
  • trunk/sources/HeuristicLab.Persistence/HeuristicLab.Persistence.csproj

    r1456 r1466  
    4444  -->
    4545  <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>
    4650    <Reference Include="System" />
    4751    <Reference Include="System.configuration" />
Note: See TracChangeset for help on using the changeset viewer.