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 abstract partial class ShapeBase :
|
---|
17 | ISerializable,
|
---|
18 | IXmlSerializable,
|
---|
19 | IDeserializationCallback
|
---|
20 | {
|
---|
21 | #region Deserialization constructor
|
---|
22 |
|
---|
23 | // -------------------------------------------------------------------
|
---|
24 | /// <summary>
|
---|
25 | /// Deserialization constructor
|
---|
26 | /// </summary>
|
---|
27 | /// <param name="info">The info.</param>
|
---|
28 | /// <param name="context">The context.</param>
|
---|
29 | // -------------------------------------------------------------------
|
---|
30 | protected ShapeBase(
|
---|
31 | SerializationInfo info,
|
---|
32 | StreamingContext context)
|
---|
33 | : base(info, context)
|
---|
34 | {
|
---|
35 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
36 | {
|
---|
37 | Trace.WriteLine("Deserializing the fields of 'ShapeBase'.");
|
---|
38 | }
|
---|
39 |
|
---|
40 | double version = info.GetDouble("ShapeBaseVersion");
|
---|
41 |
|
---|
42 | mConnectors = new CollectionBase<IConnector>();
|
---|
43 |
|
---|
44 | //transform to the new bounding rectangle
|
---|
45 | Transform(
|
---|
46 | (Rectangle)info.GetValue("Rectangle", typeof(Rectangle))
|
---|
47 | );
|
---|
48 |
|
---|
49 | this.mConnectors = info.GetValue(
|
---|
50 | "Connectors",
|
---|
51 | typeof(CollectionBase<IConnector>)) as
|
---|
52 | CollectionBase<IConnector>;
|
---|
53 |
|
---|
54 | mShowConnectors = info.GetBoolean("ShowConnectors");
|
---|
55 | mIsFixed = info.GetBoolean("IsFixed");
|
---|
56 | }
|
---|
57 |
|
---|
58 | #endregion
|
---|
59 |
|
---|
60 | #region Serialization events
|
---|
61 | /*
|
---|
62 | [OnSerializing]
|
---|
63 | void OnSerializing(StreamingContext context)
|
---|
64 | {
|
---|
65 | Trace.WriteLine("Starting to serializing the 'ShapeBase' class...");
|
---|
66 | }
|
---|
67 | [OnSerialized]
|
---|
68 | void OnSerialized(StreamingContext context)
|
---|
69 | {
|
---|
70 | Trace.WriteLine("...serialization of 'ShapeBase' finished");
|
---|
71 | }
|
---|
72 | */
|
---|
73 | #endregion
|
---|
74 |
|
---|
75 | #region Deserialization events
|
---|
76 | /*
|
---|
77 | [OnDeserializing]
|
---|
78 | void OnDeserializing(StreamingContext context)
|
---|
79 | {
|
---|
80 | Trace.Indent();
|
---|
81 | Trace.WriteLine("Starting deserializing the 'ShapeBase' class...");
|
---|
82 | }
|
---|
83 | [OnDeserialized]
|
---|
84 | void OnDeserialized(StreamingContext context)
|
---|
85 | {
|
---|
86 | Trace.WriteLine("...deserialization of 'ShapeBase' finished");
|
---|
87 | Trace.Unindent();
|
---|
88 | }
|
---|
89 | */
|
---|
90 | #endregion
|
---|
91 |
|
---|
92 | #region Serialization
|
---|
93 |
|
---|
94 | // -------------------------------------------------------------------
|
---|
95 | /// <summary>
|
---|
96 | /// Populates a <see cref="
|
---|
97 | /// T:System.Runtime.Serialization.SerializationInfo"></see> with
|
---|
98 | /// the data needed to serialize the target object.
|
---|
99 | /// </summary>
|
---|
100 | /// <param name="info">The
|
---|
101 | /// <see
|
---|
102 | /// cref="T:System.Runtime.Serialization.SerializationInfo">
|
---|
103 | /// </see> to populate with data.</param>
|
---|
104 | /// <param name="context">The destination (see <see cref="
|
---|
105 | /// T:System.Runtime.Serialization.StreamingContext"></see>)
|
---|
106 | /// for this serialization.</param>
|
---|
107 | /// <exception cref="T:System.Security.SecurityException">The
|
---|
108 | /// caller does not have the required permission. </exception>
|
---|
109 | // -------------------------------------------------------------------
|
---|
110 | public override void GetObjectData(
|
---|
111 | SerializationInfo info,
|
---|
112 | StreamingContext context)
|
---|
113 | {
|
---|
114 | if (Tracing.BinarySerializationSwitch.Enabled)
|
---|
115 | {
|
---|
116 | Trace.WriteLine("Serializing the fields of 'ShapeBase'.");
|
---|
117 | }
|
---|
118 |
|
---|
119 | base.GetObjectData(info, context);
|
---|
120 |
|
---|
121 | info.AddValue(
|
---|
122 | "ShapeBaseVersion",
|
---|
123 | shapeBaseVersion);
|
---|
124 |
|
---|
125 | info.AddValue(
|
---|
126 | "Rectangle",
|
---|
127 | this.Rectangle,
|
---|
128 | typeof(Rectangle));
|
---|
129 |
|
---|
130 | info.AddValue(
|
---|
131 | "Connectors",
|
---|
132 | this.Connectors,
|
---|
133 | typeof(CollectionBase<IConnector>));
|
---|
134 |
|
---|
135 | info.AddValue(
|
---|
136 | "IsFixed",
|
---|
137 | mIsFixed);
|
---|
138 |
|
---|
139 | info.AddValue(
|
---|
140 | "ShowConnectors",
|
---|
141 | mShowConnectors);
|
---|
142 |
|
---|
143 | }
|
---|
144 | #endregion
|
---|
145 |
|
---|
146 | #region Xml serialization
|
---|
147 | /// <summary>
|
---|
148 | /// This property is reserved, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"></see> to the class instead.
|
---|
149 | /// </summary>
|
---|
150 | /// <returns>
|
---|
151 | /// 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.
|
---|
152 | /// </returns>
|
---|
153 | public override XmlSchema GetSchema()
|
---|
154 | {
|
---|
155 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
156 | }
|
---|
157 |
|
---|
158 | /// <summary>
|
---|
159 | /// Generates an object from its XML representation.
|
---|
160 | /// </summary>
|
---|
161 | /// <param name="reader">The <see cref="T:System.Xml.XmlReader"></see> stream from which the object is deserialized.</param>
|
---|
162 | public override void ReadXml(System.Xml.XmlReader reader)
|
---|
163 | {
|
---|
164 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
165 | }
|
---|
166 |
|
---|
167 | /// <summary>
|
---|
168 | /// Converts an object into its XML representation.
|
---|
169 | /// </summary>
|
---|
170 | /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"></see> stream to which the object is serialized.</param>
|
---|
171 | public override void WriteXml(System.Xml.XmlWriter writer)
|
---|
172 | {
|
---|
173 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
174 | }
|
---|
175 | #endregion
|
---|
176 |
|
---|
177 | #region IDeserializationCallback Members
|
---|
178 |
|
---|
179 | /// <summary>
|
---|
180 | /// Runs when the entire object graph has been deserialized.
|
---|
181 | /// </summary>
|
---|
182 | /// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param>
|
---|
183 | public override void OnDeserialization(object sender)
|
---|
184 | {
|
---|
185 | base.OnDeserialization(sender);
|
---|
186 |
|
---|
187 |
|
---|
188 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
189 | Trace.WriteLine("IDeserializationCallback of 'ShapeBase' called.");
|
---|
190 | }
|
---|
191 |
|
---|
192 | #endregion
|
---|
193 | }
|
---|
194 | }
|
---|