[2768] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
[4068] | 3 | using System.Diagnostics;
|
---|
[2768] | 4 | using System.Runtime.Serialization;
|
---|
[4068] | 5 | using System.Xml.Schema;
|
---|
[2768] | 6 | using System.Xml.Serialization;
|
---|
[4068] | 7 | namespace Netron.Diagramming.Core {
|
---|
| 8 | /// <summary>
|
---|
| 9 | /// Complementary partial class related to (de)serialization.
|
---|
| 10 | /// </summary>
|
---|
| 11 | [Serializable]
|
---|
| 12 | public partial class Model : ISerializable, IXmlSerializable, IDeserializationCallback {
|
---|
| 13 | #region Deserialization constructor
|
---|
[2768] | 14 | /// <summary>
|
---|
[4068] | 15 | /// Deserialization constructor
|
---|
[2768] | 16 | /// </summary>
|
---|
[4068] | 17 | /// <param name="info">The info.</param>
|
---|
| 18 | /// <param name="context">The context.</param>
|
---|
| 19 | protected Model(SerializationInfo info, StreamingContext context) {
|
---|
| 20 | if (Tracing.BinaryDeserializationSwitch.Enabled) {
|
---|
| 21 | Trace.WriteLine("Deserializing the fields of 'Model'.");
|
---|
| 22 | }
|
---|
[2768] | 23 |
|
---|
[4068] | 24 | double version = info.GetDouble("ModelVersion");
|
---|
[2768] | 25 |
|
---|
[4068] | 26 | mPages = info.GetValue(
|
---|
| 27 | "Pages",
|
---|
| 28 | typeof(CollectionBase<IPage>)) as CollectionBase<IPage>;
|
---|
[2768] | 29 |
|
---|
[4068] | 30 | //Init();
|
---|
| 31 | }
|
---|
| 32 | #endregion
|
---|
[2768] | 33 |
|
---|
[4068] | 34 | #region Serialization events
|
---|
| 35 | /*
|
---|
[2768] | 36 | [OnSerializing]
|
---|
| 37 | void OnSerializing(StreamingContext context)
|
---|
| 38 | {
|
---|
| 39 | Trace.Indent();
|
---|
| 40 | Trace.WriteLine("Starting to serializing the 'Model' class...");
|
---|
| 41 | }
|
---|
| 42 | [OnSerialized]
|
---|
| 43 | void OnSerialized(StreamingContext context)
|
---|
| 44 | {
|
---|
| 45 |
|
---|
| 46 | Trace.WriteLine("...serialization of 'Model' finished");
|
---|
| 47 | Trace.Unindent();
|
---|
| 48 | }
|
---|
| 49 | */
|
---|
[4068] | 50 | #endregion
|
---|
[2768] | 51 |
|
---|
[4068] | 52 | #region Deserialization events
|
---|
[2768] | 53 |
|
---|
[4068] | 54 | [OnDeserializing]
|
---|
| 55 | void OnDeserializing(StreamingContext context) {
|
---|
| 56 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
| 57 | Trace.WriteLine("Starting deserializing the 'Model' class...");
|
---|
| 58 | //the anchors is a temporary collection of Uid's and parent entities to re-connect connectors
|
---|
| 59 | //to their parent. The serialization process does serialize parenting because you need on deserialization an
|
---|
| 60 | //instance in order to connect to it.
|
---|
[2768] | 61 |
|
---|
[4068] | 62 | Anchors.Clear();
|
---|
| 63 | }
|
---|
[2768] | 64 |
|
---|
[4068] | 65 | [OnDeserialized]
|
---|
| 66 | void OnDeserialized(StreamingContext context) {
|
---|
| 67 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
| 68 | Trace.WriteLine("...deserialization of 'Model' finished");
|
---|
| 69 | }
|
---|
[2768] | 70 |
|
---|
[4068] | 71 | #endregion
|
---|
[2768] | 72 |
|
---|
[4068] | 73 | #region Serialization
|
---|
| 74 | /// <summary>
|
---|
| 75 | /// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> with the data needed to serialize the target object.
|
---|
| 76 | /// </summary>
|
---|
| 77 | /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> to populate with data.</param>
|
---|
| 78 | /// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"></see>) for this serialization.</param>
|
---|
| 79 | /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
|
---|
| 80 | public void GetObjectData(SerializationInfo info, StreamingContext context) {
|
---|
| 81 | if (Tracing.BinarySerializationSwitch.Enabled)
|
---|
| 82 | Trace.WriteLine("Serializing the fields of 'Model'.");
|
---|
[2768] | 83 |
|
---|
[4068] | 84 | info.AddValue("ModelVersion", modelVersion);
|
---|
[2768] | 85 |
|
---|
[4068] | 86 | info.AddValue("Pages", this.Pages, typeof(CollectionBase<IPage>));
|
---|
| 87 | }
|
---|
| 88 | #endregion
|
---|
[2768] | 89 |
|
---|
[4068] | 90 | #region Xml serialization
|
---|
| 91 | /// <summary>
|
---|
| 92 | /// This property is reserved, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"></see> to the class instead.
|
---|
| 93 | /// </summary>
|
---|
| 94 | /// <returns>
|
---|
| 95 | /// An <see cref="T:System.Xml.Schema.XmlSchema"></see> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)"></see> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)"></see> method.
|
---|
| 96 | /// </returns>
|
---|
| 97 | public XmlSchema GetSchema() {
|
---|
| 98 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
| 99 | }
|
---|
[2768] | 100 |
|
---|
[4068] | 101 | /// <summary>
|
---|
| 102 | /// Generates an object from its XML representation.
|
---|
| 103 | /// </summary>
|
---|
| 104 | /// <param name="reader">The <see cref="T:System.Xml.XmlReader"></see> stream from which the object is deserialized.</param>
|
---|
| 105 | public void ReadXml(System.Xml.XmlReader reader) {
|
---|
| 106 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
| 107 | }
|
---|
[2768] | 108 |
|
---|
[4068] | 109 | /// <summary>
|
---|
| 110 | /// Converts an object into its XML representation.
|
---|
| 111 | /// </summary>
|
---|
| 112 | /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"></see> stream to which the object is serialized.</param>
|
---|
| 113 | public void WriteXml(System.Xml.XmlWriter writer) {
|
---|
| 114 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
| 115 | }
|
---|
| 116 | #endregion
|
---|
| 117 |
|
---|
| 118 | #region IDeserializationCallback Members
|
---|
| 119 |
|
---|
| 120 | /// <summary>
|
---|
| 121 | /// Runs when the entire object graph has been deserialized.
|
---|
| 122 | /// </summary>
|
---|
| 123 | /// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param>
|
---|
| 124 | public void OnDeserialization(object sender) {
|
---|
| 125 |
|
---|
| 126 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
| 127 | Trace.WriteLine("IDeserializationCallback of 'Model' called.");
|
---|
| 128 | Init();
|
---|
| 129 | #region Binding of connectors
|
---|
| 130 |
|
---|
| 131 | Dictionary<Guid, Anchor>.Enumerator enumer = Anchors.GetEnumerator();
|
---|
| 132 | System.Collections.Generic.KeyValuePair<Guid, Anchor> pair;
|
---|
| 133 | Anchor anchor;
|
---|
| 134 | while (enumer.MoveNext()) {
|
---|
| 135 | pair = enumer.Current;
|
---|
| 136 | anchor = pair.Value;
|
---|
| 137 | if (anchor.Parent != Guid.Empty) //there's a parent connector
|
---|
[2768] | 138 | {
|
---|
[4068] | 139 | if (Anchors.ContainsKey(anchor.Parent)) {
|
---|
| 140 | Anchors.GetAnchor(anchor.Parent).Instance.AttachConnector(anchor.Instance);
|
---|
| 141 | }
|
---|
[2768] | 142 | }
|
---|
[4068] | 143 | }
|
---|
| 144 | //clean up the anchoring matrix
|
---|
| 145 | Anchors.Clear();
|
---|
| 146 | #endregion
|
---|
| 147 | }
|
---|
[2768] | 148 |
|
---|
[4068] | 149 | #endregion
|
---|
| 150 | }
|
---|
[2768] | 151 | }
|
---|