1 | using System;
|
---|
2 | using System.Diagnostics;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Runtime.Serialization;
|
---|
5 | using System.Xml.Schema;
|
---|
6 | using System.Xml.Serialization;
|
---|
7 | namespace Netron.Diagramming.Core {
|
---|
8 | // ----------------------------------------------------------------------
|
---|
9 | /// <summary>
|
---|
10 | /// Complementary partial class related to (de)serialization.
|
---|
11 | /// </summary>
|
---|
12 | // ----------------------------------------------------------------------
|
---|
13 | [Serializable]
|
---|
14 | public partial class DiagramEntityBase :
|
---|
15 | ISerializable,
|
---|
16 | IXmlSerializable,
|
---|
17 | IDeserializationCallback {
|
---|
18 | #region Deserialization constructor
|
---|
19 |
|
---|
20 | // ------------------------------------------------------------------
|
---|
21 | /// <summary>
|
---|
22 | /// Deserialization constructor
|
---|
23 | /// </summary>
|
---|
24 | /// <param name="info">The info.</param>
|
---|
25 | /// <param name="context">The context.</param>
|
---|
26 | // ------------------------------------------------------------------
|
---|
27 | protected DiagramEntityBase(
|
---|
28 | SerializationInfo info,
|
---|
29 | StreamingContext context) {
|
---|
30 | if (Tracing.BinaryDeserializationSwitch.Enabled) {
|
---|
31 | Trace.WriteLine(
|
---|
32 | "Deserializing the fields of 'DiagramEntityBase'.");
|
---|
33 | }
|
---|
34 | Initialize();
|
---|
35 |
|
---|
36 | string version = info.GetString("DiagramEntityBaseVersion");
|
---|
37 | this.mName = info.GetString("Name");
|
---|
38 | this.mSceneIndex = info.GetInt32("SceneIndex");
|
---|
39 | this.mUid = new Guid(info.GetString("Uid"));
|
---|
40 | this.mResizable = info.GetBoolean("Resizable");
|
---|
41 |
|
---|
42 | this.mPaintStyle = info.GetValue(
|
---|
43 | "PaintStyle",
|
---|
44 | typeof(IPaintStyle)) as IPaintStyle;
|
---|
45 |
|
---|
46 | this.mPenStyle = info.GetValue(
|
---|
47 | "PenStyle",
|
---|
48 | typeof(IPenStyle)) as IPenStyle;
|
---|
49 |
|
---|
50 | mAllowDelete = (bool)info.GetValue("AllowDelete", typeof(bool));
|
---|
51 | myMinSize = (Size)info.GetValue("MinSize", typeof(Size));
|
---|
52 | myMaxSize = (Size)info.GetValue("MaxSize", typeof(Size));
|
---|
53 | mVisible = (bool)info.GetValue("Visible", typeof(bool));
|
---|
54 | mEnabled = (bool)info.GetValue("Enabled", typeof(bool));
|
---|
55 | }
|
---|
56 | #endregion
|
---|
57 |
|
---|
58 | #region Serialization events
|
---|
59 | /*
|
---|
60 | [OnSerializing]
|
---|
61 | void OnSerializing(StreamingContext context)
|
---|
62 | {
|
---|
63 | Trace.WriteLine("Starting to serializing the 'DiagramEntityBase' class...");
|
---|
64 | }
|
---|
65 | [OnSerialized]
|
---|
66 | void OnSerialized(StreamingContext context)
|
---|
67 | {
|
---|
68 | Trace.WriteLine("...serialization of 'DiagramEntityBase' finished");
|
---|
69 | }
|
---|
70 | */
|
---|
71 | #endregion
|
---|
72 |
|
---|
73 | #region Deserialization events
|
---|
74 | /*
|
---|
75 | [OnDeserializing]
|
---|
76 | void OnDeserializing(StreamingContext context)
|
---|
77 | {
|
---|
78 | Trace.Indent();
|
---|
79 | Trace.WriteLine("Starting deserializing the 'DiagramEntityBase' class...");
|
---|
80 | }
|
---|
81 | */
|
---|
82 | [OnDeserialized]
|
---|
83 | void OnDeserialized(StreamingContext context) {
|
---|
84 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
85 | Trace.WriteLine("...deserialization of 'DiagramEntityBase' finished");
|
---|
86 | }
|
---|
87 |
|
---|
88 | #endregion
|
---|
89 |
|
---|
90 | #region Serialization
|
---|
91 |
|
---|
92 | // ------------------------------------------------------------------
|
---|
93 | /// <summary>
|
---|
94 | /// Populates a <see cref=
|
---|
95 | /// "T:System.Runtime.Serialization.SerializationInfo"></see> with
|
---|
96 | /// the data needed to serialize the target object.
|
---|
97 | /// </summary>
|
---|
98 | /// <param name="info">The
|
---|
99 | /// <see cref="T:System.Runtime.Serialization.SerializationInfo"></see>
|
---|
100 | /// to populate with data.</param>
|
---|
101 | /// <param name="context">The destination (see
|
---|
102 | /// <see cref="T:System.Runtime.Serialization.StreamingContext"></see>)
|
---|
103 | /// for this serialization.</param>
|
---|
104 | /// <exception cref="T:System.Security.SecurityException">The caller
|
---|
105 | /// does not have the required permission. </exception>
|
---|
106 | // ------------------------------------------------------------------
|
---|
107 | public virtual void GetObjectData(
|
---|
108 | SerializationInfo info,
|
---|
109 | StreamingContext context) {
|
---|
110 | if (Tracing.BinarySerializationSwitch.Enabled) {
|
---|
111 | Trace.WriteLine("Serializing the fields of " +
|
---|
112 | "'DiagramEntityBase'.");
|
---|
113 | }
|
---|
114 |
|
---|
115 | info.AddValue("DiagramEntityBaseVersion", diagramEntityBaseVersion);
|
---|
116 | info.AddValue("Name", this.Name);
|
---|
117 | info.AddValue("SceneIndex", this.SceneIndex);
|
---|
118 | info.AddValue("Uid", this.Uid.ToString());
|
---|
119 | info.AddValue("Resizable", this.mResizable);
|
---|
120 | info.AddValue("PaintStyle", this.mPaintStyle, typeof(IPaintStyle));
|
---|
121 | info.AddValue("PenStyle", this.mPenStyle, typeof(IPenStyle));
|
---|
122 | info.AddValue("AllowDelete", mAllowDelete, typeof(bool));
|
---|
123 | info.AddValue("MinSize", myMinSize, typeof(Size));
|
---|
124 | info.AddValue("MaxSize", myMaxSize, typeof(Size));
|
---|
125 | info.AddValue("Visible", mVisible, typeof(bool));
|
---|
126 | info.AddValue("Enabled", mEnabled, typeof(bool));
|
---|
127 | }
|
---|
128 | #endregion
|
---|
129 |
|
---|
130 | #region Xml serialization
|
---|
131 | /// <summary>
|
---|
132 | /// This property is reserved, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"></see> to the class instead.
|
---|
133 | /// </summary>
|
---|
134 | /// <returns>
|
---|
135 | /// 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.
|
---|
136 | /// </returns>
|
---|
137 | public virtual XmlSchema GetSchema() {
|
---|
138 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
139 | }
|
---|
140 |
|
---|
141 | /// <summary>
|
---|
142 | /// Generates an object from its XML representation.
|
---|
143 | /// </summary>
|
---|
144 | /// <param name="reader">The <see cref="T:System.Xml.XmlReader"></see> stream from which the object is deserialized.</param>
|
---|
145 | public virtual void ReadXml(System.Xml.XmlReader reader) {
|
---|
146 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
147 | }
|
---|
148 |
|
---|
149 | /// <summary>
|
---|
150 | /// Converts an object into its XML representation.
|
---|
151 | /// </summary>
|
---|
152 | /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"></see> stream to which the object is serialized.</param>
|
---|
153 | public virtual void WriteXml(System.Xml.XmlWriter writer) {
|
---|
154 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
155 | }
|
---|
156 | #endregion
|
---|
157 |
|
---|
158 | #region IDeserializationCallback Members
|
---|
159 |
|
---|
160 | /// <summary>
|
---|
161 | /// Runs when the entire object graph has been deserialized.
|
---|
162 | /// </summary>
|
---|
163 | /// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param>
|
---|
164 | public virtual void OnDeserialization(object sender) {
|
---|
165 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
166 | Trace.WriteLine("IDeserializationCallback of 'DiagramEntityBase' called.");
|
---|
167 | UpdatePaintingMaterial();
|
---|
168 | }
|
---|
169 |
|
---|
170 | #endregion
|
---|
171 | }
|
---|
172 | }
|
---|