using System; using System.Diagnostics; using System.Drawing; using System.Runtime.Serialization; using System.Xml.Schema; using System.Xml.Serialization; namespace Netron.Diagramming.Core { /// /// Complementary partial class related to (de)serialization. /// [Serializable] public partial class ClassShape : ISerializable, IXmlSerializable, IDeserializationCallback { #region Deserialization constructor /// /// Deserialization constructor /// /// The info. /// The context. protected ClassShape(SerializationInfo info, StreamingContext context) : base(info, context) { if (Tracing.BinaryDeserializationSwitch.Enabled) Trace.WriteLine("Deserializing the fields of 'ClassShape'."); double version = info.GetDouble("ClassShapeVersion"); this.Resizable = false; this.mTitle = info.GetString("Title"); this.mSubTitle = info.GetString("SubTitle"); sf.Trimming = StringTrimming.EllipsisCharacter; this.textMaterial = info.GetValue("TextMaterial", typeof(LabelMaterial)) as LabelMaterial; mFolders = new CollectionBase(); this.Resizable = false; this.mCollapsed = info.GetBoolean("Collapsed"); this.mBodyType = (BodyType)Enum.Parse(typeof(BodyType), info.GetString("BodyType")); } #endregion #region Serialization events /* [OnSerializing] void OnSerializing(StreamingContext context) { Trace.WriteLine("Starting to serializing the 'ClassShape' class..."); } [OnSerialized] void OnSerialized(StreamingContext context) { Trace.WriteLine("...serialization of 'ClassShape' finished"); } */ #endregion #region Deserialization events /* [OnDeserializing] void OnDeserializing(StreamingContext context) { Trace.Indent(); Trace.WriteLine("Starting deserializing the 'ClassShape' class..."); } */ [OnDeserialized] void OnDeserialized(StreamingContext context) { if (Tracing.BinaryDeserializationSwitch.Enabled) Trace.WriteLine("...deserialization of 'ClassShape' finished"); #region Loop over the children and make re-attach the events foreach (IShapeMaterial material in Children) { //set the parent material.Shape = this; if (typeof(FolderMaterial).IsInstanceOfType(material)) { (material as FolderMaterial).OnFolderChanged += new EventHandler(folders_OnFolderChanged); mFolders.Add(material as FolderMaterial); bodyHeight += material.Rectangle.Height + 3; } else if (typeof(SwitchIconMaterial).IsInstanceOfType(material)) { xicon = material as SwitchIconMaterial; xicon.Collapsed = mCollapsed; (material as SwitchIconMaterial).OnExpand += new EventHandler(xicon_OnExpand); (material as SwitchIconMaterial).OnCollapse += new EventHandler(xicon_OnCollapse); } } #endregion #region Set the initial state if (mCollapsed) { Collapse(); } else { Expand(); } #endregion #region Update the body, this will set the bodytype for example UpdateBody(); #endregion #region Finally, position everything Transform(Rectangle); #endregion } #endregion #region Serialization /// /// Populates a with the data needed to serialize the target object. /// /// The to populate with data. /// The destination (see ) for this serialization. /// The caller does not have the required permission. public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); if (Tracing.BinarySerializationSwitch.Enabled) Trace.WriteLine("Serializing the fields of 'ClassShape'."); info.AddValue("Title", this.Title); info.AddValue("SubTitle", this.SubTitle); info.AddValue("TextMaterial", this.textMaterial, typeof(LabelMaterial)); info.AddValue("Collapsed", mCollapsed); info.AddValue("BodyType", mBodyType.ToString()); info.AddValue("ClassShapeVersion", classShapeVersion); } #endregion #region Xml serialization /// /// This property is reserved, apply the to the class instead. /// /// /// An that describes the XML representation of the object that is produced by the method and consumed by the method. /// public override XmlSchema GetSchema() { throw new NotImplementedException("The method or operation is not implemented."); } /// /// Generates an object from its XML representation. /// /// The stream from which the object is deserialized. public override void ReadXml(System.Xml.XmlReader reader) { throw new NotImplementedException("The method or operation is not implemented."); } /// /// Converts an object into its XML representation. /// /// The stream to which the object is serialized. public override void WriteXml(System.Xml.XmlWriter writer) { throw new NotImplementedException("The method or operation is not implemented."); } #endregion /// /// Runs when the entire object graph has been deserialized. /// /// The object that initiated the callback. The functionality for this parameter is not currently implemented. public override void OnDeserialization(object sender) { base.OnDeserialization(sender); if (Tracing.BinaryDeserializationSwitch.Enabled) Trace.WriteLine("IDeserializationCallback of 'ClassShape' called."); } } }