Changeset 1667
- Timestamp:
- 04/27/09 14:18:39 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Core/3.3
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Core/3.3/AtomicOperation.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public class AtomicOperation : ItemBase, IOperation { 33 34 [Storable] 32 35 private IOperator myOperator; 33 36 /// <summary> … … 37 40 get { return myOperator; } 38 41 } 39 private IScope myScope; 42 43 [Storable] 44 private IScope myScope; 40 45 /// <summary> 41 46 /// Gets the current scope as <see cref="IScope"/>. … … 74 79 return clone; 75 80 } 76 77 #region Persistence Methods78 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 base83 /// 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 class100 /// <see cref="ItemBase"/>.<br/>101 /// The operator must be saved as a child node with the tag name <c>Operator</c>, also the scope must102 /// 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 #endregion111 81 } 112 82 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/CompositeOperation.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 31 32 /// </summary> 32 33 public class CompositeOperation : ItemBase, IOperation { 34 35 [Storable] 33 36 private bool myExecuteInParallel; 34 35 37 /// <summary> 36 38 /// Gets or sets the bool value, whether the operation should be executed in parallel or not. … … 40 42 set { myExecuteInParallel = value; } 41 43 } 44 45 [Storable] 42 46 private List<IOperation> myOperations; 43 47 /// <summary> … … 88 92 return clone; 89 93 } 90 91 #region Persistence Methods92 /// <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 base96 /// class <see cref="ItemBase"/>.<br/>97 /// The <see cref="ExecuteInParallel"/> property is saved as <see cref="XmlAttribute"/> with the98 /// tag name <c>ExecuteInParallel</c>. A child node with tag name <c>Operations</c> is created where99 /// 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 #endregion136 94 } 137 95 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/ConstrainedItemBase.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public abstract class ConstrainedItemBase : ItemBase, IConstrainedItem { 33 34 [Storable] 32 35 private List<IConstraint> myConstraints; 33 36 /// <summary> … … 144 147 ConstraintRemoved(this, new ConstraintEventArgs(constraint)); 145 148 } 146 147 #region Persistence Methods148 /// <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 this153 /// 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 must173 /// 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 #endregion188 149 } 189 150 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/EngineBase.cs ¶
r1529 r1667 25 25 using System.Xml; 26 26 using System.Threading; 27 using HeuristicLab.Persistence.Default.Decomposers.Storable; 27 28 28 29 namespace HeuristicLab.Core { … … 33 34 /// </summary> 34 35 public abstract class EngineBase : ItemBase, IEngine { 36 35 37 /// <summary> 36 38 /// Field of the current instance that represent the operator graph. 37 39 /// </summary> 40 [Storable] 38 41 protected IOperatorGraph myOperatorGraph; 39 42 /// <summary> … … 46 49 /// Field of the current instance that represent the global scope. 47 50 /// </summary> 51 [Storable] 48 52 protected IScope myGlobalScope; 49 53 /// <summary> … … 54 58 } 55 59 60 [Storable] 56 61 private TimeSpan myExecutionTime; 57 62 /// <summary> … … 70 75 /// Field of the current instance that represent the execution stack. 71 76 /// </summary> 77 [Storable] 72 78 protected Stack<IOperation> myExecutionStack; 73 79 /// <summary> … … 77 83 get { return myExecutionStack; } 78 84 } 79 85 80 86 /// <summary> 81 87 /// Flag of the current instance whether it is currently running. … … 136 142 clone.myCanceled = Canceled; 137 143 return clone; 138 139 144 } 140 145 … … 276 281 Finished(this, new EventArgs()); 277 282 } 278 279 #region Persistence Methods280 /// <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 node297 /// 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 execution302 /// 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 #endregion348 283 } 349 284 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj ¶
r1663 r1667 32 32 <UseApplicationTrust>false</UseApplicationTrust> 33 33 <BootstrapperEnabled>true</BootstrapperEnabled> 34 <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> 34 35 </PropertyGroup> 35 36 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> … … 90 91 <ItemGroup> 91 92 <Reference Include="System" /> 93 <Reference Include="System.Core"> 94 <RequiredTargetFramework>3.5</RequiredTargetFramework> 95 </Reference> 92 96 <Reference Include="System.Data" /> 93 97 <Reference Include="System.Drawing" /> … … 268 272 </ItemGroup> 269 273 <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> 270 278 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj"> 271 279 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/HeuristicLabCorePlugin.cs ¶
r1529 r1667 30 30 /// Plugin class for HeuristicLab.Core plugin. 31 31 /// </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")] 34 35 public class HeuristicLabCorePlugin : PluginBase { 35 36 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/Interfaces/IStorable.cs ¶
r776 r1667 26 26 27 27 namespace HeuristicLab.Core { 28 28 29 /// <summary> 29 30 /// Interface to represent objects that are de- and serializeable. 30 31 /// </summary> 31 32 public interface IStorable { 33 32 34 /// <summary> 33 35 /// Gets the objects unique identifier. … … 40 42 /// <returns>The cloned object.</returns> 41 43 object Clone(); 44 42 45 /// <summary> 43 46 /// Clones the current instance, considering already cloned objects. … … 46 49 /// <returns>The cloned object.</returns> 47 50 object Clone(IDictionary<Guid, object> clonedObjects); 48 49 /// <summary>50 /// Saves the current instance as <see cref="XmlNode"/> in the specified51 /// <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 avoid64 /// cycles.)</param>65 void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects);66 51 } 67 52 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/OperatorBase.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public abstract class OperatorBase : ConstrainedItemBase, IOperator { 33 34 [Storable] 32 35 private string myName; 33 36 /// <summary> … … 59 62 get { return myCanceled; } 60 63 } 64 65 [Storable] 61 66 private bool myBreakpoint; 62 67 /// <inheritdoc/> … … 72 77 } 73 78 79 [Storable] 74 80 private List<IOperator> mySubOperators; 75 81 /// <summary> … … 80 86 get { return mySubOperators.AsReadOnly(); } 81 87 } 88 89 [Storable] 82 90 private Dictionary<string, IVariableInfo> myVariableInfos; 83 91 /// <inheritdoc/> … … 85 93 get { return myVariableInfos.Values; } 86 94 } 95 96 [Storable] 87 97 private Dictionary<string, IVariable> myVariables; 88 98 /// <inheritdoc/> … … 589 599 } 590 600 } 591 592 #region Persistence Methods593 /// <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 themselves612 /// 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 themselves617 /// 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 themselves622 /// 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 class658 /// <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 #endregion680 601 } 681 602 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/OperatorGraph.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public class OperatorGraph : ItemBase, IOperatorGraph { 33 34 [Storable] 32 35 private IDictionary<Guid, IOperator> myOperators; 33 36 /// <summary> … … 37 40 get { return myOperators.Values; } 38 41 } 42 43 [Storable] 39 44 private IOperator myInitialOperator; 40 45 /// <summary> … … 165 170 InitialOperatorChanged(this, new EventArgs()); 166 171 } 167 168 #region Persistence Methods169 /// <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 name174 /// <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 #endregion214 172 } 215 173 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/OperatorGroup.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public class OperatorGroup : StorableBase, IOperatorGroup { 33 34 [Storable] 32 35 private string myName; 33 36 /// <summary> … … 44 47 } 45 48 } 49 50 [Storable] 46 51 private List<IOperatorGroup> mySubGroups; 47 52 /// <summary> … … 52 57 get { return mySubGroups.AsReadOnly(); } 53 58 } 59 60 [Storable] 54 61 private List<IOperator> myOperators; 55 62 /// <summary> … … 128 135 } 129 136 } 130 131 #region Persistence Methods132 /// <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 node145 /// 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 node150 /// 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 #endregion192 137 } 193 138 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/OperatorLibrary.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public class OperatorLibrary : ItemBase, IOperatorLibrary, IEditable { 33 34 [Storable] 32 35 private IOperatorGroup myGroup; 33 36 /// <summary> … … 73 76 return clone; 74 77 } 75 76 #region Persistence Methods77 /// <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 #endregion105 78 } 106 79 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/PersistenceManager.cs ¶
r1529 r1667 27 27 using System.IO.Compression; 28 28 using HeuristicLab.PluginInfrastructure; 29 using HeuristicLab.Persistence.Default.Xml; 29 30 30 31 namespace HeuristicLab.Core { … … 34 35 public static class PersistenceManager { 35 36 /// <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 the85 /// 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>104 37 /// Saves the specified <paramref name="instance"/> in the specified file through creating an 105 38 /// <see cref="XmlDocument"/>. … … 108 41 /// <param name="filename">The name of the file where the <paramref name="object"/> should be saved.</param> 109 42 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); 114 44 } 45 115 46 /// <summary> 116 47 /// Saves the specified <paramref name="instance"/> in the specified <paramref name="stream"/> … … 120 51 /// <param name="stream">The (file) stream where the object should be saved.</param> 121 52 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); 147 65 } 148 66 /// <summary> … … 154 72 /// <returns>The loaded object.</returns> 155 73 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); 161 75 } 162 76 /// <summary> … … 168 82 /// <returns>The loaded object.</returns> 169 83 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); 202 92 stream.Close(); 203 return memStream.ToArray(); 93 writer.Close(); 94 object o = XmlParser.DeSerialize(tempfile); 95 File.Delete(tempfile); 96 return (IStorable)o; 204 97 } 205 98 … … 219 112 builder.Append(type.Name); 220 113 Type[] args = type.GetGenericArguments(); 221 if (args.Length > 0) {114 if (args.Length > 0) { 222 115 builder.Append("[["); 223 116 builder.Append(BuildTypeString(args[0])); 224 117 builder.Append("]"); 225 for (int i = 1; i < args.Length; i++) {118 for (int i = 1; i < args.Length; i++) { 226 119 builder.Append(",["); 227 120 builder.Append(BuildTypeString(args[i])); -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/Scope.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public class Scope : ItemBase, IScope { 33 32 34 private IScope parent; 33 35 34 private string myName; 36 [Storable] 37 private string myName; 35 38 /// <summary> 36 39 /// Gets the name of the current scope. … … 40 43 } 41 44 45 [Storable] 42 46 private IDictionary<string, IVariable> myVariables; 43 47 /// <inheritdoc/> … … 45 49 get { return myVariables.Values; } 46 50 } 51 52 [Storable] 47 53 private IDictionary<string, string> myAliases; 48 54 /// <inheritdoc/> … … 50 56 get { return myAliases; } 51 57 } 58 59 [Storable] 52 60 private List<IScope> mySubScopes; 53 61 /// <summary> … … 238 246 RemoveVariable(variableNames[j]); 239 247 240 KeyValuePair<string, string>[] aliases = new KeyValuePair<string, string>[myAliases.Count];248 KeyValuePair<string, string>[] aliases = new KeyValuePair<string, string>[myAliases.Count]; 241 249 myAliases.CopyTo(aliases, 0); 242 250 for (int j = 0; j < aliases.Length; j++) … … 333 341 SubScopesReordered(this, new EventArgs()); 334 342 } 335 336 #region Persistence Methods337 /// <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 an357 /// <see cref="XmlAttribute"/> with the tag name "Alias", holding the alias, and an attribute358 /// 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 must406 /// 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 #endregion434 343 } 435 344 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/StorableBase.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public abstract class StorableBase : IStorable { 33 34 [Storable] 32 35 private Guid myGuid; 33 36 /// <summary> … … 64 67 return clone; 65 68 } 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 name71 /// <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 }96 69 } 97 70 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/Variable.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public class Variable : ItemBase, IVariable { 33 34 [Storable] 32 35 private string myName; 33 36 /// <inheritdoc/> … … 47 50 } 48 51 } 52 53 [Storable] 49 54 private IItem myValue; 50 55 /// <inheritdoc/> … … 59 64 } 60 65 } 61 66 62 67 /// <summary> 63 68 /// Initializes a new instance of <see cref="Variable"/> with name <c>Anonymous</c> … … 145 150 OnChanged(); 146 151 } 147 148 #region Persistence Methods149 /// <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 the154 /// 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 #endregion184 152 } 185 153 } -
TabularUnified trunk/sources/HeuristicLab.Core/3.3/VariableInfo.cs ¶
r1529 r1667 24 24 using System.Text; 25 25 using System.Xml; 26 using HeuristicLab.Persistence.Default.Decomposers.Storable; 26 27 27 28 namespace HeuristicLab.Core { … … 30 31 /// </summary> 31 32 public class VariableInfo : ItemBase, IVariableInfo { 33 34 [Storable] 32 35 private string myActualName; 33 36 /// <summary> … … 44 47 } 45 48 } 49 50 [Storable] 46 51 private string myFormalName; 47 52 /// <summary> … … 51 56 get { return myFormalName; } 52 57 } 58 59 [Storable] 53 60 private string myDescription; 54 61 /// <summary> … … 58 65 get { return myDescription; } 59 66 } 67 68 [Storable] 60 69 private Type myDataType; 61 70 /// <summary> … … 65 74 get { return myDataType; } 66 75 } 76 77 [Storable] 67 78 private VariableKind myKind; 68 79 /// <summary> … … 72 83 get { return myKind; } 73 84 } 85 86 [Storable] 74 87 private bool myLocal; 75 88 /// <summary> … … 162 175 LocalChanged(this, new EventArgs()); 163 176 } 164 165 #region Persistence Methods166 /// <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 be232 /// 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 #endregion247 177 } 248 178 }
Note: See TracChangeset
for help on using the changeset viewer.