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/Model.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: 5.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
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 Model : 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 Model(SerializationInfo info, StreamingContext context) {
20      if (Tracing.BinaryDeserializationSwitch.Enabled) {
21        Trace.WriteLine("Deserializing the fields of 'Model'.");
22      }
23
24      double version = info.GetDouble("ModelVersion");
25
26      mPages = info.GetValue(
27          "Pages",
28          typeof(CollectionBase<IPage>)) as CollectionBase<IPage>;
29
30      //Init();
31    }
32    #endregion
33
34    #region Serialization events
35    /*
36        [OnSerializing]
37        void OnSerializing(StreamingContext context)
38        {
39            Trace.Indent();
40            Trace.WriteLine("Starting to serializing the 'Model' class...");
41        }
42        [OnSerialized]
43        void OnSerialized(StreamingContext context)
44        {
45           
46            Trace.WriteLine("...serialization of 'Model' finished");
47            Trace.Unindent();
48        }
49        */
50    #endregion
51
52    #region Deserialization events
53
54    [OnDeserializing]
55    void OnDeserializing(StreamingContext context) {
56      if (Tracing.BinaryDeserializationSwitch.Enabled)
57        Trace.WriteLine("Starting deserializing the 'Model' class...");
58      //the anchors is a temporary collection of Uid's and parent entities to re-connect connectors
59      //to their parent. The serialization process does serialize parenting because you need on deserialization an
60      //instance in order to connect to it.
61
62      Anchors.Clear();
63    }
64
65    [OnDeserialized]
66    void OnDeserialized(StreamingContext context) {
67      if (Tracing.BinaryDeserializationSwitch.Enabled)
68        Trace.WriteLine("...deserialization of 'Model' finished");
69    }
70
71    #endregion
72
73    #region Serialization
74    /// <summary>
75    /// Populates a <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> with the data needed to serialize the target object.
76    /// </summary>
77    /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"></see> to populate with data.</param>
78    /// <param name="context">The destination (see <see cref="T:System.Runtime.Serialization.StreamingContext"></see>) for this serialization.</param>
79    /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
80    public void GetObjectData(SerializationInfo info, StreamingContext context) {
81      if (Tracing.BinarySerializationSwitch.Enabled)
82        Trace.WriteLine("Serializing the fields of 'Model'.");
83
84      info.AddValue("ModelVersion", modelVersion);
85
86      info.AddValue("Pages", this.Pages, typeof(CollectionBase<IPage>));
87    }
88    #endregion
89
90    #region Xml serialization
91    /// <summary>
92    /// This property is reserved, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"></see> to the class instead.
93    /// </summary>
94    /// <returns>
95    /// 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.
96    /// </returns>
97    public XmlSchema GetSchema() {
98      throw new NotImplementedException("The method or operation is not implemented.");
99    }
100
101    /// <summary>
102    /// Generates an object from its XML representation.
103    /// </summary>
104    /// <param name="reader">The <see cref="T:System.Xml.XmlReader"></see> stream from which the object is deserialized.</param>
105    public void ReadXml(System.Xml.XmlReader reader) {
106      throw new NotImplementedException("The method or operation is not implemented.");
107    }
108
109    /// <summary>
110    /// Converts an object into its XML representation.
111    /// </summary>
112    /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"></see> stream to which the object is serialized.</param>
113    public void WriteXml(System.Xml.XmlWriter writer) {
114      throw new NotImplementedException("The method or operation is not implemented.");
115    }
116    #endregion
117
118    #region IDeserializationCallback Members
119
120    /// <summary>
121    /// Runs when the entire object graph has been deserialized.
122    /// </summary>
123    /// <param name="sender">The object that initiated the callback. The functionality for this parameter is not currently implemented.</param>
124    public void OnDeserialization(object sender) {
125
126      if (Tracing.BinaryDeserializationSwitch.Enabled)
127        Trace.WriteLine("IDeserializationCallback of 'Model' called.");
128      Init();
129      #region Binding of connectors
130
131      Dictionary<Guid, Anchor>.Enumerator enumer = Anchors.GetEnumerator();
132      System.Collections.Generic.KeyValuePair<Guid, Anchor> pair;
133      Anchor anchor;
134      while (enumer.MoveNext()) {
135        pair = enumer.Current;
136        anchor = pair.Value;
137        if (anchor.Parent != Guid.Empty) //there's a parent connector
138                {
139          if (Anchors.ContainsKey(anchor.Parent)) {
140            Anchors.GetAnchor(anchor.Parent).Instance.AttachConnector(anchor.Instance);
141          }
142        }
143      }
144      //clean up the anchoring matrix
145      Anchors.Clear();
146      #endregion
147    }
148
149    #endregion
150  }
151}
Note: See TracBrowser for help on using the repository browser.