Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/08/15 15:32:12 (9 years ago)
Author:
dglaser
Message:

#2388: Merged trunk into HiveStatistics branch

Location:
branches/HiveStatistics/sources
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources

  • branches/HiveStatistics/sources/HeuristicLab.Persistence

  • branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs

    r12467 r12689  
    398398    /// <param name="obj">The object.</param>
    399399    /// <param name="stream">The stream.</param>
    400     /// <param name="useZip">If true, uses zip for compression, otherwise gzip.</param>
    401     public static void Serialize(object obj, Stream stream, bool useZip = false) {
    402       Serialize(obj, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), useZip);
     400    /// <param name="compressionType">Type of compression, default is GZip.</param>
     401    public static void Serialize(object obj, Stream stream, CompressionType compressionType = CompressionType.GZip) {
     402      Serialize(obj, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), compressionType);
    403403    }
    404404
     
    410410    /// <param name="stream">The stream.</param>
    411411    /// <param name="config">The configuration.</param>
    412     /// <param name="useZip">If true, uses zip for compression, otherwise gzip.</param>
    413     public static void Serialize(object obj, Stream stream, Configuration config, bool useZip = false) {
    414       Serialize(obj, stream, config, false, useZip);
     412    /// <param name="compressionType">Type of compression, default is GZip.</param>
     413    public static void Serialize(object obj, Stream stream, Configuration config, CompressionType compressionType = CompressionType.GZip) {
     414      Serialize(obj, stream, config, false, compressionType);
    415415    }
    416416
     
    422422    /// <param name="config">The configuration.</param>
    423423    /// <param name="includeAssemblies">if set to <c>true</c> include need assemblies.</param>
    424     /// <param name="useZip">If true, uses zip for compression, otherwise gzip.</param>
    425     public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies, bool useZip = false) {
     424    /// <param name="compressionType">Type of compression, default is GZip.</param>
     425    public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies,
     426                                 CompressionType compressionType = CompressionType.GZip) {
    426427      try {
    427428        Serializer serializer = new Serializer(obj, config);
    428         if (useZip) {
     429        if (compressionType == CompressionType.Zip) {
    429430          Serialize(obj, stream, config, includeAssemblies, CompressionLevel.Optimal);
    430431        } else {
     
    448449    /// <param name="includeAssemblies">if set to <c>true</c> include need assemblies.</param>
    449450    /// <param name="types">The list of all serialized types.</param>
    450     /// <param name="useZip">If true, uses zip for compression, otherwise gzip.</param>
    451     public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies, out IEnumerable<Type> types, bool useZip = false) {
     451    /// <param name="compressionType">Type of compression, default is GZip.</param>
     452    public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies, out IEnumerable<Type> types,
     453                                 CompressionType compressionType = CompressionType.GZip) {
    452454      try {
    453455        Serializer serializer = new Serializer(obj, config);
    454         if (useZip) {
     456        if (compressionType == CompressionType.Zip) {
    455457          Serialize(stream, includeAssemblies, CompressionLevel.Optimal, serializer);
    456458        } else {
  • branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs

    r12584 r12689  
    3131
    3232namespace HeuristicLab.Persistence.Default.Xml {
     33  /// <summary>
     34  /// Type of compression used for the Xml stream or file.
     35  /// </summary>
     36  public enum CompressionType {
     37    GZip,
     38    Zip
     39  }
    3340
    3441  /// <summary>
     
    221228    }
    222229
    223 
    224     /// <summary>
    225     /// Deserializes an object from the specified stream using GZip compression.
    226     /// </summary>
    227     /// <param name="stream">The stream.</param>
    228     /// <returns>A fresh object instance.</returns>
    229     private static object DeserializeWithGZip(Stream stream) {
    230       try {
    231         using (StreamReader reader = new StreamReader(new GZipStream(stream, CompressionMode.Decompress))) {
    232           XmlParser parser = new XmlParser(reader);
    233           Deserializer deserializer = new Deserializer(new TypeMapping[] { });
    234           return deserializer.Deserialize(parser);
    235         }
    236       }
    237       catch (PersistenceException) {
    238         throw;
    239       }
    240       catch (Exception x) {
    241         throw new PersistenceException("Unexpected exception during deserialization", x);
    242       }
    243     }
    244 
    245     /// <summary>
    246     /// Deserializes an object from the specified stream using Zip compression.
    247     /// </summary>
    248     /// <param name="stream">The stream.</param>
    249     /// <returns>A fresh object instance.</returns>
    250     private static object DeserializeWithZip(Stream stream) {
    251       ZipArchive zipFile = new ZipArchive(stream);
    252       return Deserialize(zipFile);
    253     }
    254 
    255230    /// <summary>
    256231    /// Deserializes an object from the specified stream.
     
    258233    /// <typeparam name="T">object type expected from the serialized stream</typeparam>
    259234    /// <param name="stream">The stream.</param>
    260     /// <param name="useZip">If true, uses zip for decompression, otherwise gzip.</param>
     235    /// <param name="compressionType">Type of compression, default is GZip.</param>
    261236    /// <returns>A fresh object instance.</returns>
    262     public static T Deserialize<T>(Stream stream, bool useZip = false) {
    263       return (T)Deserialize(stream, useZip);
     237    public static T Deserialize<T>(Stream stream, CompressionType compressionType = CompressionType.GZip) {
     238      return (T)Deserialize(stream, compressionType);
    264239    }
    265240
     
    268243    /// </summary>
    269244    /// <param name="stream">The stream.</param>
    270     /// <param name="useZip">If true, uses zip for decompression, otherwise gzip.</param>
     245    /// <param name="compressionType">Type of compression, default is GZip.</param>
    271246    /// <returns>A fresh object instance.</returns>
    272     public static object Deserialize(Stream stream, bool useZip = false) {
    273       if (useZip) {
    274         return DeserializeWithZip(stream);
     247    public static object Deserialize(Stream stream, CompressionType compressionType = CompressionType.GZip) {
     248      if (compressionType == CompressionType.Zip) {
     249        ZipArchive zipFile = new ZipArchive(stream);
     250        return Deserialize(zipFile);
    275251      } else {
    276         return DeserializeWithGZip(stream);
     252        try {
     253          using (StreamReader reader = new StreamReader(new GZipStream(stream, CompressionMode.Decompress))) {
     254            XmlParser parser = new XmlParser(reader);
     255            Deserializer deserializer = new Deserializer(new TypeMapping[] { });
     256            return deserializer.Deserialize(parser);
     257          }
     258        }
     259        catch (PersistenceException) {
     260          throw;
     261        }
     262        catch (Exception x) {
     263          throw new PersistenceException("Unexpected exception during deserialization", x);
     264        }
    277265      }
    278266    }
Note: See TracChangeset for help on using the changeset viewer.