Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/25/09 18:03:39 (16 years ago)
Author:
epitzer
Message:

Configurable compression level (and lower default settings) and remove excessive logging for better saving speed. (#646)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs

    r1823 r1892  
    157157
    158158    public static void Serialize(object o, string filename) {
    159       Serialize(o, filename, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()));
     159      Serialize(o, filename, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat()), false, 5);
     160    }
     161
     162    public static void Serialize(object o, string filename, int compression) {
     163      Serialize(o, filename, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, compression);
    160164    }
    161165
    162166    public static void Serialize(object obj, string filename, Configuration config) {
    163       Serialize(obj, filename, config, false);
    164     }
    165 
    166     public static void Serialize(object obj, string filename, Configuration config, bool includeAssemblies) {
    167       string tempfile = Path.GetTempFileName();
     167      Serialize(obj, filename, config, false, 5);
     168    }
     169
     170    public static void Serialize(object obj, string filename, Configuration config, bool includeAssemblies, int compression) {     
    168171      try {
    169         Serialize(obj, File.Create(tempfile), config, includeAssemblies);
     172        string tempfile = Path.GetTempFileName();
     173        DateTime start = DateTime.Now;
     174        Serialize(obj, File.Create(tempfile), config, includeAssemblies, compression);
     175        Logger.Info(String.Format("serialization took {0} seconds with compression level {1}",
     176          (DateTime.Now - start).TotalSeconds, compression));
    170177        File.Copy(tempfile, filename, true);
    171178        File.Delete(tempfile);
     
    180187      Serialize(obj, stream, config, false);
    181188    }
    182 
     189   
    183190    public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies) {
     191      Serialize(obj, stream, config, includeAssemblies, 9);
     192    }
     193
     194    public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies, int compression) {     
    184195      try {
    185196        Serializer serializer = new Serializer(obj, config);
    186197        XmlGenerator generator = new XmlGenerator();
    187         ILog logger = Logger.GetDefaultLogger();
    188198        using (ZipOutputStream zipStream = new ZipOutputStream(stream)) {
    189           zipStream.SetLevel(9);
     199          zipStream.SetLevel(compression);
    190200          zipStream.PutNextEntry(new ZipEntry("data.xml"));
    191201          StreamWriter writer = new StreamWriter(zipStream);
     
    193203            string line = generator.Format(token);
    194204            writer.Write(line);
    195             logger.Debug(line.TrimEnd());
    196205          }
    197206          writer.Flush();
     
    199208          foreach (string line in generator.Format(serializer.TypeCache)) {
    200209            writer.Write(line);
    201             logger.Debug(line.TrimEnd());
    202210          }
    203211          writer.Flush();
     
    226234      } catch (Exception e) {
    227235        throw new PersistenceException("Unexpected exception during Serialization.", e);
    228       }
     236      }     
    229237    }
    230238  }
Note: See TracChangeset for help on using the changeset viewer.