Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/30/09 15:06:13 (15 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/HeuristicLab.Persistence
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.