Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/27/09 14:18:39 (15 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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.