- Timestamp:
- 09/25/15 14:39:59 (9 years ago)
- Location:
- branches/gteufl
- Files:
-
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gteufl
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 25 obj
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/gteufl/HeuristicLab.Persistence
- Property svn:mergeinfo changed
-
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Compact/ByteArray2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Compact/CompactXmlSerializerBase.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleArray2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleList2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Compact/IntArray2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Compact/IntList2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberArray2XmlSerializerBase.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberEnumeration2XmlSerializerBase.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/EasyXmlGenerator.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 167 167 /// <param name="obj">The object.</param> 168 168 /// <param name="stream">The stream.</param> 169 public newstatic void Serialize(object obj, Stream stream) {169 public static void Serialize(object obj, Stream stream) { 170 170 Serialize(obj, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat())); 171 171 } … … 178 178 /// <param name="stream">The stream.</param> 179 179 /// <param name="config">The configuration.</param> 180 public newstatic void Serialize(object obj, Stream stream, Configuration config) {180 public static void Serialize(object obj, Stream stream, Configuration config) { 181 181 try { 182 182 using (StreamWriter writer = new StreamWriter(stream)) { -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Bool2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Byte2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Char2XmlFormatter.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 23 using System.Text; 24 using System.Text.RegularExpressions; 22 25 using HeuristicLab.Persistence.Core; 23 26 using HeuristicLab.Persistence.Interfaces; … … 27 30 internal sealed class Char2XmlSerializer : PrimitiveSerializerBase<char, XmlString> { 28 31 32 private static readonly Regex base64Regex = new Regex("<Base64>(.+)</Base64>"); 33 34 private static bool IsSpecial(char c) { 35 return c <= 0x1F && c != 0x9 && c != 0xA && c != 0xD; 36 } 37 38 private static string ToBase64String(char c) { 39 return string.Format("<Base64>{0}</Base64>", Convert.ToBase64String(Encoding.ASCII.GetBytes(new[] {c}))); 40 } 41 29 42 public override XmlString Format(char c) { 30 return new XmlString( new string(c, 1));43 return new XmlString(IsSpecial(c) ? ToBase64String(c) : new string(c, 1)); 31 44 } 32 45 33 46 public override char Parse(XmlString x) { 34 if (x.Data.Length != 1) 35 throw new PersistenceException("Invalid character format, XML string length != 1"); 36 return x.Data[0]; 47 if (x.Data.Length <= 1) return x.Data[0]; 48 var m = base64Regex.Match(x.Data); 49 if (m.Success) 50 return Encoding.ASCII.GetString(Convert.FromBase64String(m.Groups[1].Value))[0]; 51 throw new PersistenceException("Invalid character format, XML string length != 1"); 37 52 } 38 53 } -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DateTime2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Decimal2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Double2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Float2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Guid2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Int2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Long2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/PrimitiveXmlSerializerBase.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/SByte2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Short2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/SimpleNumber2XmlSerializerBase.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 22 23 using System.Text; 23 24 using System.Text.RegularExpressions; 24 25 using HeuristicLab.Persistence.Core; 25 26 26 27 27 namespace HeuristicLab.Persistence.Default.Xml.Primitive { … … 42 42 sb.Append(s.Replace("]]>", "]]]]><![CDATA[>")); 43 43 sb.Append("]]>"); 44 return new XmlString(sb.ToString()); 44 s = special.Replace(sb.ToString(), m => ToBase64Tag(m.Value)); 45 return new XmlString(s); 45 46 } 46 47 47 private static Regex re = new Regex(@"<!\[CDATA\[((?:[^]]|\](?!\]>))*)\]\]>", RegexOptions.Singleline); 48 private static readonly Regex re = new Regex(@"<!\[CDATA\[((?:[^]]|\](?!\]>))*)\]\]>|<Base64>([^<]*)</Base64>", RegexOptions.Singleline); 49 private static readonly Regex special = new Regex(@"[\x00-\x08\x0b\x0c\x0e-\x1f]+", RegexOptions.Singleline); 50 51 private static string ToBase64Tag(string s) { 52 return new StringBuilder() 53 .Append("]]><Base64>") 54 .Append(Convert.ToBase64String(Encoding.ASCII.GetBytes(s))) 55 .Append("</Base64><![CDATA[") 56 .ToString(); 57 } 48 58 49 59 /// <summary> … … 55 65 StringBuilder sb = new StringBuilder(); 56 66 foreach (Match m in re.Matches(x.Data)) { 57 sb.Append(m.Groups[1]); 67 if (m.Groups[1].Success) 68 sb.Append(m.Groups[1].Value); 69 else if (m.Groups[2].Success) { 70 sb.Append(Encoding.ASCII.GetString(Convert.FromBase64String(m.Groups[2].Value))); 71 } 58 72 } 59 73 string result = sb.ToString(); -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/System.Drawing/Bitmap2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/System.Drawing/Font2XmlSerializer.cs
r9988 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 28 28 public override XmlString Format(Font font) { 29 29 return new XmlString(string.Format("{0};{1};{2};{3};{4};{5}", 30 font.FontFamily.Name,30 GetFontFamilyName(font.FontFamily), 31 31 Float2XmlSerializer.FormatG8(font.Size), 32 32 font.Style, … … 39 39 string[] tokens = fontData.Data.Split(';'); 40 40 return new Font( 41 tokens[0],41 GetFontFamily(tokens[0]), 42 42 Float2XmlSerializer.ParseG8(tokens[1]), 43 43 (FontStyle)Enum.Parse(typeof(FontStyle), tokens[2]), … … 46 46 bool.Parse(tokens[5])); 47 47 } 48 49 public const string GENERIC_MONOSPACE_NAME = "_GenericMonospace"; 50 public const string GENERIC_SANS_SERIF_NAME = "_GenericSansSerif"; 51 public const string GENERIC_SERIF_NAME = "_GenericSerif"; 52 53 public static FontFamily GetFontFamily(string name) { 54 if (name == GENERIC_MONOSPACE_NAME) return FontFamily.GenericMonospace; 55 if (name == GENERIC_SANS_SERIF_NAME) return FontFamily.GenericSansSerif; 56 if (name == GENERIC_SERIF_NAME) return FontFamily.GenericSerif; 57 return new FontFamily(name); 58 } 59 60 public static string GetFontFamilyName(FontFamily ff) { 61 if (ff.Equals(FontFamily.GenericMonospace)) return GENERIC_MONOSPACE_NAME; 62 if (ff.Equals(FontFamily.GenericSansSerif)) return GENERIC_SANS_SERIF_NAME; 63 if (ff.Equals(FontFamily.GenericSerif)) return GENERIC_SERIF_NAME; 64 return ff.Name; 65 } 66 48 67 } 49 68 } -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/TimeSpan2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/UInt2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/ULong2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/UShort2XmlSerializer.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/XmlFormat.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 30 30 using HeuristicLab.Persistence.Interfaces; 31 31 using HeuristicLab.Tracing; 32 using ICSharpCode.SharpZipLib.Zip;33 32 34 33 namespace HeuristicLab.Persistence.Default.Xml { … … 286 285 /// <param name="filename">The filename.</param> 287 286 public static void Serialize(object o, string filename) { 288 Serialize(o, filename, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, 5);287 Serialize(o, filename, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, CompressionLevel.Optimal); 289 288 } 290 289 … … 297 296 /// <param name="filename">The filename.</param> 298 297 /// <param name="compression">ZIP file compression level</param> 299 public static void Serialize(object o, string filename, intcompression) {298 public static void Serialize(object o, string filename, CompressionLevel compression) { 300 299 Serialize(o, filename, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, compression); 301 300 } … … 309 308 /// <param name="config">The configuration.</param> 310 309 public static void Serialize(object obj, string filename, Configuration config) { 311 Serialize(obj, filename, config, false, 5); 310 Serialize(obj, filename, config, false, CompressionLevel.Optimal); 311 } 312 313 private static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies 314 , CompressionLevel compression) { 315 Serializer serializer = new Serializer(obj, config); 316 Serialize(stream, includeAssemblies, compression, serializer); 317 } 318 319 private static void Serialize(Stream stream, bool includeAssemblies, CompressionLevel compression, Serializer serializer) { 320 try { 321 DateTime start = DateTime.Now; 322 serializer.InterleaveTypeInformation = false; 323 XmlGenerator generator = new XmlGenerator(); 324 using (ZipArchive zipArchive = new ZipArchive(stream, ZipArchiveMode.Create)) { 325 ZipArchiveEntry entry = zipArchive.CreateEntry("data.xml", compression); 326 using (StreamWriter writer = new StreamWriter(entry.Open())) { 327 foreach (ISerializationToken token in serializer) { 328 string line = generator.Format(token); 329 writer.Write(line); 330 } 331 } 332 entry = zipArchive.CreateEntry("typecache.xml", compression); 333 using (StreamWriter writer = new StreamWriter(entry.Open())) { 334 foreach (string line in generator.Format(serializer.TypeCache)) { 335 writer.Write(line); 336 } 337 } 338 if (includeAssemblies) { 339 foreach (string name in serializer.RequiredFiles) { 340 Uri uri = new Uri(name); 341 if (!uri.IsFile) { 342 Logger.Warn("cannot read non-local files"); 343 continue; 344 } 345 entry = zipArchive.CreateEntry(Path.GetFileName(uri.PathAndQuery), compression); 346 using (BinaryWriter bw = new BinaryWriter(entry.Open())) { 347 using (FileStream reader = File.OpenRead(uri.PathAndQuery)) { 348 byte[] buffer = new byte[1024 * 1024]; 349 while (true) { 350 int bytesRead = reader.Read(buffer, 0, 1024 * 1024); 351 if (bytesRead == 0) 352 break; 353 bw.Write(buffer, 0, bytesRead); 354 } 355 } 356 } 357 } 358 } 359 } 360 Logger.Info(String.Format("serialization took {0} seconds with compression level {1}", 361 (DateTime.Now - start).TotalSeconds, compression)); 362 } 363 catch (Exception) { 364 Logger.Warn("Exception caught, no data has been serialized."); 365 throw; 366 } 312 367 } 313 368 … … 320 375 /// <param name="includeAssemblies">if set to <c>true</c> include needed assemblies.</param> 321 376 /// <param name="compression">The ZIP compression level.</param> 322 public static void Serialize(object obj, string filename, Configuration config, bool includeAssemblies, intcompression) {377 public static void Serialize(object obj, string filename, Configuration config, bool includeAssemblies, CompressionLevel compression) { 323 378 try { 324 379 string tempfile = Path.GetTempFileName(); 325 DateTime start = DateTime.Now; 380 326 381 using (FileStream stream = File.Create(tempfile)) { 327 Serializer serializer = new Serializer(obj, config); 328 serializer.InterleaveTypeInformation = false; 329 XmlGenerator generator = new XmlGenerator(); 330 using (ZipOutputStream zipStream = new ZipOutputStream(stream)) { 331 zipStream.IsStreamOwner = false; 332 zipStream.SetLevel(compression); 333 zipStream.PutNextEntry(new ZipEntry("data.xml") { DateTime = DateTime.MinValue }); 334 StreamWriter writer = new StreamWriter(zipStream); 335 foreach (ISerializationToken token in serializer) { 336 string line = generator.Format(token); 337 writer.Write(line); 338 } 339 writer.Flush(); 340 zipStream.PutNextEntry(new ZipEntry("typecache.xml") { DateTime = DateTime.MinValue }); 341 foreach (string line in generator.Format(serializer.TypeCache)) { 342 writer.Write(line); 343 } 344 writer.Flush(); 345 if (includeAssemblies) { 346 foreach (string name in serializer.RequiredFiles) { 347 Uri uri = new Uri(name); 348 if (!uri.IsFile) { 349 Logger.Warn("cannot read non-local files"); 350 continue; 351 } 352 zipStream.PutNextEntry(new ZipEntry(Path.GetFileName(uri.PathAndQuery))); 353 FileStream reader = File.OpenRead(uri.PathAndQuery); 354 byte[] buffer = new byte[1024 * 1024]; 355 while (true) { 356 int bytesRead = reader.Read(buffer, 0, 1024 * 1024); 357 if (bytesRead == 0) 358 break; 359 zipStream.Write(buffer, 0, bytesRead); 360 } 361 writer.Flush(); 362 } 363 } 364 } 365 } 366 Logger.Info(String.Format("serialization took {0} seconds with compression level {1}", 367 (DateTime.Now - start).TotalSeconds, compression)); 382 Serialize(obj, stream, config, includeAssemblies, compression); 383 } 384 368 385 File.Copy(tempfile, filename, true); 369 386 File.Delete(tempfile); … … 381 398 /// <param name="obj">The object.</param> 382 399 /// <param name="stream">The stream.</param> 383 public static void Serialize(object obj, Stream stream) { 384 Serialize(obj, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat())); 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); 385 403 } 386 404 … … 392 410 /// <param name="stream">The stream.</param> 393 411 /// <param name="config">The configuration.</param> 394 public static void Serialize(object obj, Stream stream, Configuration config) { 395 Serialize(obj, stream, config, false); 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); 396 415 } 397 416 … … 403 422 /// <param name="config">The configuration.</param> 404 423 /// <param name="includeAssemblies">if set to <c>true</c> include need assemblies.</param> 405 public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies) { 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) { 406 427 try { 407 428 Serializer serializer = new Serializer(obj, config); 408 Serialize(stream, serializer); 409 } catch (PersistenceException) { 429 if (compressionType == CompressionType.Zip) { 430 Serialize(obj, stream, config, includeAssemblies, CompressionLevel.Optimal); 431 } else { 432 Serialize(stream, serializer); 433 } 434 } 435 catch (PersistenceException) { 410 436 throw; 411 } catch (Exception e) { 437 } 438 catch (Exception e) { 412 439 throw new PersistenceException("Unexpected exception during Serialization.", e); 413 440 } … … 422 449 /// <param name="includeAssemblies">if set to <c>true</c> include need assemblies.</param> 423 450 /// <param name="types">The list of all serialized types.</param> 424 public static void Serialize(object obj, Stream stream, Configuration config, bool includeAssemblies, out IEnumerable<Type> types) { 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) { 425 454 try { 426 455 Serializer serializer = new Serializer(obj, config); 427 Serialize(stream, serializer); 456 if (compressionType == CompressionType.Zip) { 457 Serialize(stream, includeAssemblies, CompressionLevel.Optimal, serializer); 458 } else { 459 Serialize(stream, serializer); 460 } 428 461 types = serializer.SerializedTypes; 429 } catch (PersistenceException) { 462 } 463 catch (PersistenceException) { 430 464 throw; 431 } catch (Exception e) { 465 } 466 catch (Exception e) { 432 467 throw new PersistenceException("Unexpected exception during Serialization.", e); 433 468 } -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/XmlParser.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 29 29 using HeuristicLab.Persistence.Core.Tokens; 30 30 using HeuristicLab.Persistence.Interfaces; 31 using ICSharpCode.SharpZipLib.Zip;32 31 33 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 } 34 40 35 41 /// <summary> … … 193 199 TimeSpan start = System.Diagnostics.Process.GetCurrentProcess().TotalProcessorTime; 194 200 try { 195 using (ZipFile file = new ZipFile(filename)) { 196 return Deserialize(file); 201 using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read)) { 202 using (ZipArchive zip = new ZipArchive(fs)) { 203 return Deserialize(zip); 204 } 197 205 } 198 206 } … … 215 223 } 216 224 217 218 225 /// <summary> 219 226 /// Deserializes an object from the specified stream. 220 227 /// </summary> 228 /// <typeparam name="T">object type expected from the serialized stream</typeparam> 221 229 /// <param name="stream">The stream.</param> 230 /// <param name="compressionType">Type of compression, default is GZip.</param> 222 231 /// <returns>A fresh object instance.</returns> 223 public static object Deserialize(Stream stream) { 232 public static T Deserialize<T>(Stream stream, CompressionType compressionType = CompressionType.GZip) { 233 return (T)Deserialize(stream, compressionType); 234 } 235 236 /// <summary> 237 /// Deserializes an object from the specified stream. 238 /// </summary> 239 /// <param name="stream">The stream.</param> 240 /// <param name="compressionType">Type of compression, default is GZip.</param> 241 /// <returns>A fresh object instance.</returns> 242 public static object Deserialize(Stream stream, CompressionType compressionType = CompressionType.GZip) { 243 if (compressionType == CompressionType.Zip) { 244 ZipArchive zipFile = new ZipArchive(stream); 245 return Deserialize(zipFile); 246 } else { 247 try { 248 using (StreamReader reader = new StreamReader(new GZipStream(stream, CompressionMode.Decompress))) { 249 XmlParser parser = new XmlParser(reader); 250 Deserializer deserializer = new Deserializer(new TypeMapping[] { }); 251 return deserializer.Deserialize(parser); 252 } 253 } 254 catch (PersistenceException) { 255 throw; 256 } 257 catch (Exception x) { 258 throw new PersistenceException("Unexpected exception during deserialization", x); 259 } 260 } 261 } 262 263 private static object Deserialize(ZipArchive zipFile) { 224 264 try { 225 using (StreamReader reader = new StreamReader(new GZipStream(stream, CompressionMode.Decompress))) { 226 XmlParser parser = new XmlParser(reader); 227 Deserializer deserializer = new Deserializer(new TypeMapping[] { }); 228 return deserializer.Deserialize(parser); 229 } 265 ZipArchiveEntry typecache = zipFile.GetEntry("typecache.xml"); 266 if (typecache == null) throw new PersistenceException("file does not contain typecache.xml"); 267 Deserializer deSerializer; 268 using (StreamReader sr = new StreamReader(typecache.Open())) { 269 deSerializer = new Deserializer(ParseTypeCache(sr)); 270 } 271 272 ZipArchiveEntry data = zipFile.GetEntry("data.xml"); 273 if (data == null) throw new PersistenceException("file does not contain data.xml"); 274 object result; 275 using (StreamReader sr = new StreamReader(data.Open())) { 276 XmlParser parser = new XmlParser(sr); 277 result = deSerializer.Deserialize(parser); 278 } 279 280 return result; 230 281 } 231 282 catch (PersistenceException) { 232 283 throw; 233 284 } 234 catch (Exception x) {235 throw new PersistenceException("Unexpected exception during deserialization", x);236 }237 }238 239 /// <summary>240 /// Deserializes an object from the specified stream.241 /// </summary>242 /// <typeparam name="T">object type expected from the serialized stream</typeparam>243 /// <param name="stream">The stream.</param>244 /// <returns>A fresh object instance.</returns>245 public static T Deserialize<T>(Stream stream) {246 return (T)Deserialize(stream);247 }248 249 private static object Deserialize(ZipFile zipFile) {250 try {251 ZipEntry typecache = zipFile.GetEntry("typecache.xml");252 if (typecache == null)253 throw new PersistenceException("file does not contain typecache.xml");254 Deserializer deSerializer = new Deserializer(ParseTypeCache(new StreamReader(zipFile.GetInputStream(typecache))));255 ZipEntry data = zipFile.GetEntry("data.xml");256 if (data == null)257 throw new PersistenceException("file does not contain data.xml");258 XmlParser parser = new XmlParser(259 new StreamReader(zipFile.GetInputStream(data)));260 object result = deSerializer.Deserialize(parser);261 zipFile.Close();262 return result;263 }264 catch (PersistenceException) {265 throw;266 }267 285 catch (Exception e) { 268 286 throw new PersistenceException("Unexpected exception during deserialization", e); -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/XmlSerializerBase.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/XmlString.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/gteufl/HeuristicLab.Persistence/3.3/Default/Xml/XmlStringConstants.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab.
Note: See TracChangeset
for help on using the changeset viewer.