Index: trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/EasyXmlGenerator.cs
===================================================================
--- trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/EasyXmlGenerator.cs	(revision 3935)
+++ trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/EasyXmlGenerator.cs	(revision 3935)
@@ -0,0 +1,201 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Collections.Generic;
+using System;
+using System.Text;
+using HeuristicLab.Persistence.Interfaces;
+using HeuristicLab.Persistence.Core;
+using System.IO;
+using ICSharpCode.SharpZipLib.Zip;
+using HeuristicLab.Tracing;
+using HeuristicLab.Persistence.Core.Tokens;
+using System.IO.Compression;
+using HeuristicLab.Persistence.Auxiliary;
+
+namespace HeuristicLab.Persistence.Default.Xml {
+
+
+  /// <summary>
+  /// Main entry point of persistence to XML. Use the static methods to serialize
+  /// to a file or to a stream.
+  /// </summary>
+  public class ReadableXmlGenerator : XmlGenerator {
+
+    protected Dictionary<int, string> typeCache = new Dictionary<int, string>();
+
+    /// <summary>
+    /// Formats the specified begin token.
+    /// </summary>
+    /// <param name="beginToken">The begin token.</param>
+    /// <returns>The token in serialized form.</returns>
+    protected override string Format(BeginToken beginToken) {
+      var dict = new Dictionary<string, object> {
+          {"name", beginToken.Name},
+          {"id", beginToken.Id}};
+      return CreateNodeStart(typeCache[beginToken.TypeId], dict);        
+    }
+
+    /// <summary>
+    /// Formats the specified end token.
+    /// </summary>
+    /// <param name="endToken">The end token.</param>
+    /// <returns>The token in serialized form.</returns>
+    protected override string Format(EndToken endToken) {
+      return CreateNodeEnd(typeCache[endToken.TypeId]);
+    }
+
+    /// <summary>
+    /// Formats the specified data token.
+    /// </summary>
+    /// <param name="dataToken">The data token.</param>
+    /// <returns>The token in serialized form.</returns>
+    protected override string Format(PrimitiveToken dataToken) {
+      var dict = new Dictionary<string, object> {
+            {"name", dataToken.Name},
+            {"id", dataToken.Id}};
+      return CreateNode(typeCache[dataToken.TypeId], dict,
+        ((XmlString)dataToken.SerialData).Data);
+    }
+
+    /// <summary>
+    /// Formats the specified ref token.
+    /// </summary>
+    /// <param name="refToken">The ref token.</param>
+    /// <returns>The token in serialized form.</returns>
+    protected override string Format(ReferenceToken refToken) {
+      return CreateNode(refToken.Id.ToString(),
+        new Dictionary<string, object> {
+          {"name", refToken.Name}});
+    }
+
+    /// <summary>
+    /// Formats the specified null ref token.
+    /// </summary>
+    /// <param name="nullRefToken">The null ref token.</param>
+    /// <returns>The token in serialized form.</returns>
+    protected override string Format(NullReferenceToken nullRefToken) {
+      return CreateNode(XmlStringConstants.NULL,
+        new Dictionary<string, object>{
+          {"name", nullRefToken.Name}});
+    }
+
+    /// <summary>
+    /// Formats the specified meta info begin token.
+    /// </summary>
+    /// <param name="metaInfoBeginToken">The meta info begin token.</param>
+    /// <returns>The token in serialized form.</returns>
+    protected override string Format(MetaInfoBeginToken metaInfoBeginToken) {
+      return CreateNodeStart(XmlStringConstants.METAINFO);
+    }
+
+    /// <summary>
+    /// Formats the specified meta info end token.
+    /// </summary>
+    /// <param name="metaInfoEndToken">The meta info end token.</param>
+    /// <returns>The token in serialized form.</returns>
+    protected override string Format(MetaInfoEndToken metaInfoEndToken) {
+      return CreateNodeEnd(XmlStringConstants.METAINFO);
+    }
+
+    /// <summary>
+    /// Formats the specified token.
+    /// </summary>
+    /// <param name="token">The token.</param>
+    /// <returns>The token in serialized form.</returns>
+    protected override string Format(TypeToken token) {
+      typeCache[token.Id] = TypeNameParser.Parse(token.TypeName).GetTypeNameInCode(false);
+      return "";
+    }
+
+    /// <summary>
+    /// Serialize an object into a file.
+    /// The XML configuration is obtained from the <c>ConfigurationService</c>.
+    /// The file is actually a ZIP file.
+    /// Compression level is set to 5 and needed assemblies are not included.
+    /// </summary>
+    /// <param name="o">The object.</param>
+    /// <param name="filename">The filename.</param>
+    public static void Serialize(object o, string filename) {
+      Serialize(o, filename, ConfigurationService.Instance.GetConfiguration(new XmlFormat()));
+    }
+
+    /// <summary>
+    /// Serializes the specified object into a file.
+    /// Needed assemblies are not included, ZIP compression level is set to 5.
+    /// </summary>
+    /// <param name="obj">The object.</param>
+    /// <param name="filename">The filename.</param>
+    /// <param name="config">The configuration.</param>
+    public static void Serialize(object obj, string filename, Configuration config) {      
+      try {
+        string tempfile = Path.GetTempFileName();
+        DateTime start = DateTime.Now;
+        using (FileStream stream = File.Create(tempfile)) {
+          Serialize(obj, stream, config);
+        }
+        Logger.Info(String.Format("easy serialization took {0} seconds",
+          (DateTime.Now - start).TotalSeconds));
+        File.Copy(tempfile, filename, true);
+        File.Delete(tempfile);
+      } catch (Exception) {
+        Logger.Warn("Exception caught, no data has been written.");
+        throw;
+      }
+    }
+
+    /// <summary>
+    /// Serializes the specified object into a stream using the <see cref="XmlFormat"/>
+    /// obtained from the <see cref="ConfigurationService"/>.
+    /// </summary>
+    /// <param name="obj">The object.</param>
+    /// <param name="stream">The stream.</param>
+    public static void Serialize(object obj, Stream stream) {
+      Serialize(obj, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()));
+    }
+
+
+    /// <summary>
+    /// Serializes the specified object into a stream.
+    /// </summary>
+    /// <param name="obj">The object.</param>
+    /// <param name="stream">The stream.</param>
+    /// <param name="config">The configuration.</param>
+    public static void Serialize(object obj, Stream stream, Configuration config) {      
+      try {
+        using (StreamWriter writer = new StreamWriter(stream)) {
+          Serializer serializer = new Serializer(obj, config);
+          serializer.InterleaveTypeInformation = true;
+          ReadableXmlGenerator generator = new ReadableXmlGenerator();
+          foreach (ISerializationToken token in serializer) {
+            string line = generator.Format(token);
+            writer.Write(line);
+          }
+          writer.Flush();
+        }
+      } catch (PersistenceException) {
+        throw;
+      } catch (Exception e) {
+        throw new PersistenceException("Unexpected exception during Serialization.", e);
+      }
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
===================================================================
--- trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs	(revision 3917)
+++ trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs	(revision 3935)
@@ -40,6 +40,6 @@
   public class XmlGenerator : GeneratorBase<string> {
 
-    private int depth;
-    private int Depth {
+    protected int depth;
+    protected int Depth {
       get {
         return depth;
@@ -51,5 +51,5 @@
     }
 
-    private string prefix;
+    protected string prefix;
 
 
@@ -61,7 +61,7 @@
     }
 
-    private enum NodeType { Start, End, Inline } ;
-
-    private static void AddXmlTagContent(StringBuilder sb, string name, Dictionary<string, object> attributes) {
+    protected enum NodeType { Start, End, Inline } ;
+
+    protected static void AddXmlTagContent(StringBuilder sb, string name, Dictionary<string, object> attributes) {
       sb.Append(name);
       foreach (var attribute in attributes) {
@@ -76,5 +76,5 @@
     }
 
-    private static void AddXmlStartTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {
+    protected static void AddXmlStartTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {
       sb.Append('<');
       AddXmlTagContent(sb, name, attributes);
@@ -82,5 +82,5 @@
     }
 
-    private static void AddXmlInlineTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {
+    protected static void AddXmlInlineTag(StringBuilder sb, string name, Dictionary<string, object> attributes) {
       sb.Append('<');
       AddXmlTagContent(sb, name, attributes);
@@ -88,5 +88,5 @@
     }
 
-    private static void AddXmlEndTag(StringBuilder sb, string name) {
+    protected static void AddXmlEndTag(StringBuilder sb, string name) {
       sb.Append("</");
       sb.Append(name);
@@ -94,5 +94,5 @@
     }
 
-    private string CreateNodeStart(string name, Dictionary<string, object> attributes) {
+    protected string CreateNodeStart(string name, Dictionary<string, object> attributes) {
       StringBuilder sb = new StringBuilder();
       sb.Append(prefix);
@@ -103,9 +103,9 @@
     }
 
-    private string CreateNodeStart(string name) {
+    protected string CreateNodeStart(string name) {
       return CreateNodeStart(name, new Dictionary<string, object>());
     }
 
-    private string CreateNodeEnd(string name) {
+    protected string CreateNodeEnd(string name) {
       Depth -= 1;
       StringBuilder sb = new StringBuilder();
@@ -116,5 +116,5 @@
     }
 
-    private string CreateNode(string name, Dictionary<string, object> attributes) {
+    protected string CreateNode(string name, Dictionary<string, object> attributes) {
       StringBuilder sb = new StringBuilder();
       sb.Append(prefix);
@@ -124,5 +124,5 @@
     }
 
-    private string CreateNode(string name, Dictionary<string, object> attributes, string content) {
+    protected string CreateNode(string name, Dictionary<string, object> attributes, string content) {
       StringBuilder sb = new StringBuilder();
       sb.Append(prefix);
@@ -148,5 +148,5 @@
     }
 
-    private void AddTypeInfo(int typeId, Dictionary<string, object> dict) {
+    protected void AddTypeInfo(int typeId, Dictionary<string, object> dict) {
       if (lastTypeToken != null) {
         if (typeId == lastTypeToken.Id) {
@@ -225,5 +225,5 @@
     }
 
-    private TypeToken lastTypeToken;
+    protected TypeToken lastTypeToken;
     /// <summary>
     /// Formats the specified token.
@@ -236,5 +236,5 @@
     }
 
-    private string FlushTypeToken() {
+    protected string FlushTypeToken() {
       if (lastTypeToken == null)
         return "";
