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 ComplexShapeBase : 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 ComplexShapeBase(SerializationInfo info, StreamingContext context)
|
---|
25 | : base(info, context)
|
---|
26 | {
|
---|
27 |
|
---|
28 | double version = info.GetDouble("ComplexShapeBaseVersion");
|
---|
29 | mServices = new Dictionary<Type, IInteraction>();
|
---|
30 | mServices[typeof(IMouseListener)] = this;
|
---|
31 | mServices[typeof(IHoverListener)] = this;
|
---|
32 | this.mChildren = info.GetValue("Children", typeof(CollectionBase<IShapeMaterial>)) as CollectionBase<IShapeMaterial>;
|
---|
33 |
|
---|
34 | mChildren.OnItemAdded += new EventHandler<CollectionEventArgs<IShapeMaterial>>(mChildren_OnItemAdded);
|
---|
35 |
|
---|
36 |
|
---|
37 | if(Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
38 | Trace.WriteLine("Deserializing the fields of 'ComplexShapeBase'.");
|
---|
39 | }
|
---|
40 | #endregion
|
---|
41 |
|
---|
42 | #region Serialization events
|
---|
43 | /*
|
---|
44 | [OnSerializing]
|
---|
45 | void OnSerializing(StreamingContext context)
|
---|
46 | {
|
---|
47 | Trace.WriteLine("Starting to serializing the 'ComplexShapeBase' class...");
|
---|
48 | }
|
---|
49 | [OnSerialized]
|
---|
50 | void OnSerialized(StreamingContext context)
|
---|
51 | {
|
---|
52 | Trace.WriteLine("...serialization of 'ComplexShapeBase' finished");
|
---|
53 | }
|
---|
54 | */
|
---|
55 | #endregion
|
---|
56 |
|
---|
57 | #region Deserialization events
|
---|
58 | /*
|
---|
59 | [OnDeserializing]
|
---|
60 | void OnDeserializing(StreamingContext context)
|
---|
61 | {
|
---|
62 | Trace.Indent();
|
---|
63 | Trace.WriteLine("Starting deserializing the 'ComplexShapeBase' class...");
|
---|
64 | }
|
---|
65 | */
|
---|
66 | [OnDeserialized]
|
---|
67 | void OnDeserialized(StreamingContext context)
|
---|
68 | {
|
---|
69 | Transform(Rectangle);//the children have to be mapped still
|
---|
70 | //setting the shape since the deserialization does not raise the event ..
|
---|
71 | foreach(IShapeMaterial material in mChildren)
|
---|
72 | material.Shape = this;
|
---|
73 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
74 | Trace.WriteLine("...deserialization of 'ComplexShapeBase' finished");
|
---|
75 | }
|
---|
76 |
|
---|
77 | #endregion
|
---|
78 |
|
---|
79 | #region Serialization
|
---|
80 | /// <summary>
|
---|
81 | /// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> with the data needed to serialize the target object.
|
---|
82 | /// </summary>
|
---|
83 | /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> to populate with data.</param>
|
---|
84 | /// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"></see>) for this serialization.</param>
|
---|
85 | /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
|
---|
86 | public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
---|
87 | {
|
---|
88 | if(Tracing.BinarySerializationSwitch.Enabled)
|
---|
89 | Trace.WriteLine("Serializing the fields of 'ComplexShapeBase'.");
|
---|
90 | base.GetObjectData(info, context);
|
---|
91 |
|
---|
92 | info.AddValue("Children", this.mChildren, typeof(CollectionBase<IShapeMaterial>));
|
---|
93 | info.AddValue("ComplexShapeBaseVersion", complexShapeVersion);
|
---|
94 | }
|
---|
95 | #endregion
|
---|
96 |
|
---|
97 | #region Xml serialization
|
---|
98 | /// <summary>
|
---|
99 | /// This property is reserved, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"></see> to the class instead.
|
---|
100 | /// </summary>
|
---|
101 | /// <returns>
|
---|
102 | /// 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.
|
---|
103 | /// </returns>
|
---|
104 | public override XmlSchema GetSchema()
|
---|
105 | {
|
---|
106 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
107 | }
|
---|
108 |
|
---|
109 | /// <summary>
|
---|
110 | /// Generates an object from its XML representation.
|
---|
111 | /// </summary>
|
---|
112 | /// <param name="reader">The <see cref="T:System.Xml.XmlReader"></see> stream from which the object is deserialized.</param>
|
---|
113 | public override void ReadXml(System.Xml.XmlReader reader)
|
---|
114 | {
|
---|
115 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
116 | }
|
---|
117 |
|
---|
118 | /// <summary>
|
---|
119 | /// Converts an object into its XML representation.
|
---|
120 | /// </summary>
|
---|
121 | /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"></see> stream to which the object is serialized.</param>
|
---|
122 | public override void WriteXml(System.Xml.XmlWriter writer)
|
---|
123 | {
|
---|
124 | throw new NotImplementedException("The method or operation is not implemented.");
|
---|
125 | }
|
---|
126 | #endregion
|
---|
127 |
|
---|
128 | /// <summary>
|
---|
129 | /// Runs when the entire object graph has been deserialized.
|
---|
130 | /// </summary>
|
---|
131 | /// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param>
|
---|
132 | public override void OnDeserialization(object sender)
|
---|
133 | {
|
---|
134 | base.OnDeserialization(sender);
|
---|
135 |
|
---|
136 | if(Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
137 | Trace.WriteLine("IDeserializationCallback of 'ComplexShapeBase' called.");
|
---|
138 | }
|
---|
139 | }
|
---|
140 | }
|
---|