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