Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Serialization/ClassShape.Serialization.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 6.8 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Drawing;
4using System.Runtime.Serialization;
5using System.Xml.Schema;
6using System.Xml.Serialization;
7namespace Netron.Diagramming.Core {
8  /// <summary>
9  /// Complementary partial class related to (de)serialization.
10  /// </summary>
11  [Serializable]
12  public partial class ClassShape : 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 ClassShape(SerializationInfo info, StreamingContext context)
20      : base(info, context) {
21
22
23      if (Tracing.BinaryDeserializationSwitch.Enabled)
24        Trace.WriteLine("Deserializing the fields of 'ClassShape'.");
25
26      double version = info.GetDouble("ClassShapeVersion");
27      this.Resizable = false;
28      this.mTitle = info.GetString("Title");
29      this.mSubTitle = info.GetString("SubTitle");
30      sf.Trimming = StringTrimming.EllipsisCharacter;
31      this.textMaterial = info.GetValue("TextMaterial", typeof(LabelMaterial)) as LabelMaterial;
32      mFolders = new CollectionBase<FolderMaterial>();
33      this.Resizable = false;
34      this.mCollapsed = info.GetBoolean("Collapsed");
35      this.mBodyType = (BodyType)Enum.Parse(typeof(BodyType), info.GetString("BodyType"));
36
37    }
38    #endregion
39
40    #region Serialization events
41    /*
42        [OnSerializing]
43        void OnSerializing(StreamingContext context)
44        {
45            Trace.WriteLine("Starting to serializing the 'ClassShape' class...");
46        }
47        [OnSerialized]
48        void OnSerialized(StreamingContext context)
49        {
50            Trace.WriteLine("...serialization of 'ClassShape' finished");
51        }
52        */
53    #endregion
54
55    #region Deserialization events
56    /*
57        [OnDeserializing]
58        void OnDeserializing(StreamingContext context)
59        {
60            Trace.Indent();
61            Trace.WriteLine("Starting deserializing the 'ClassShape' class...");
62        }
63        */
64    [OnDeserialized]
65    void OnDeserialized(StreamingContext context) {
66      if (Tracing.BinaryDeserializationSwitch.Enabled)
67        Trace.WriteLine("...deserialization of 'ClassShape' finished");
68
69      #region Loop over the children and make re-attach the events
70      foreach (IShapeMaterial material in Children) {
71        //set the parent
72        material.Shape = this;
73
74        if (typeof(FolderMaterial).IsInstanceOfType(material)) {
75          (material as FolderMaterial).OnFolderChanged += new EventHandler<RectangleEventArgs>(folders_OnFolderChanged);
76          mFolders.Add(material as FolderMaterial);
77          bodyHeight += material.Rectangle.Height + 3;
78        } else if (typeof(SwitchIconMaterial).IsInstanceOfType(material)) {
79          xicon = material as SwitchIconMaterial;
80          xicon.Collapsed = mCollapsed;
81          (material as SwitchIconMaterial).OnExpand += new EventHandler(xicon_OnExpand);
82          (material as SwitchIconMaterial).OnCollapse += new EventHandler(xicon_OnCollapse);
83        }
84      }
85      #endregion
86
87      #region Set the initial state
88      if (mCollapsed) {
89        Collapse();
90      } else {
91        Expand();
92      }
93      #endregion
94
95      #region Update the body, this will set the bodytype for example
96      UpdateBody();
97      #endregion
98
99      #region Finally, position everything
100      Transform(Rectangle);
101      #endregion
102    }
103
104    #endregion
105
106    #region Serialization
107    /// <summary>
108    /// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> with the data needed to serialize the target object.
109    /// </summary>
110    /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> to populate with data.</param>
111    /// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"></see>) for this serialization.</param>
112    /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
113    public override void GetObjectData(SerializationInfo info, StreamingContext context) {
114
115      base.GetObjectData(info, context);
116      if (Tracing.BinarySerializationSwitch.Enabled)
117        Trace.WriteLine("Serializing the fields of 'ClassShape'.");
118
119      info.AddValue("Title", this.Title);
120      info.AddValue("SubTitle", this.SubTitle);
121      info.AddValue("TextMaterial", this.textMaterial, typeof(LabelMaterial));
122      info.AddValue("Collapsed", mCollapsed);
123      info.AddValue("BodyType", mBodyType.ToString());
124      info.AddValue("ClassShapeVersion", classShapeVersion);
125    }
126    #endregion
127
128    #region Xml serialization
129    /// <summary>
130    /// This property is reserved, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"></see> to the class instead.
131    /// </summary>
132    /// <returns>
133    /// 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.
134    /// </returns>
135    public override XmlSchema GetSchema() {
136      throw new NotImplementedException("The method or operation is not implemented.");
137    }
138
139    /// <summary>
140    /// Generates an object from its XML representation.
141    /// </summary>
142    /// <param name="reader">The <see cref="T:System.Xml.XmlReader"></see> stream from which the object is deserialized.</param>
143    public override void ReadXml(System.Xml.XmlReader reader) {
144      throw new NotImplementedException("The method or operation is not implemented.");
145    }
146
147    /// <summary>
148    /// Converts an object into its XML representation.
149    /// </summary>
150    /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"></see> stream to which the object is serialized.</param>
151    public override void WriteXml(System.Xml.XmlWriter writer) {
152      throw new NotImplementedException("The method or operation is not implemented.");
153    }
154    #endregion
155
156    /// <summary>
157    /// Runs when the entire object graph has been deserialized.
158    /// </summary>
159    /// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param>
160    public override void OnDeserialization(object sender) {
161      base.OnDeserialization(sender);
162
163      if (Tracing.BinaryDeserializationSwitch.Enabled)
164        Trace.WriteLine("IDeserializationCallback of 'ClassShape' called.");
165    }
166  }
167}
Note: See TracBrowser for help on using the repository browser.