- Timestamp:
- 07/08/15 15:32:12 (9 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
-
branches/HiveStatistics/sources/HeuristicLab.Persistence
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Persistence merged: 12638
- Property svn:mergeinfo changed
-
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r12467 r12689 398 398 /// <param name="obj">The object.</param> 399 399 /// <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); 403 403 } 404 404 … … 410 410 /// <param name="stream">The stream.</param> 411 411 /// <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); 415 415 } 416 416 … … 422 422 /// <param name="config">The configuration.</param> 423 423 /// <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) { 426 427 try { 427 428 Serializer serializer = new Serializer(obj, config); 428 if ( useZip) {429 if (compressionType == CompressionType.Zip) { 429 430 Serialize(obj, stream, config, includeAssemblies, CompressionLevel.Optimal); 430 431 } else { … … 448 449 /// <param name="includeAssemblies">if set to <c>true</c> include need assemblies.</param> 449 450 /// <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) { 452 454 try { 453 455 Serializer serializer = new Serializer(obj, config); 454 if ( useZip) {456 if (compressionType == CompressionType.Zip) { 455 457 Serialize(stream, includeAssemblies, CompressionLevel.Optimal, serializer); 456 458 } else { -
branches/HiveStatistics/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r12584 r12689 31 31 32 32 namespace 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 } 33 40 34 41 /// <summary> … … 221 228 } 222 229 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 255 230 /// <summary> 256 231 /// Deserializes an object from the specified stream. … … 258 233 /// <typeparam name="T">object type expected from the serialized stream</typeparam> 259 234 /// <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> 261 236 /// <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); 264 239 } 265 240 … … 268 243 /// </summary> 269 244 /// <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> 271 246 /// <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); 275 251 } 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 } 277 265 } 278 266 }
Note: See TracChangeset
for help on using the changeset viewer.