using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.Serialization;
namespace Netron.GraphLib.IO.Binary
{
///
/// Encapsulates the GraphAbstract and additional ambient properties of the GraphControl
/// for binary (de)serialization.
///
[Serializable] class BinaryCapsule : ISerializable
{
#region Fields
///
/// the actual diagram
///
private GraphAbstract mGraphAbstract;
///
/// the ambiant properties
///
private BinaryAmbiance mBinaryAmbiance;
///
/// the thumbnail
///
private Image mThumbnail;
#endregion
#region Properties
///
/// Gets or sets the thumbnail of the diagram
///
public Image Thumbnail
{
get{return mThumbnail;}
set{mThumbnail = value;}
}
///
/// Gets or sets the GraphAbstract
///
public GraphAbstract Abstract
{
get{return mGraphAbstract;}
set{mGraphAbstract = value;}
}
///
/// Gets or sets the ambiance properties
///
public BinaryAmbiance Ambiance
{
get{return mBinaryAmbiance;}
set{mBinaryAmbiance = value;}
}
#endregion
#region Constructor
///
/// Default Constructor
///
public BinaryCapsule()
{
}
protected BinaryCapsule(SerializationInfo info, StreamingContext context)
{
try
{
this.mBinaryAmbiance = info.GetValue("mBinaryAmbiance", typeof(BinaryAmbiance)) as BinaryAmbiance;
}
catch(Exception exc)
{
Trace.WriteLine(exc.Message, "BinaryCapsule.DeserializationConstructor");
//trying to recover the old binaries
this.mBinaryAmbiance = info.GetValue("mBinaryAmbience", typeof(BinaryAmbiance)) as BinaryAmbiance;
}
this.mGraphAbstract = info.GetValue("mGraphAbstract", typeof(GraphAbstract)) as GraphAbstract;
this.mThumbnail = info.GetValue("mThumbnail", typeof(Image)) as Image;
}
///
/// Constructor
///
///
///
public BinaryCapsule(GraphAbstract graphAbstract, BinaryAmbiance ambiance)
{
this.mGraphAbstract = graphAbstract;
this.mBinaryAmbiance = ambiance;
}
#endregion
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("mGraphAbstract",this.mGraphAbstract);
info.AddValue("mBinaryAmbiance", this.mBinaryAmbiance);
info.AddValue("mThumbnail", this.mThumbnail);
}
}
}