Changeset 1667


Ignore:
Timestamp:
04/27/09 14:18:39 (12 years ago)
Author:
epitzer
Message:

Convert persistence of Core plugin to new persistence framework. The target framework has been upgraded from 2.0 to 3.5 and events during persistence are not generated anymore. (#603)

Location:
trunk/sources/HeuristicLab.Core/3.3
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/AtomicOperation.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public class AtomicOperation : ItemBase, IOperation {
     33
     34    [Storable]
    3235    private IOperator myOperator;
    3336    /// <summary>
     
    3740      get { return myOperator; }
    3841    }
    39     private IScope myScope; 
     42
     43    [Storable]
     44    private IScope myScope;
    4045    /// <summary>
    4146    /// Gets the current scope as <see cref="IScope"/>.
     
    7479      return clone;
    7580    }
    76 
    77     #region Persistence Methods
    78 
    79     /// <summary>
    80     ///  Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    81     /// </summary>
    82     /// <remarks>Calls <see cref="HeuristicLab.Core.StorableBase.GetXmlNode"/> of base
    83     /// class <see cref="ItemBase"/>. <br/>
    84     /// The operator is saved as child node having the tag name <c>Operator</c>.<br/>
    85     /// The scope is also saved as a child node having the tag name <c>Scope</c>.</remarks>
    86     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    87     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    88     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    89     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    90     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    91       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    92       node.AppendChild(PersistenceManager.Persist("Operator", Operator, document, persistedObjects));
    93       node.AppendChild(PersistenceManager.Persist("Scope", Scope, document, persistedObjects));
    94       return node;
    95     }
    96     /// <summary>
    97     /// Loads the persisted operation from the specified <paramref name="node"/>.
    98     /// </summary>
    99     /// <remarks>Calls <see cref="HeuristicLab.Core.StorableBase.Populate"/> of base class
    100     /// <see cref="ItemBase"/>.<br/>
    101     /// The operator must be saved as a child node with the tag name <c>Operator</c>, also the scope must
    102     /// be saved as a child node having the tag name <c>Scope</c> (see <see cref="GetXmlNode"/>).</remarks>
    103     /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param>
    104     /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    105     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    106       base.Populate(node, restoredObjects);
    107       myOperator = (IOperator)PersistenceManager.Restore(node.SelectSingleNode("Operator"), restoredObjects);
    108       myScope = (IScope)PersistenceManager.Restore(node.SelectSingleNode("Scope"), restoredObjects);
    109     }
    110     #endregion
    11181  }
    11282}
  • trunk/sources/HeuristicLab.Core/3.3/CompositeOperation.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3132  /// </summary>
    3233  public class CompositeOperation : ItemBase, IOperation {
     34
     35    [Storable]
    3336    private bool myExecuteInParallel;
    34 
    3537    /// <summary>
    3638    /// Gets or sets the bool value, whether the operation should be executed in parallel or not. 
     
    4042      set { myExecuteInParallel = value; }
    4143    }
     44
     45    [Storable]
    4246    private List<IOperation> myOperations;
    4347    /// <summary>
     
    8892      return clone;
    8993    }
    90 
    91     #region Persistence Methods
    92     /// <summary>
    93     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    94     /// </summary>
    95     /// <remarks>Calls <see cref="HeuristicLab.Core.StorableBase.GetXmlNode"/> of base
    96     /// class <see cref="ItemBase"/>.<br/>
    97     /// The <see cref="ExecuteInParallel"/> property is saved as <see cref="XmlAttribute"/> with the
    98     /// tag name <c>ExecuteInParallel</c>. A child node with tag name <c>Operations</c> is created where
    99     /// all operations are saved as child nodes.</remarks>
    100     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    101     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    102     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    103     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    104     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    105       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    106       XmlAttribute parallelAttribute = document.CreateAttribute("ExecuteInParallel");
    107       parallelAttribute.Value = ExecuteInParallel.ToString();
    108       node.Attributes.Append(parallelAttribute);
    109 
    110       XmlNode operationsNode = document.CreateNode(XmlNodeType.Element, "Operations", null);
    111       for (int i = 0; i < Operations.Count; i++)
    112         operationsNode.AppendChild(PersistenceManager.Persist(Operations[i], document, persistedObjects));
    113       node.AppendChild(operationsNode);
    114       return node;
    115     }
    116     /// <summary>
    117     /// Loads the persisted operation from the specified <paramref name="node"/>.
    118     /// </summary>
    119     /// <remarks>The <see cref="ExecuteInParallel"/> property must be saved as <see cref="XmlAttribute"/>
    120     /// with the tag name <c>ExecuteInParallel</c>. <br/>
    121     /// The single operations must be saved as child nodes of a node with tag name <c>Operations</c>,
    122     /// being a child node of the current instance. <br/>
    123     /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks>
    124     /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param>
    125     /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    126     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    127       base.Populate(node, restoredObjects);
    128 
    129       myExecuteInParallel = bool.Parse(node.Attributes["ExecuteInParallel"].Value);
    130 
    131       XmlNode operationsNode = node.SelectSingleNode("Operations");
    132       for (int i = 0; i < operationsNode.ChildNodes.Count; i++)
    133         AddOperation((IOperation)PersistenceManager.Restore(operationsNode.ChildNodes[i], restoredObjects));
    134     }
    135     #endregion
    13694  }
    13795}
  • trunk/sources/HeuristicLab.Core/3.3/ConstrainedItemBase.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public abstract class ConstrainedItemBase : ItemBase, IConstrainedItem {
     33
     34    [Storable]
    3235    private List<IConstraint> myConstraints;
    3336    /// <summary>
     
    144147        ConstraintRemoved(this, new ConstraintEventArgs(constraint));
    145148    }
    146 
    147     #region Persistence Methods 
    148     /// <summary>
    149     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    150     /// </summary>
    151     /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>. <br/>
    152     /// For saving the constraints a child node is created having the tag name <c>Constraints</c>. Beyond this
    153     /// child node all constraints are saved as child nodes themselves.</remarks>
    154     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    155     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    156     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    157     /// (Needed to avoid cycles.)</param>
    158     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    159     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    160       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    161       if (Constraints.Count > 0) {
    162         XmlNode constraintsNode = document.CreateNode(XmlNodeType.Element, "Constraints", null);
    163         foreach (IConstraint constraint in Constraints)
    164           constraintsNode.AppendChild(PersistenceManager.Persist(constraint, document, persistedObjects));
    165         node.AppendChild(constraintsNode);
    166       }
    167       return node;
    168     }
    169     /// <summary>
    170     /// Loads the persisted item from the specified <paramref name="node"/>.
    171     /// </summary>
    172     /// <remarks>See <see cref="GetXmlNode"/> to get information about how the constrained item must
    173     /// be saved. <br/>
    174     /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks>
    175     /// <param name="node">The <see cref="XmlNode"/> where the constrained item is saved.</param>
    176     /// <param name="restoredObjects">The dictionary of all already restored objects.
    177     /// (Needed to avoid cycles.)</param>
    178     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    179       base.Populate(node, restoredObjects);
    180       XmlNode constraintsNode = node.SelectSingleNode("Constraints");
    181       if (constraintsNode != null) {
    182         myConstraints.Clear();
    183         foreach (XmlNode constraintNode in constraintsNode.ChildNodes)
    184           AddConstraint((IConstraint)PersistenceManager.Restore(constraintNode, restoredObjects));
    185       }
    186     }
    187     #endregion
    188149  }
    189150}
  • trunk/sources/HeuristicLab.Core/3.3/EngineBase.cs

    r1529 r1667  
    2525using System.Xml;
    2626using System.Threading;
     27using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2728
    2829namespace HeuristicLab.Core {
     
    3334  /// </summary>
    3435  public abstract class EngineBase : ItemBase, IEngine {
     36
    3537    /// <summary>
    3638    /// Field of the current instance that represent the operator graph.
    3739    /// </summary>
     40    [Storable]
    3841    protected IOperatorGraph myOperatorGraph;
    3942    /// <summary>
     
    4649    /// Field of the current instance that represent the global scope.
    4750    /// </summary>
     51    [Storable]
    4852    protected IScope myGlobalScope;
    4953    /// <summary>
     
    5458    }
    5559
     60    [Storable]
    5661    private TimeSpan myExecutionTime;
    5762    /// <summary>
     
    7075    /// Field of the current instance that represent the execution stack.
    7176    /// </summary>
     77    [Storable]
    7278    protected Stack<IOperation> myExecutionStack;
    7379    /// <summary>
     
    7783      get { return myExecutionStack; }
    7884    }
    79    
     85
    8086    /// <summary>
    8187    /// Flag of the current instance whether it is currently running.
     
    136142      clone.myCanceled = Canceled;
    137143      return clone;
    138      
    139144    }
    140145
     
    276281        Finished(this, new EventArgs());
    277282    }
    278 
    279     #region Persistence Methods
    280     /// <summary>
    281     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    282     /// </summary>
    283     /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/>
    284     /// A quick overview how the single elements of the current instance are saved:
    285     /// <list type="bullet">
    286     /// <item>
    287     /// <term>Operator graph: </term>
    288     /// <description>Saved as a child node with the tag name <c>OperatorGraph</c>.</description>
    289     /// </item>
    290     /// <item>
    291     /// <term>Global scope: </term>
    292     /// <description>Saved as a child node with the tag name <c>GlobalScope</c>.</description>
    293     /// </item>
    294     /// <item>
    295     /// <term>Execution stack: </term>
    296     /// <description>A child node is created with the tag name <c>ExecutionStack</c>. Beyond this child node
    297     /// all operations of the execution stack are saved as child nodes.</description>
    298     /// </item>
    299     /// <item>
    300     /// <term>Execution time: </term>
    301     /// <description>Saved as a child node with the tag name <c>ExecutionTime</c>, where the execution
    302     /// time is saved as string in the node's inner text.</description>
    303     /// </item>
    304     /// </list></remarks>
    305     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    306     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    307     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    308     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    309     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    310       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    311 
    312       node.AppendChild(PersistenceManager.Persist("OperatorGraph", OperatorGraph, document, persistedObjects));
    313       node.AppendChild(PersistenceManager.Persist("GlobalScope", GlobalScope, document, persistedObjects));
    314 
    315       XmlNode stackNode = document.CreateNode(XmlNodeType.Element, "ExecutionStack", null);
    316       IOperation[] operations = new IOperation[ExecutionStack.Count];
    317       ExecutionStack.CopyTo(operations, 0);
    318       for (int i = 0; i < operations.Length; i++)
    319         stackNode.AppendChild(PersistenceManager.Persist(operations[i], document, persistedObjects));
    320       node.AppendChild(stackNode);
    321 
    322       XmlNode timeNode = document.CreateNode(XmlNodeType.Element, "ExecutionTime", null);
    323       timeNode.InnerText = ExecutionTime.ToString();
    324       node.AppendChild(timeNode);
    325       return node;
    326     }
    327     /// <summary>
    328     ///  Loads the persisted instance from the specified <paramref name="node"/>.
    329     /// </summary>
    330     /// <remarks>See <see cref="GetXmlNode"/> to get information on how the instance must be saved. <br/>
    331     /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks>
    332     /// <param name="node">The <see cref="XmlNode"/> where the engine is saved.</param>
    333     /// <param name="restoredObjects">The dictionary of all already restored objects.
    334     /// (Needed to avoid cycles.)</param>
    335     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    336       base.Populate(node, restoredObjects);
    337       myOperatorGraph = (IOperatorGraph)PersistenceManager.Restore(node.SelectSingleNode("OperatorGraph"), restoredObjects);
    338       myGlobalScope = (IScope)PersistenceManager.Restore(node.SelectSingleNode("GlobalScope"), restoredObjects);
    339 
    340       XmlNode stackNode = node.SelectSingleNode("ExecutionStack");
    341       for (int i = stackNode.ChildNodes.Count - 1; i >= 0; i--)
    342         myExecutionStack.Push((IOperation)PersistenceManager.Restore(stackNode.ChildNodes[i], restoredObjects));
    343 
    344       XmlNode timeNode = node.SelectSingleNode("ExecutionTime");
    345       myExecutionTime = TimeSpan.Parse(timeNode.InnerText);
    346     }
    347     #endregion
    348283  }
    349284}
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r1663 r1667  
    3232    <UseApplicationTrust>false</UseApplicationTrust>
    3333    <BootstrapperEnabled>true</BootstrapperEnabled>
     34    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    3435  </PropertyGroup>
    3536  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     
    9091  <ItemGroup>
    9192    <Reference Include="System" />
     93    <Reference Include="System.Core">
     94      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     95    </Reference>
    9296    <Reference Include="System.Data" />
    9397    <Reference Include="System.Drawing" />
     
    268272  </ItemGroup>
    269273  <ItemGroup>
     274    <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
     275      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
     276      <Name>HeuristicLab.Persistence-3.3</Name>
     277    </ProjectReference>
    270278    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
    271279      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLabCorePlugin.cs

    r1529 r1667  
    3030  /// Plugin class for HeuristicLab.Core plugin.
    3131  /// </summary>
    32   [ClassInfo(Name = "HeuristicLab.Core-3.2")]
    33   [PluginFile(Filename = "HeuristicLab.Core-3.2.dll", Filetype = PluginFileType.Assembly)]
     32  [ClassInfo(Name = "HeuristicLab.Core-3.3")]
     33  [PluginFile(Filename = "HeuristicLab.Core-3.3.dll", Filetype = PluginFileType.Assembly)]
     34  [Dependency(Dependency="HeuristicLab.Persistence-3.3")]
    3435  public class HeuristicLabCorePlugin : PluginBase {
    3536  }
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IStorable.cs

    r776 r1667  
    2626
    2727namespace HeuristicLab.Core {
     28
    2829  /// <summary>
    2930  /// Interface to represent objects that are de- and serializeable.
    3031  /// </summary>
    3132  public interface IStorable {
     33
    3234    /// <summary>
    3335    /// Gets the objects unique identifier.
     
    4042    /// <returns>The cloned object.</returns>
    4143    object Clone();
     44
    4245    /// <summary>
    4346    /// Clones the current instance, considering already cloned objects.
     
    4649    /// <returns>The cloned object.</returns>
    4750    object Clone(IDictionary<Guid, object> clonedObjects);
    48 
    49     /// <summary>
    50     /// Saves the current instance as <see cref="XmlNode"/> in the specified
    51     /// <typeparamref name="document"/>.
    52     /// </summary>
    53     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    54     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    55     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    56     /// (Needed to avoid cycles.)</param>
    57     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    58     XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects);
    59     /// <summary>
    60     /// Loads the persisted object from the specified <paramref name="node"/>.
    61     /// </summary>
    62     /// <param name="node">The <see cref="XmlNode"/> where the object is saved.</param>
    63     /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid
    64     /// cycles.)</param>
    65     void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects);
    6651  }
    6752}
  • trunk/sources/HeuristicLab.Core/3.3/OperatorBase.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public abstract class OperatorBase : ConstrainedItemBase, IOperator {
     33
     34    [Storable]
    3235    private string myName;
    3336    /// <summary>
     
    5962      get { return myCanceled; }
    6063    }
     64
     65    [Storable]
    6166    private bool myBreakpoint;
    6267    /// <inheritdoc/>
     
    7277    }
    7378
     79    [Storable]
    7480    private List<IOperator> mySubOperators;
    7581    /// <summary>
     
    8086      get { return mySubOperators.AsReadOnly(); }
    8187    }
     88
     89    [Storable]
    8290    private Dictionary<string, IVariableInfo> myVariableInfos;
    8391    /// <inheritdoc/>
     
    8593      get { return myVariableInfos.Values; }
    8694    }
     95
     96    [Storable]
    8797    private Dictionary<string, IVariable> myVariables;
    8898    /// <inheritdoc/>
     
    589599      }
    590600    }
    591 
    592     #region Persistence Methods
    593     /// <summary>
    594     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    595     /// </summary>
    596     /// <remarks>
    597     /// Calls <see cref="ConstrainedItemBase.GetXmlNode"/> of base class <see cref="ConstrainedItemBase"/>.
    598     /// <br/>A quick overview how the single elements of the current instance are saved:
    599     /// <list type="bullet">
    600     /// <item>
    601     /// <term>Name: </term>
    602     /// <description>Saved as an <see cref="XmlAttribute"/> with the name <c>Name</c>.</description>
    603     /// </item>
    604     /// <item>
    605     /// <term>Breakpoint: </term>
    606     /// <description>Is only saved if it set to <c>true</c>.
    607     /// Saved as an <see cref="XmlAttribute"/> with the name <c>Breakpoint</c>.</description>
    608     /// </item>
    609     /// <item>
    610     /// <term>Sub operators: </term>
    611     /// <description>Saved as child node with tag name <c>SubOperators</c>. All sub operators are themselves
    612     /// saved as child nodes.</description>
    613     /// </item>
    614     /// <item>
    615     /// <term>Variable infos: </term>
    616     /// <description>Saved as child node with tag name <c>VariableInfos</c>. All variable infos are themselves
    617     /// saved as child nodes.</description>
    618     /// </item>
    619     /// <item>
    620     /// <term>Variables: </term>
    621     /// <description>Saved as child node with tag name <c>Variables</c>. All variables are themselves
    622     /// saved as child nodes.</description>
    623     /// </item>
    624     /// </list>
    625     /// </remarks>
    626     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    627     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    628     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    629     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    630     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    631       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    632       XmlAttribute nameAttribute = document.CreateAttribute("Name");
    633       nameAttribute.Value = Name;
    634       node.Attributes.Append(nameAttribute);
    635       if (Breakpoint) {
    636         XmlAttribute breakpointAttribute = document.CreateAttribute("Breakpoint");
    637         breakpointAttribute.Value = Breakpoint.ToString();
    638         node.Attributes.Append(breakpointAttribute);
    639       }
    640       XmlNode subOperatorsNode = document.CreateNode(XmlNodeType.Element, "SubOperators", null);
    641       for (int i = 0; i < SubOperators.Count; i++)
    642         subOperatorsNode.AppendChild(PersistenceManager.Persist(SubOperators[i], document, persistedObjects));
    643       node.AppendChild(subOperatorsNode);
    644       XmlNode infosNode = document.CreateNode(XmlNodeType.Element, "VariableInfos", null);
    645       foreach (IVariableInfo info in myVariableInfos.Values)
    646         infosNode.AppendChild(PersistenceManager.Persist(info, document, persistedObjects));
    647       node.AppendChild(infosNode);
    648       XmlNode variablesNode = document.CreateNode(XmlNodeType.Element, "Variables", null);
    649       foreach (IVariable variable in myVariables.Values)
    650         variablesNode.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects));
    651       node.AppendChild(variablesNode);
    652       return node;
    653     }
    654     /// <summary>
    655     /// Loads the persisted operation from the specified <paramref name="node"/>.
    656     /// </summary>
    657     /// <remarks>Calls <see cref="ConstrainedItemBase.Populate"/> of base class
    658     /// <see cref="ConstrainedItemBase"/>.
    659     /// For informations how the different elements must be saved please see <see cref="GetXmlNode"/>.</remarks>
    660     /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param>
    661     /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
    662     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    663       base.Populate(node, restoredObjects);
    664       myName = node.Attributes["Name"].Value;
    665       if (node.Attributes["Breakpoint"] != null)
    666         myBreakpoint = bool.Parse(node.Attributes["Breakpoint"].Value);
    667       XmlNode subOperatorsNode = node.SelectSingleNode("SubOperators");
    668       for (int i = 0; i < subOperatorsNode.ChildNodes.Count; i++)
    669         AddSubOperator((IOperator)PersistenceManager.Restore(subOperatorsNode.ChildNodes[i], restoredObjects));
    670       XmlNode infosNode = node.SelectSingleNode("VariableInfos");
    671       myVariableInfos.Clear();
    672       foreach (XmlNode infoNode in infosNode.ChildNodes)
    673         AddVariableInfo((IVariableInfo)PersistenceManager.Restore(infoNode, restoredObjects));
    674       XmlNode variablesNode = node.SelectSingleNode("Variables");
    675       myVariables.Clear();
    676       foreach (XmlNode variableNode in variablesNode.ChildNodes)
    677         AddVariable((IVariable)PersistenceManager.Restore(variableNode, restoredObjects));
    678     }
    679     #endregion
    680601  }
    681602}
  • trunk/sources/HeuristicLab.Core/3.3/OperatorGraph.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public class OperatorGraph : ItemBase, IOperatorGraph {
     33
     34    [Storable]
    3235    private IDictionary<Guid, IOperator> myOperators;
    3336    /// <summary>
     
    3740      get { return myOperators.Values; }
    3841    }
     42
     43    [Storable]
    3944    private IOperator myInitialOperator;
    4045    /// <summary>
     
    165170        InitialOperatorChanged(this, new EventArgs());
    166171    }
    167 
    168     #region Persistence Methods
    169     /// <summary>
    170     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    171     /// </summary>
    172     /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/>
    173     /// To save the operators of the current instance a child node is created with the tag name
    174     /// <c>Operators</c>. Beyond this child node all operators are saved as child nodes themselves.<br/>
    175     /// The initial operator is saved as child node with the tag name <c>InitialOperator</c>.</remarks>
    176     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    177     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    178     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    179     /// (Needed to avoid cycles.)</param>
    180     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    181     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    182       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    183       XmlNode ops = document.CreateNode(XmlNodeType.Element, "Operators", null);
    184       foreach (IOperator op in myOperators.Values)
    185         ops.AppendChild(PersistenceManager.Persist(op, document, persistedObjects));
    186       node.AppendChild(ops);
    187       if (InitialOperator != null)
    188         node.AppendChild(PersistenceManager.Persist("InitialOperator", InitialOperator, document, persistedObjects));
    189       return node;
    190     }
    191     /// <summary>
    192     /// Loads the persisted operator graph from the specified <paramref name="node"/>.
    193     /// </summary>
    194     /// <remarks>See <see cref="GetXmlNode"/> to get more information about how the graph must be saved. <br/>
    195     /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks>
    196     /// <param name="node">The <see cref="XmlNode"/> where the operator graph is saved.</param>
    197     /// <param name="restoredObjects">The dictionary of all already restored objects.
    198     /// (Needed to avoid cycles.)</param>
    199     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    200       base.Populate(node, restoredObjects);
    201 
    202       XmlNode ops = node.SelectSingleNode("Operators");
    203       for (int i = 0; i < ops.ChildNodes.Count; i++) {
    204         XmlNode opNode = ops.ChildNodes[i];
    205         IOperator op = (IOperator)PersistenceManager.Restore(opNode, restoredObjects);
    206         myOperators.Add(op.Guid, op);
    207       }
    208 
    209       XmlNode initial = node.SelectSingleNode("InitialOperator");
    210       if (initial != null)
    211         myInitialOperator = (IOperator)PersistenceManager.Restore(initial, restoredObjects);
    212     }
    213     #endregion
    214172  }
    215173}
  • trunk/sources/HeuristicLab.Core/3.3/OperatorGroup.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public class OperatorGroup : StorableBase, IOperatorGroup {
     33
     34    [Storable]
    3235    private string myName;
    3336    /// <summary>
     
    4447      }
    4548    }
     49
     50    [Storable]
    4651    private List<IOperatorGroup> mySubGroups;
    4752    /// <summary>
     
    5257      get { return mySubGroups.AsReadOnly(); }
    5358    }
     59
     60    [Storable]
    5461    private List<IOperator> myOperators;
    5562    /// <summary>
     
    128135      }
    129136    }
    130 
    131     #region Persistence Methods
    132     /// <summary>
    133     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    134     /// </summary>
    135     /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/>
    136     /// A quick overview how the single elements of the current instance are saved:
    137     /// <list type="bullet">
    138     /// <item>
    139     /// <term>Name: </term>
    140     /// <description>Saved as an <see cref="XmlAttribute"/> with attribute name <c>Name</c>.</description>
    141     /// </item>
    142     /// <item>
    143     /// <term>Sub groups: </term>
    144     /// <description>A child node is created with tag name <c>SubGroups</c>. Beyond this child node
    145     /// all sub operator groups are saved as child nodes themselves.</description>
    146     /// </item>
    147     /// <item>
    148     /// <term>Operators: </term>
    149     /// <description>A child node is created with tag name <c>Operators</c>. Beyond this child node
    150     /// all operators are saved as child nodes themselves.</description>
    151     /// </item>
    152     /// </list>
    153     /// </remarks>
    154     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    155     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    156     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    157     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    158     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    159       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    160       XmlAttribute nameAttribute = document.CreateAttribute("Name");
    161       nameAttribute.Value = Name;
    162       node.Attributes.Append(nameAttribute);
    163       XmlNode subGroupsNode = document.CreateNode(XmlNodeType.Element, "SubGroups", null);
    164       foreach (IOperatorGroup group in SubGroups)
    165         subGroupsNode.AppendChild(PersistenceManager.Persist(group, document, persistedObjects));
    166       node.AppendChild(subGroupsNode);
    167       XmlNode operatorsNode = document.CreateNode(XmlNodeType.Element, "Operators", null);
    168       foreach (IOperator op in Operators)
    169         operatorsNode.AppendChild(PersistenceManager.Persist(op, document, persistedObjects));
    170       node.AppendChild(operatorsNode);
    171       return node;
    172     }
    173     /// <summary>
    174     /// Loads the persisted operator group from the specified <paramref name="node"/>.
    175     /// </summary>
    176     /// <remarks>See <see cref="GetXmlNode"/> to get information about how the data must be saved. <br/>
    177     /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="StorableBase"/>.</remarks>
    178     /// <param name="node">The <see cref="XmlNode"/> where the boolean value is saved.</param>
    179     /// <param name="restoredObjects">The dictionary of all already restored objects.
    180     /// (Needed to avoid cycles.)</param>
    181     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    182       base.Populate(node, restoredObjects);
    183       myName = node.Attributes["Name"].Value;
    184       XmlNode subGroupsNode = node.SelectSingleNode("SubGroups");
    185       foreach (XmlNode subGroupNode in subGroupsNode.ChildNodes)
    186         AddSubGroup((IOperatorGroup)PersistenceManager.Restore(subGroupNode, restoredObjects));
    187       XmlNode operatorsNode = node.SelectSingleNode("Operators");
    188       foreach (XmlNode operatorNode in operatorsNode.ChildNodes)
    189         AddOperator((IOperator)PersistenceManager.Restore(operatorNode, restoredObjects));
    190     }
    191     #endregion
    192137  }
    193138}
  • trunk/sources/HeuristicLab.Core/3.3/OperatorLibrary.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public class OperatorLibrary : ItemBase, IOperatorLibrary, IEditable {
     33
     34    [Storable]
    3235    private IOperatorGroup myGroup;
    3336    /// <summary>
     
    7376      return clone;
    7477    }
    75 
    76     #region Persistence Methods
    77     /// <summary>
    78     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    79     /// </summary>
    80     /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/>
    81     /// The operator group is saved as a child node with the tag name <c>OperatorGroup</c>.</remarks>
    82     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    83     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    84     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    85     /// (Needed to avoid cycles.)</param>
    86     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    87     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    88       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    89       node.AppendChild(PersistenceManager.Persist("OperatorGroup", Group, document, persistedObjects));
    90       return node;
    91     }
    92     /// <summary>
    93     /// Loads the persisted operator library from the specified <paramref name="node"/>.
    94     /// </summary>
    95     /// <remarks>Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.<br/>
    96     /// See <see cref="GetXmlNode"/> for further information on how the data must be saved.</remarks>
    97     /// <param name="node">The <see cref="XmlNode"/> where the operator library is saved.</param>
    98     /// <param name="restoredObjects">The dictionary of all already restored objects.
    99     /// (Needed to avoid cycles.)</param>
    100     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    101       base.Populate(node, restoredObjects);
    102       myGroup = (IOperatorGroup)PersistenceManager.Restore(node.SelectSingleNode("OperatorGroup"), restoredObjects);
    103     }
    104     #endregion
    10578  }
    10679}
  • trunk/sources/HeuristicLab.Core/3.3/PersistenceManager.cs

    r1529 r1667  
    2727using System.IO.Compression;
    2828using HeuristicLab.PluginInfrastructure;
     29using HeuristicLab.Persistence.Default.Xml;
    2930
    3031namespace HeuristicLab.Core {
     
    3435  public static class PersistenceManager {
    3536    /// <summary>
    36     /// Creates an <see cref="XmlDocument"/> to persist an object with xml declaration.
    37     /// </summary>
    38     /// <returns>The created <see cref="XmlDocument"/>.</returns>
    39     public static XmlDocument CreateXmlDocument() {
    40       XmlDocument document = new XmlDocument();
    41       document.AppendChild(document.CreateXmlDeclaration("1.0", null, null));
    42       return document;
    43     }
    44     /// <summary>
    45     /// Saves the specified <paramref name="instance"/> in the specified <paramref name="document"/>
    46     /// if it has not already been serialized.
    47     /// </summary>
    48     /// <remarks>The tag name of the saved instance is its type name.<br/>
    49     /// The guid is saved as an <see cref="XmlAttribute"/> with tag name <c>GUID</c>.</remarks>
    50     /// <param name="instance">The object that should be saved.</param>
    51     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    52     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    53     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    54     public static XmlNode Persist(IStorable instance, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    55       string name = instance.GetType().Name;
    56       name = name.Replace('`', '_');
    57       return Persist(name, instance, document, persistedObjects);
    58     }
    59     /// <summary>
    60     /// Saves the specified <paramref name="instance"/> in the specified <paramref name="document"/>
    61     /// if it has not already been serialized.
    62     /// </summary>
    63     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    64     /// <param name="instance">The object that should be saved.</param>
    65     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    66     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    67     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    68     public static XmlNode Persist(string name, IStorable instance, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    69       if(persistedObjects.ContainsKey(instance.Guid)) {
    70         XmlNode node = document.CreateNode(XmlNodeType.Element, name, null);
    71         XmlAttribute guidAttribute = document.CreateAttribute("GUID");
    72         guidAttribute.Value = instance.Guid.ToString();
    73         node.Attributes.Append(guidAttribute);
    74         return node;
    75       } else {
    76         persistedObjects.Add(instance.Guid, instance);
    77         XmlNode node = instance.GetXmlNode(name, document, persistedObjects);
    78         return node;
    79       }
    80     }
    81     /// <summary>
    82     /// Loads a persisted object from the specified <paramref name="node"/>.
    83     /// </summary>
    84     /// <remarks>The guid is saved as an attribute with tag name <c>GUID</c>. The type of the
    85     /// persisted object is saved as attribute with tag name <c>Type</c>.<br/>
    86     /// Calls <c>instance.Populate</c>.</remarks>
    87     /// <param name="node">The <see cref="XmlNode"/> where the object is saved.</param>
    88     /// <param name="restoredObjects">A dictionary of all already restored objects.
    89     /// (Needed to avoid cycles.)</param>
    90     /// <returns>The loaded object.</returns>
    91     public static IStorable Restore(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    92       Guid guid = new Guid(node.Attributes["GUID"].Value);
    93       if(restoredObjects.ContainsKey(guid)) {
    94         return restoredObjects[guid];
    95       } else {
    96         Type type = Type.GetType(node.Attributes["Type"].Value, true);
    97         IStorable instance = (IStorable)Activator.CreateInstance(type);
    98         restoredObjects.Add(guid, instance);
    99         instance.Populate(node, restoredObjects);
    100         return instance;
    101       }
    102     }
    103     /// <summary>
    10437    /// Saves the specified <paramref name="instance"/> in the specified file through creating an
    10538    /// <see cref="XmlDocument"/>.
     
    10841    /// <param name="filename">The name of the file where the <paramref name="object"/> should be saved.</param>
    10942    public static void Save(IStorable instance, string filename) {
    110       using(FileStream stream = File.Create(filename)) {
    111         Save(instance, stream);
    112         stream.Close();
    113       }
     43      XmlGenerator.Serialize(instance, filename);
    11444    }
     45
    11546    /// <summary>
    11647    /// Saves the specified <paramref name="instance"/> in the specified <paramref name="stream"/>
     
    12051    /// <param name="stream">The (file) stream where the object should be saved.</param>
    12152    public static void Save(IStorable instance, Stream stream) {
    122       XmlDocument document = PersistenceManager.CreateXmlDocument();
    123       Dictionary<Guid, IStorable> dictionary = new Dictionary<Guid, IStorable>();
    124       XmlNode rootNode = document.CreateElement("Root");
    125       document.AppendChild(rootNode);
    126       XmlNode necessaryPluginsNode = document.CreateElement("NecessaryPlugins");
    127       rootNode.AppendChild(necessaryPluginsNode);
    128       rootNode.AppendChild(Persist(instance, document, dictionary));
    129       // determine the list of necessary plugins for this document
    130       DiscoveryService service = new DiscoveryService();
    131       List<PluginInfo> plugins = new List<PluginInfo>();
    132       foreach(IStorable storeable in dictionary.Values) {
    133         PluginInfo pluginInfo = service.GetDeclaringPlugin(storeable.GetType());
    134         if(!plugins.Contains(pluginInfo)) plugins.Add(pluginInfo);
    135       }
    136       foreach(PluginInfo uniquePlugin in plugins) {
    137         XmlNode necessaryPluginNode = document.CreateElement("Plugin");
    138         XmlAttribute nameAttr = document.CreateAttribute("Name");
    139         nameAttr.Value = uniquePlugin.Name;
    140         XmlAttribute versionAttr = document.CreateAttribute("Version");
    141         versionAttr.Value = uniquePlugin.Version.ToString();
    142         necessaryPluginNode.Attributes.Append(nameAttr);
    143         necessaryPluginNode.Attributes.Append(versionAttr);
    144         necessaryPluginsNode.AppendChild(necessaryPluginNode);
    145       }
    146       document.Save(stream);
     53      string tempfile = Path.GetTempFileName();
     54      XmlGenerator.Serialize(instance, tempfile);
     55      Stream reader = new FileStream(tempfile, FileMode.Open);
     56      byte[] buffer = new byte[1024];
     57      int bytesRead = 0;
     58      do {
     59        bytesRead = reader.Read(buffer, 0, buffer.Length);
     60        stream.Write(buffer, 0, bytesRead);
     61      } while (bytesRead > 0);
     62      reader.Close();
     63      stream.Close();
     64      File.Delete(tempfile);
    14765    }
    14866    /// <summary>
     
    15472    /// <returns>The loaded object.</returns>
    15573    public static IStorable Load(string filename) {
    156       using(FileStream stream = File.OpenRead(filename)) {
    157         IStorable storable = Load(stream);
    158         stream.Close();
    159         return storable;
    160       }
     74      return (IStorable)XmlParser.DeSerialize(filename);
    16175    }
    16276    /// <summary>
     
    16882    /// <returns>The loaded object.</returns>
    16983    public static IStorable Load(Stream stream) {
    170       XmlDocument doc = new XmlDocument();
    171       doc.Load(stream);
    172       XmlNode rootNode = doc.ChildNodes[1];
    173       if(rootNode.Name == "Root" && rootNode.ChildNodes.Count == 2) {
    174         // load documents that have a list of necessary plugins at the top
    175         return PersistenceManager.Restore(rootNode.ChildNodes[1], new Dictionary<Guid, IStorable>());
    176       } else {
    177         // compatibility to load documents without list of necessary plugins
    178         return PersistenceManager.Restore(rootNode, new Dictionary<Guid, IStorable>());
    179       }
    180     }
    181 
    182     /// <summary>
    183     /// Loads an object from a zip file.
    184     /// </summary>
    185     /// <param name="serializedStorable">The zip file from where to load as byte array.</param>
    186     /// <returns>The loaded object.</returns>
    187     public static IStorable RestoreFromGZip(byte[] serializedStorable) {
    188       GZipStream stream = new GZipStream(new MemoryStream(serializedStorable), CompressionMode.Decompress);
    189       return Load(stream);
    190     }
    191 
    192     /// <summary>
    193     /// Saves the specified <paramref name="storable"/> in a zip file.
    194     /// </summary>
    195     /// <remarks>Calls <see cref="Save(HeuristicLab.Core.IStorable, Stream)"/>.</remarks>
    196     /// <param name="storable">The object to save.</param>
    197     /// <returns>The zip stream as byte array.</returns>
    198     public static byte[] SaveToGZip(IStorable storable) {
    199       MemoryStream memStream = new MemoryStream();
    200       GZipStream stream = new GZipStream(memStream, CompressionMode.Compress, true);
    201       Save(storable, stream);
     84      string tempfile = Path.GetTempFileName();
     85      Stream writer = new FileStream(tempfile, FileMode.CreateNew);
     86      byte[] buffer = new byte[1024];
     87      int bytesRead = 0;
     88      do {
     89        bytesRead = stream.Read(buffer, 0, buffer.Length);
     90        writer.Write(buffer, 0, bytesRead);
     91      } while (bytesRead > 0);
    20292      stream.Close();
    203       return memStream.ToArray();
     93      writer.Close();
     94      object o = XmlParser.DeSerialize(tempfile);
     95      File.Delete(tempfile);
     96      return (IStorable)o;
    20497    }
    20598
     
    219112      builder.Append(type.Name);
    220113      Type[] args = type.GetGenericArguments();
    221       if(args.Length > 0) {
     114      if (args.Length > 0) {
    222115        builder.Append("[[");
    223116        builder.Append(BuildTypeString(args[0]));
    224117        builder.Append("]");
    225         for(int i = 1; i < args.Length; i++) {
     118        for (int i = 1; i < args.Length; i++) {
    226119          builder.Append(",[");
    227120          builder.Append(BuildTypeString(args[i]));
  • trunk/sources/HeuristicLab.Core/3.3/Scope.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public class Scope : ItemBase, IScope {
     33
    3234    private IScope parent;
    3335
    34     private string myName;
     36    [Storable]
     37    private string myName;
    3538    /// <summary>
    3639    /// Gets the name of the current scope.
     
    4043    }
    4144
     45    [Storable]
    4246    private IDictionary<string, IVariable> myVariables;
    4347    /// <inheritdoc/>
     
    4549      get { return myVariables.Values; }
    4650    }
     51
     52    [Storable]
    4753    private IDictionary<string, string> myAliases;
    4854    /// <inheritdoc/>
     
    5056      get { return myAliases; }
    5157    }
     58
     59    [Storable]
    5260    private List<IScope> mySubScopes;
    5361    /// <summary>
     
    238246        RemoveVariable(variableNames[j]);
    239247
    240       KeyValuePair<string, string>[] aliases = new KeyValuePair<string,string>[myAliases.Count];
     248      KeyValuePair<string, string>[] aliases = new KeyValuePair<string, string>[myAliases.Count];
    241249      myAliases.CopyTo(aliases, 0);
    242250      for (int j = 0; j < aliases.Length; j++)
     
    333341        SubScopesReordered(this, new EventArgs());
    334342    }
    335 
    336     #region Persistence Methods
    337     /// <summary>
    338     /// Saves the current instance as <see cref="XmlNode"/> in the given <paramref name="document"/>.
    339     /// </summary>
    340     /// <remarks>
    341     /// Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/>
    342     /// A quick overview how the single elements of the current instance are saved:
    343     /// <list type="bullet">
    344     /// <item>
    345     /// <term>Name: </term>
    346     /// <description>Saved as an <see cref="XmlAttribute"/> having the tag name <c>Name</c>.</description>
    347     /// </item>
    348     /// <item>
    349     /// <term>Variables: </term>
    350     /// <description>A child node is created with the tag name <c>Variables</c>. Beyond this child node,
    351     /// all variables are saved as child nodes.</description>
    352     /// </item>
    353     /// <item>
    354     /// <term>Aliases: </term>
    355     /// <description>A child node is created with the tag name <c>Aliases</c>. Beyond this child node,
    356     /// all aliases are saved as child nodes with the tag name <c>Alias</c>. Each alias has an
    357     /// <see cref="XmlAttribute"/> with the tag name "Alias", holding the alias, and an attribute
    358     /// with the tag name <c>Name</c>, holding the name of the alias.</description>
    359     /// </item>
    360     /// <item>
    361     /// <term>Sub scopes: </term>
    362     /// <description>A child node is created with the tag name <c>SubScopes</c>. Beyond this child node,
    363     /// all sub scopes are saved as child nodes.</description>
    364     /// </item>
    365     /// </list>
    366     /// </remarks>
    367     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    368     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    369     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    370     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    371     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    372       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    373       XmlAttribute nameAttribute = document.CreateAttribute("Name");
    374       nameAttribute.Value = Name.ToString();
    375       node.Attributes.Append(nameAttribute);
    376 
    377       XmlNode variables = document.CreateNode(XmlNodeType.Element, "Variables", null);
    378       foreach (IVariable variable in Variables)
    379         variables.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects));
    380       node.AppendChild(variables);
    381 
    382       XmlNode aliases = document.CreateNode(XmlNodeType.Element, "Aliases", null);
    383       foreach (KeyValuePair<string, string> alias in myAliases) {
    384         XmlNode aliasNode = document.CreateNode(XmlNodeType.Element, "Alias", null);
    385         XmlAttribute keyAttribute = document.CreateAttribute("Alias");
    386         keyAttribute.Value = alias.Key;
    387         aliasNode.Attributes.Append(keyAttribute);
    388         XmlAttribute valueAttribute = document.CreateAttribute("Name");
    389         valueAttribute.Value = alias.Value;
    390         aliasNode.Attributes.Append(valueAttribute);
    391         aliases.AppendChild(aliasNode);
    392       }
    393       node.AppendChild(aliases);
    394 
    395       XmlNode subScopes = document.CreateNode(XmlNodeType.Element, "SubScopes", null);
    396       for (int i = 0; i < SubScopes.Count; i++)
    397         subScopes.AppendChild(PersistenceManager.Persist(SubScopes[i], document, persistedObjects));
    398       node.AppendChild(subScopes);
    399 
    400       return node;
    401     }
    402     /// <summary>
    403     /// Loads the persisted scope from the specified <paramref name="node"/>.
    404     /// </summary>
    405     /// <remarks>See <see cref="GetXmlNode"/> to get further information on how the current instance must
    406     /// be saved. <br/>
    407     /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks>
    408     /// <param name="node">The <see cref="XmlNode"/> where the boolean value is saved.</param>
    409     /// <param name="restoredObjects">The dictionary of all already restored objects.
    410     /// (Needed to avoid cycles.)</param>
    411     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    412       base.Populate(node, restoredObjects);
    413       myName = node.Attributes["Name"].Value;
    414 
    415       XmlNode variables = node.SelectSingleNode("Variables");
    416       foreach (XmlNode variableNode in variables.ChildNodes) {
    417         IVariable variable = (IVariable)PersistenceManager.Restore(variableNode, restoredObjects);
    418         AddVariable(variable);
    419       }
    420 
    421       XmlNode aliases = node.SelectSingleNode("Aliases");
    422       if (aliases != null) {
    423         foreach (XmlNode aliasNode in aliases.ChildNodes)
    424           AddAlias(aliasNode.Attributes["Alias"].Value, aliasNode.Attributes["Name"].Value);
    425       }
    426 
    427       XmlNode subScopes = node.SelectSingleNode("SubScopes");
    428       for (int i = 0; i < subScopes.ChildNodes.Count; i++) {
    429         IScope scope = (IScope)PersistenceManager.Restore(subScopes.ChildNodes[i], restoredObjects);
    430         AddSubScope(scope);
    431       }
    432     }
    433     #endregion
    434343  }
    435344}
  • trunk/sources/HeuristicLab.Core/3.3/StorableBase.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public abstract class StorableBase : IStorable {
     33
     34    [Storable]
    3235    private Guid myGuid;
    3336    /// <summary>
     
    6467      return clone;
    6568    }
    66 
    67     /// <summary>
    68     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    69     /// </summary>
    70     /// <remarks>The type of the current instance is saved as <see cref="XmlAttribute"/> with tag name
    71     /// <c>Type</c>, the guid is also saved as an attribute with the tag name <c>GUID</c>.</remarks>
    72     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    73     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    74     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    75     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    76     public virtual XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    77       XmlNode node = document.CreateNode(XmlNodeType.Element, name, null);
    78       XmlAttribute typeAttribute = document.CreateAttribute("Type");
    79       typeAttribute.Value = PersistenceManager.BuildTypeString(this.GetType());
    80       node.Attributes.Append(typeAttribute);
    81       XmlAttribute guidAttribute = document.CreateAttribute("GUID");
    82       guidAttribute.Value = Guid.ToString();
    83       node.Attributes.Append(guidAttribute);
    84       return node;
    85     }
    86     /// <summary>
    87     /// Loads the persisted object from the specified <paramref name="node"/>.
    88     /// </summary>
    89     /// <remarks>Loads only guid; type,... already loaded by the <see cref="PersistenceManager"/>.</remarks>
    90     /// <param name="node">The <see cref="XmlNode"/> where the object is saved.</param>
    91     /// <param name="restoredObjects">The dictionary of all already restored objects.
    92     /// (Needed to avoid cycles.)</param>
    93     public virtual void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    94       myGuid = new Guid(node.Attributes["GUID"].Value);
    95     }
    9669  }
    9770}
  • trunk/sources/HeuristicLab.Core/3.3/Variable.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public class Variable : ItemBase, IVariable {
     33
     34    [Storable]
    3235    private string myName;
    3336    /// <inheritdoc/>
     
    4750      }
    4851    }
     52
     53    [Storable]
    4954    private IItem myValue;
    5055    /// <inheritdoc/>
     
    5964      }
    6065    }
    61    
     66
    6267    /// <summary>
    6368    /// Initializes a new instance of <see cref="Variable"/> with name <c>Anonymous</c>
     
    145150      OnChanged();
    146151    }
    147 
    148     #region Persistence Methods
    149     /// <summary>
    150     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    151     /// </summary>
    152     /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/>
    153     /// The name of the current instance is saved as an <see cref="XmlAttribute"/> with the
    154     /// tag name <c>Name</c>, the value is saved as child node with the tag name <c>Value</c>.</remarks>
    155     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    156     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    157     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    158     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    159     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    160       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    161       XmlAttribute nameAttribute = document.CreateAttribute("Name");
    162       nameAttribute.Value = Name;
    163       node.Attributes.Append(nameAttribute);
    164       if (Value != null)
    165         node.AppendChild(PersistenceManager.Persist("Value", Value, document, persistedObjects));
    166       return node;
    167     }
    168     /// <summary>
    169     /// Loads the persisted variable from the specified <paramref name="node"/>.
    170     /// </summary>
    171     /// <remarks>See <see cref="GetXmlNode"/> to get information on how the variable must be saved.<br/>
    172     /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks>
    173     /// <param name="node">The <see cref="XmlNode"/> where the variable is saved.</param>
    174     /// <param name="restoredObjects">The dictionary of all already restored objects.
    175     /// (Needed to avoid cycles.)</param>
    176     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    177       base.Populate(node, restoredObjects);
    178       myName = node.Attributes["Name"].Value;
    179       XmlNode valueNode = node.SelectSingleNode("Value");
    180       if (valueNode != null)
    181         myValue = (IItem)PersistenceManager.Restore(valueNode, restoredObjects);
    182     }
    183     #endregion
    184152  }
    185153}
  • trunk/sources/HeuristicLab.Core/3.3/VariableInfo.cs

    r1529 r1667  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2627
    2728namespace HeuristicLab.Core {
     
    3031  /// </summary>
    3132  public class VariableInfo : ItemBase, IVariableInfo {
     33
     34    [Storable]
    3235    private string myActualName;
    3336    /// <summary>
     
    4447      }
    4548    }
     49
     50    [Storable]
    4651    private string myFormalName;
    4752    /// <summary>
     
    5156      get { return myFormalName; }
    5257    }
     58
     59    [Storable]
    5360    private string myDescription;
    5461    /// <summary>
     
    5865      get { return myDescription; }
    5966    }
     67
     68    [Storable]
    6069    private Type myDataType;
    6170    /// <summary>
     
    6574      get { return myDataType; }
    6675    }
     76
     77    [Storable]
    6778    private VariableKind myKind;
    6879    /// <summary>
     
    7283      get { return myKind; }
    7384    }
     85
     86    [Storable]
    7487    private bool myLocal;
    7588    /// <summary>
     
    162175        LocalChanged(this, new EventArgs());
    163176    }
    164 
    165     #region Persistence Methods
    166     /// <summary>
    167     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    168     /// </summary>
    169     /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>. <br/>
    170     /// A quick overview how the single elements of the current instance are saved:
    171     /// <list type="bullet">
    172     /// <item>
    173     /// <term>Actual name: </term>
    174     /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>ActualName</c>.</description>
    175     /// </item>
    176     /// <item>
    177     /// <term>Formal name: </term>
    178     /// <description>Saves as <see cref="XmlAttribute"/> with tag name <c>FormalName</c>.</description>
    179     /// </item>
    180     /// <item>
    181     /// <term>Description: </term>
    182     /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Description</c>.</description>
    183     /// </item>
    184     /// <item><term>Data type: </term>
    185     /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>DataType</c>.</description>
    186     /// </item>
    187     /// <item>
    188     /// <term>Kind: </term>
    189     /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Kind</c>.</description>
    190     /// </item>
    191     /// <item>
    192     /// <term>Local: </term>
    193     /// <description>Saved as <see cref="XmlAttribute"/> with tag name <c>Local</c>.</description>
    194     /// </item>
    195     /// </list></remarks>
    196     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    197     /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
    198     /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
    199     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    200     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    201       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    202       XmlAttribute actualNameAttribute = document.CreateAttribute("ActualName");
    203       actualNameAttribute.Value = ActualName;
    204       node.Attributes.Append(actualNameAttribute);
    205 
    206       XmlAttribute formalNameAttribute = document.CreateAttribute("FormalName");
    207       formalNameAttribute.Value = FormalName;
    208       node.Attributes.Append(formalNameAttribute);
    209 
    210       XmlAttribute descriptionAttribute = document.CreateAttribute("Description");
    211       descriptionAttribute.Value = Description;
    212       node.Attributes.Append(descriptionAttribute);
    213 
    214       XmlAttribute dataTypeAttribute = document.CreateAttribute("DataType");
    215       dataTypeAttribute.Value = PersistenceManager.BuildTypeString(DataType);
    216       node.Attributes.Append(dataTypeAttribute);
    217 
    218       XmlAttribute kindAttribute = document.CreateAttribute("Kind");
    219       kindAttribute.Value = Kind.ToString();
    220       node.Attributes.Append(kindAttribute);
    221 
    222       XmlAttribute localAttribute = document.CreateAttribute("Local");
    223       localAttribute.Value = Local.ToString();
    224       node.Attributes.Append(localAttribute);
    225 
    226       return node;
    227     }
    228     /// <summary>
    229     /// Loads the persisted variable info from the specified <paramref name="node"/>.
    230     /// </summary>
    231     /// <remarks>See <see cref="GetXmlNode"/> for further information on how the variable info must be
    232     /// saved. <br/>
    233     /// Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.</remarks>
    234     /// <param name="node">The <see cref="XmlNode"/> where the variable info is saved.</param>
    235     /// <param name="restoredObjects">The dictionary of all already restored objects.
    236     /// (Needed to avoid cycles.)</param>
    237     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    238       base.Populate(node, restoredObjects);
    239       myActualName = node.Attributes["ActualName"].Value;
    240       myFormalName = node.Attributes["FormalName"].Value;
    241       myDescription = node.Attributes["Description"].Value;
    242       myDataType = Type.GetType(node.Attributes["DataType"].Value, true);
    243       myKind = (VariableKind)Enum.Parse(typeof(VariableKind), node.Attributes["Kind"].Value);
    244       myLocal = bool.Parse(node.Attributes["Local"].Value);
    245     }
    246     #endregion
    247177  }
    248178}
Note: See TracChangeset for help on using the changeset viewer.