1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Runtime.Serialization;
|
---|
5 | using System.Xml.Serialization;
|
---|
6 | using System.Xml.Schema;
|
---|
7 | using System.Diagnostics;
|
---|
8 | using System.Drawing;
|
---|
9 | using ToolBox.Formatting;
|
---|
10 |
|
---|
11 |
|
---|
12 | namespace Netron.Diagramming.Core
|
---|
13 | {
|
---|
14 | [Serializable]
|
---|
15 | public partial class TextStyle :
|
---|
16 | ISerializable,
|
---|
17 | IXmlSerializable,
|
---|
18 | IDeserializationCallback
|
---|
19 | {
|
---|
20 | #region Deserialization constructor
|
---|
21 |
|
---|
22 | // ------------------------------------------------------------------
|
---|
23 | /// <summary>
|
---|
24 | /// Deserialization constructor
|
---|
25 | /// </summary>
|
---|
26 | /// <param name="info">The info.</param>
|
---|
27 | /// <param name="context">The context.</param>
|
---|
28 | // ------------------------------------------------------------------
|
---|
29 | protected TextStyle(
|
---|
30 | SerializationInfo info,
|
---|
31 | StreamingContext context)
|
---|
32 | {
|
---|
33 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
34 | {
|
---|
35 | Trace.WriteLine("Deserializing the fields of 'TextStyle'.");
|
---|
36 | }
|
---|
37 |
|
---|
38 | double version = info.GetDouble("TextStyleVersion");
|
---|
39 |
|
---|
40 | mDecimalPlaces = info.GetInt32("DecimalPlaces");
|
---|
41 |
|
---|
42 | mTextFormat = (TextFormat) info.GetValue(
|
---|
43 | "TextFormat",
|
---|
44 | typeof(TextFormat));
|
---|
45 |
|
---|
46 | mFont = (Font) info.GetValue(
|
---|
47 | "Font",
|
---|
48 | typeof(Font));
|
---|
49 |
|
---|
50 | mFontColor = (Color) info.GetValue(
|
---|
51 | "FontColor",
|
---|
52 | typeof(Color));
|
---|
53 |
|
---|
54 | mHorizontalAlignment = (StringAlignment)info.GetValue(
|
---|
55 | "HorizontalAlignment",
|
---|
56 | typeof(StringAlignment));
|
---|
57 |
|
---|
58 | mVerticalAlignment = (StringAlignment)info.GetValue(
|
---|
59 | "VerticalAlignment",
|
---|
60 | typeof(StringAlignment));
|
---|
61 | }
|
---|
62 |
|
---|
63 | #endregion
|
---|
64 |
|
---|
65 | #region Serialization events
|
---|
66 | /*
|
---|
67 | [OnSerializing]
|
---|
68 | void OnSerializing(StreamingContext context)
|
---|
69 | {
|
---|
70 | Trace.WriteLine("Starting to serializing the 'PenStyle' class...");
|
---|
71 | }
|
---|
72 | [OnSerialized]
|
---|
73 | void OnSerialized(StreamingContext context)
|
---|
74 | {
|
---|
75 | Trace.WriteLine("...serialization of 'PenStyle' finished");
|
---|
76 | }
|
---|
77 | */
|
---|
78 | #endregion
|
---|
79 |
|
---|
80 | #region Deserialization events
|
---|
81 | /*
|
---|
82 | [OnDeserializing]
|
---|
83 | void OnDeserializing(StreamingContext context)
|
---|
84 | {
|
---|
85 | Trace.Indent();
|
---|
86 | Trace.WriteLine("Starting deserializing the 'PenStyle' class...");
|
---|
87 | }
|
---|
88 | [OnDeserialized]
|
---|
89 | void OnDeserialized(StreamingContext context)
|
---|
90 | {
|
---|
91 | Trace.WriteLine("...deserialization of 'PenStyle' finished");
|
---|
92 | Trace.Unindent();
|
---|
93 | }
|
---|
94 | */
|
---|
95 | #endregion
|
---|
96 |
|
---|
97 | #region Serialization
|
---|
98 | /// <summary>
|
---|
99 | /// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> with the data needed to serialize the target object.
|
---|
100 | /// </summary>
|
---|
101 | /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> to populate with data.</param>
|
---|
102 | /// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"></see>) for this serialization.</param>
|
---|
103 | /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
|
---|
104 | public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
|
---|
105 | {
|
---|
106 | if(Tracing.BinarySerializationSwitch.Enabled)
|
---|
107 | Trace.WriteLine("Serializing the fields of 'PenStyle'.");
|
---|
108 |
|
---|
109 | info.AddValue("TextStyleVersion", textStyleVersion);
|
---|
110 |
|
---|
111 | info.AddValue("DecimalPlaces", this.mDecimalPlaces, typeof(int));
|
---|
112 |
|
---|
113 | info.AddValue("TextFormat", this.mTextFormat, typeof(TextFormat));
|
---|
114 |
|
---|
115 | // Note: we do not have to serialize the font style (i.e. IsBold,
|
---|
116 | // IsUnderline, etc.) because that's included in the font.
|
---|
117 | info.AddValue("Font", this.mFont, typeof(Font));
|
---|
118 |
|
---|
119 | info.AddValue("FontColor", this.mFontColor, typeof(Color));
|
---|
120 |
|
---|
121 | info.AddValue(
|
---|
122 | "HorizontalAlignment",
|
---|
123 | this.mHorizontalAlignment,
|
---|
124 | typeof(StringAlignment));
|
---|
125 |
|
---|
126 | info.AddValue(
|
---|
127 | "VerticalAlignment",
|
---|
128 | this.mVerticalAlignment,
|
---|
129 | typeof(StringAlignment));
|
---|
130 | }
|
---|
131 | #endregion
|
---|
132 |
|
---|
133 | #region Xml serialization
|
---|
134 |
|
---|
135 | // ------------------------------------------------------------------
|
---|
136 | /// <summary>
|
---|
137 | /// This property is reserved, apply the
|
---|
138 | /// <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute">
|
---|
139 | /// </see> to the class instead.
|
---|
140 | /// </summary>
|
---|
141 | /// <returns>
|
---|
142 | /// An <see cref="T:System.Xml.Schema.XmlSchema"></see> that describes
|
---|
143 | /// the XML representation of the object that is produced by the
|
---|
144 | /// <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(
|
---|
145 | /// System.Xml.XmlWriter)"></see> method and consumed by the
|
---|
146 | /// <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(
|
---|
147 | /// System.Xml.XmlReader)"></see> method.
|
---|
148 | /// </returns>
|
---|
149 | // ------------------------------------------------------------------
|
---|
150 | public virtual XmlSchema GetSchema()
|
---|
151 | {
|
---|
152 | throw new NotImplementedException(
|
---|
153 | "The method or operation is not implemented.");
|
---|
154 | }
|
---|
155 |
|
---|
156 | // ------------------------------------------------------------------
|
---|
157 | /// <summary>
|
---|
158 | /// Generates an object from its XML representation.
|
---|
159 | /// </summary>
|
---|
160 | /// <param name="reader">The <see cref="T:System.Xml.XmlReader"></see>
|
---|
161 | /// stream from which the object is deserialized.</param>
|
---|
162 | // ------------------------------------------------------------------
|
---|
163 | public virtual void ReadXml(System.Xml.XmlReader reader)
|
---|
164 | {
|
---|
165 | throw new NotImplementedException(
|
---|
166 | "The method or operation is not implemented.");
|
---|
167 | }
|
---|
168 |
|
---|
169 | // ------------------------------------------------------------------
|
---|
170 | /// <summary>
|
---|
171 | /// Converts an object into its XML representation.
|
---|
172 | /// </summary>
|
---|
173 | /// <param name="writer">The <see cref="T:System.Xml.XmlWriter">
|
---|
174 | /// </see> stream to which the object is serialized.</param>
|
---|
175 | // ------------------------------------------------------------------
|
---|
176 | public virtual void WriteXml(System.Xml.XmlWriter writer)
|
---|
177 | {
|
---|
178 | throw new NotImplementedException(
|
---|
179 | "The method or operation is not implemented.");
|
---|
180 | }
|
---|
181 | #endregion
|
---|
182 |
|
---|
183 | // ------------------------------------------------------------------
|
---|
184 | /// <summary>
|
---|
185 | /// Runs when the entire object graph has been deserialized.
|
---|
186 | /// </summary>
|
---|
187 | /// <param name="sender">The object that initiated the callback. The
|
---|
188 | /// functionality for this parameter is not currently implemented.
|
---|
189 | /// </param>
|
---|
190 | // ------------------------------------------------------------------
|
---|
191 | public virtual void OnDeserialization(object sender)
|
---|
192 | {
|
---|
193 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
194 | {
|
---|
195 | Trace.WriteLine(
|
---|
196 | "IDeserializationCallback of 'PenStyle' called.");
|
---|
197 | }
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|