using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization; using System.IO; using System.Xml; namespace EduNetworkBuilder { [Serializable] public class NetworkComponent { public bool IsDirty = true; //If something has changed and it needs to be re-drawn. It starts as "true" protected int UniqueIdentifier = NB.GetUniqueIdentifier(); public string hostname = ""; public virtual void Print(Image BaseImage, bool DrawTitle) { } public virtual bool HasMac(string MAC) { return false; } public virtual void ProcessPacket(Packet tPacket) { } public virtual void Destroy() { //This really does nothing. But the link will trigger some stuff needing to be done } public virtual List arp(UInt32 IP) { List arps = new List(); return arps; //links have no MAC addresses } public virtual void Save(XmlWriter writer) { } public virtual void Load(XmlNode theNode) { } public virtual void UpdateFromComponent(NetworkComponent CopyFrom) { } public virtual void DoProcessing(Packet tPacket) { } public virtual void DoMoving(Packet tPacket) { } public virtual void DoInput(Packet tPacket) { } public virtual void DoOutput(Packet tPacket) { } public int GetUniqueIdentifier { get { return UniqueIdentifier; } } public static T Clone(T source) { if (!typeof(T).IsSerializable) { throw new ArgumentException(NB.Translate("NC_CloneSerialzable"), NB.Translate("_source")); } // Don't serialize a null object, simply return the default for that object if (Object.ReferenceEquals(source, null)) { return default(T); } IFormatter formatter = new BinaryFormatter(); Stream stream = new MemoryStream(); using (stream) { formatter.Serialize(stream, source); stream.Seek(0, SeekOrigin.Begin); return (T)formatter.Deserialize(stream); } } } }