[2768] | 1 | using System;
|
---|
[4068] | 2 | using System.Diagnostics;
|
---|
[2768] | 3 | using System.Drawing;
|
---|
| 4 | using System.Runtime.Serialization;
|
---|
[4068] | 5 | using System.Xml.Schema;
|
---|
[2768] | 6 | using System.Xml.Serialization;
|
---|
[4068] | 7 | namespace 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
|
---|
[2768] | 14 | /// <summary>
|
---|
[4068] | 15 | /// Deserialization constructor
|
---|
[2768] | 16 | /// </summary>
|
---|
[4068] | 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) {
|
---|
[2768] | 21 |
|
---|
| 22 |
|
---|
[4068] | 23 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
| 24 | Trace.WriteLine("Deserializing the fields of 'ClassShape'.");
|
---|
[2768] | 25 |
|
---|
[4068] | 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 | /*
|
---|
[2768] | 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 | */
|
---|
[4068] | 53 | #endregion
|
---|
[2768] | 54 |
|
---|
[4068] | 55 | #region Deserialization events
|
---|
| 56 | /*
|
---|
[2768] | 57 | [OnDeserializing]
|
---|
| 58 | void OnDeserializing(StreamingContext context)
|
---|
| 59 | {
|
---|
| 60 | Trace.Indent();
|
---|
| 61 | Trace.WriteLine("Starting deserializing the 'ClassShape' class...");
|
---|
| 62 | }
|
---|
| 63 | */
|
---|
[4068] | 64 | [OnDeserialized]
|
---|
| 65 | void OnDeserialized(StreamingContext context) {
|
---|
| 66 | if (Tracing.BinaryDeserializationSwitch.Enabled)
|
---|
| 67 | Trace.WriteLine("...deserialization of 'ClassShape' finished");
|
---|
[2768] | 68 |
|
---|
[4068] | 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;
|
---|
[2768] | 73 |
|
---|
[4068] | 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
|
---|
[2768] | 86 |
|
---|
[4068] | 87 | #region Set the initial state
|
---|
| 88 | if (mCollapsed) {
|
---|
| 89 | Collapse();
|
---|
| 90 | } else {
|
---|
| 91 | Expand();
|
---|
| 92 | }
|
---|
| 93 | #endregion
|
---|
[2768] | 94 |
|
---|
[4068] | 95 | #region Update the body, this will set the bodytype for example
|
---|
| 96 | UpdateBody();
|
---|
| 97 | #endregion
|
---|
[2768] | 98 |
|
---|
[4068] | 99 | #region Finally, position everything
|
---|
| 100 | Transform(Rectangle);
|
---|
| 101 | #endregion
|
---|
| 102 | }
|
---|
[2768] | 103 |
|
---|
[4068] | 104 | #endregion
|
---|
[2768] | 105 |
|
---|
[4068] | 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) {
|
---|
[2768] | 114 |
|
---|
[4068] | 115 | base.GetObjectData(info, context);
|
---|
| 116 | if (Tracing.BinarySerializationSwitch.Enabled)
|
---|
| 117 | Trace.WriteLine("Serializing the fields of 'ClassShape'.");
|
---|
[2768] | 118 |
|
---|
[4068] | 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
|
---|
[2768] | 127 |
|
---|
[4068] | 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 | }
|
---|
[2768] | 138 |
|
---|
[4068] | 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.");
|
---|
[2768] | 145 | }
|
---|
[4068] | 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 | }
|
---|
[2768] | 167 | }
|
---|