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