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