Changeset 776 for trunk/sources/HeuristicLab.Core/PersistenceManager.cs
- Timestamp:
- 11/19/08 12:12:39 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/PersistenceManager.cs
r750 r776 29 29 30 30 namespace HeuristicLab.Core { 31 /// <summary> 32 /// Static class for serializing and deserializing objects. 33 /// </summary> 31 34 public static class PersistenceManager { 35 /// <summary> 36 /// Creates an <see cref="XmlDocument"/> to persist an object with xml declaration. 37 /// </summary> 38 /// <returns>The created <see cref="XmlDocument"/>.</returns> 32 39 public static XmlDocument CreateXmlDocument() { 33 40 XmlDocument document = new XmlDocument(); … … 35 42 return document; 36 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> 37 54 public static XmlNode Persist(IStorable instance, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 38 55 string name = instance.GetType().Name; … … 40 57 return Persist(name, instance, document, persistedObjects); 41 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> 42 68 public static XmlNode Persist(string name, IStorable instance, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 43 69 if(persistedObjects.ContainsKey(instance.Guid)) { … … 53 79 } 54 80 } 55 public static IStorable Restore(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 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) { 56 92 Guid guid = new Guid(node.Attributes["GUID"].Value); 57 93 if(restoredObjects.ContainsKey(guid)) { … … 65 101 } 66 102 } 103 /// <summary> 104 /// Saves the specified <paramref name="instance"/> in the specified file through creating an 105 /// <see cref="XmlDocument"/>. 106 /// </summary> 107 /// <param name="instance">The object that should be saved.</param> 108 /// <param name="filename">The name of the file where the <paramref name="object"/> should be saved.</param> 67 109 public static void Save(IStorable instance, string filename) { 68 110 using(FileStream stream = File.Create(filename)) { … … 71 113 } 72 114 } 115 /// <summary> 116 /// Saves the specified <paramref name="instance"/> in the specified <paramref name="stream"/> 117 /// through creating an <see cref="XmlDocument"/>. 118 /// </summary> 119 /// <param name="instance">The object that should be saved.</param> 120 /// <param name="stream">The (file) stream where the object should be saved.</param> 73 121 public static void Save(IStorable instance, Stream stream) { 74 122 XmlDocument document = PersistenceManager.CreateXmlDocument(); … … 98 146 document.Save(stream); 99 147 } 148 /// <summary> 149 /// Loads an object from a file with the specified <paramref name="filename"/>. 150 /// </summary> 151 /// <remarks>The object must be saved as an <see cref="XmlDocument"/>. <br/> 152 /// Calls <see cref="Restore"/>.</remarks> 153 /// <param name="filename">The filename of the file where the data is saved.</param> 154 /// <returns>The loaded object.</returns> 100 155 public static IStorable Load(string filename) { 101 156 using(FileStream stream = File.OpenRead(filename)) { … … 105 160 } 106 161 } 162 /// <summary> 163 /// Loads an object from the specified <paramref name="stream"/>. 164 /// </summary> 165 /// <remarks>The object must be saved as an <see cref="XmlDocument"/>. <br/> 166 /// Calls <see cref="Restore"/>.</remarks> 167 /// <param name="stream">The stream from where to load the data.</param> 168 /// <returns>The loaded object.</returns> 107 169 public static IStorable Load(Stream stream) { 108 170 XmlDocument doc = new XmlDocument(); … … 118 180 } 119 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> 120 187 public static IStorable RestoreFromGZip(byte[] serializedStorable) { 121 188 GZipStream stream = new GZipStream(new MemoryStream(serializedStorable), CompressionMode.Decompress); … … 123 190 } 124 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> 125 198 public static byte[] SaveToGZip(IStorable storable) { 126 199 MemoryStream memStream = new MemoryStream(); … … 131 204 } 132 205 206 /// <summary> 207 /// Builds a meaningful string for the given <paramref name="type"/> with the namespace information, 208 /// all its arguments, the assembly name... 209 /// </summary> 210 /// <param name="type">The type for which a string should be created.</param> 211 /// <returns>A string value of this type containing different additional information.</returns> 133 212 public static string BuildTypeString(Type type) { 134 213 string assembly = type.Assembly.FullName;
Note: See TracChangeset
for help on using the changeset viewer.