From 2df6c5c2f887f215aabf31049fafe21e8b5faa5b Mon Sep 17 00:00:00 2001 From: Tim Young Date: Wed, 16 May 2018 09:14:18 -0500 Subject: [PATCH] Get loading and saving of devices in Actions working. Lots of things needed to be "public" so reflection works. --- EduNetworkBuilder/ActionClass.cs | 20 +- EduNetworkBuilder/IPAddress.cs | 24 +- EduNetworkBuilder/NB.cs | 2 +- EduNetworkBuilder/NBSettings.cs | 4 + EduNetworkBuilder/NetworkBuilder.cs | 15 +- EduNetworkBuilder/NetworkCard.cs | 8 +- EduNetworkBuilder/NetworkComponent.cs | 2 +- EduNetworkBuilder/NetworkDevice.cs | 26 +- EduNetworkBuilder/NetworkLink.cs | 4 +- .../Resources/EduNetworkReplay.xml | 536 +++++++++++++++++- 10 files changed, 608 insertions(+), 33 deletions(-) diff --git a/EduNetworkBuilder/ActionClass.cs b/EduNetworkBuilder/ActionClass.cs index 5514b5f..0da3560 100644 --- a/EduNetworkBuilder/ActionClass.cs +++ b/EduNetworkBuilder/ActionClass.cs @@ -20,12 +20,14 @@ namespace EduNetworkBuilder public void RegisterNet(Network starting) { StartingState = Network.DeepClone(starting); - CurrentNetAction = new NetworkAction(starting); + CurrentNetAction = FindAction(starting); + if(CurrentNetAction == null) + CurrentNetAction = new NetworkAction(starting); } public void Add(ActionClass What) { - if(CurrentNetAction == null) + if(CurrentNetAction == null || CurrentNetAction.HasBeenStored == true) { Network start = NB.GetNetwork(); if (start == null) return;//Do nothing @@ -35,6 +37,19 @@ namespace EduNetworkBuilder CurrentNetAction.Add(What); } + public NetworkAction FindAction(Network Fitting) + { + return FindAction(NameFromNet(Fitting)); + } + public NetworkAction FindAction(string Fitting) + { + foreach(NetworkAction one in NetActions) + { + if (one.NetworkName == Fitting) + return one; + } + return null; + } public bool CurrentNeedsStoring { get { if (CurrentNetAction == null) return false; @@ -161,6 +176,7 @@ namespace EduNetworkBuilder if(ChangedComponent is NetworkDevice) { source.UpdateFromComponent(ChangedComponent); //Copy any changes across + source.SetImageFromType(); //The image was not saved. Re-make it } else { //It is a link. Delete the old, make the new. Mark as linked diff --git a/EduNetworkBuilder/IPAddress.cs b/EduNetworkBuilder/IPAddress.cs index fde16cb..9fe940f 100644 --- a/EduNetworkBuilder/IPAddress.cs +++ b/EduNetworkBuilder/IPAddress.cs @@ -15,16 +15,30 @@ namespace EduNetworkBuilder public class NB_IPAddress { - private UInt32 _ip; - private UInt32 _mask; - private UInt32 _gw; - private IPAddressType myType; + public UInt32 _ip; + public UInt32 _mask; + public UInt32 _gw; + public IPAddressType myType; //Add in new values for the IP, Netmask, and gateway. Will start migrating to use these. private IPAddress theIP; private IPAddress theNetmask; private IPAddress theGateway; - public NB_IPAddress() { } //used for reflection + public NB_IPAddress() { } //used for reflection + /// + /// Duplicate an IP address structure + /// + /// + public NB_IPAddress(NB_IPAddress Orig) + { + _ip = Orig._ip; + _mask = Orig._mask; + _gw = Orig._gw; + myType = Orig.myType; + theIP = Orig.theIP; + theNetmask = Orig.theNetmask; + theGateway = Orig.theGateway; + } public NB_IPAddress(string ip, string mask, IPAddressType WhatType) { myType = WhatType; diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index 963bf60..50fb513 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -1453,7 +1453,7 @@ namespace EduNetworkBuilder ActionClass AC = new ActionClass(); AC.Action = NBAction.ping; AC.SourceID = HostID; - AC.Destination = Destination; + AC.Destination = new NB_IPAddress(Destination); RegisterAction(AC); diff --git a/EduNetworkBuilder/NBSettings.cs b/EduNetworkBuilder/NBSettings.cs index d48a808..b3aae08 100644 --- a/EduNetworkBuilder/NBSettings.cs +++ b/EduNetworkBuilder/NBSettings.cs @@ -162,6 +162,10 @@ namespace EduNetworkBuilder { ReplayMode = true; UserActions = NB.ReadFromXmlResource("EduNetworkReplay"); + foreach(NetworkAction NetAction in UserActions.NetActions) + { + NetAction.HasBeenStored = true; //All of them start out stored + } } public bool CheckIfDone(string PuzzleName) diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index 915a6f5..6867d0c 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -2862,12 +2862,15 @@ namespace EduNetworkBuilder if (OurSettings != null && OurSettings.ReplayMode) { ActionCollection AC = OurSettings.GetUserActionCollection(); - if(AC != null && AC.GetActionCount >0) - replayToolStripMenuItem.Visible = true; //Only visible if we have something to replay - if (AC.CurrentNeedsStoring) - storeReplayToolStripMenuItem.Visible = true; - if (AC.HasUnsavedChanges) - saveReplayToolStripMenuItem.Visible = true; + if (AC != null) + { + if (AC.GetActionCount > 0) + replayToolStripMenuItem.Visible = true; //Only visible if we have something to replay + if (AC.CurrentNeedsStoring && AC.GetActionCount > 0) + storeReplayToolStripMenuItem.Visible = true; + if (AC.HasUnsavedChanges) + saveReplayToolStripMenuItem.Visible = true; + } } } diff --git a/EduNetworkBuilder/NetworkCard.cs b/EduNetworkBuilder/NetworkCard.cs index 3a796b2..b0ec504 100644 --- a/EduNetworkBuilder/NetworkCard.cs +++ b/EduNetworkBuilder/NetworkCard.cs @@ -16,15 +16,15 @@ namespace EduNetworkBuilder public class NetworkCard { public string MAC = NB.GenerateMACAddress(); //Technically we should make sure it is unique - List interfaces = new List(); + public List interfaces = new List(); public bool UsesDHCP = false; public bool CanUseDHCP = false; public bool MustUseDHCP = false; - private NicType myNicType = NicType.eth; + public NicType myNicType = NicType.eth; public HostNicID myID; public int ConnectedLink=-1; //The link that is connected to this nic. - private int UniqueIdentifier = NB.GetUniqueIdentifier(); - private string _nic_name=""; + public int UniqueIdentifier = NB.GetUniqueIdentifier(); + public string _nic_name=""; public NB_IPAddress TunnelEndpoint; public string EncryptionKey; public string SSID; diff --git a/EduNetworkBuilder/NetworkComponent.cs b/EduNetworkBuilder/NetworkComponent.cs index 1797a65..04bdc52 100644 --- a/EduNetworkBuilder/NetworkComponent.cs +++ b/EduNetworkBuilder/NetworkComponent.cs @@ -18,7 +18,7 @@ namespace EduNetworkBuilder 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 int UniqueIdentifier = NB.GetUniqueIdentifier(); public string hostname = ""; /// /// isInvisible is what happens when we have forgotton something exists. We can have a forgotton switch, WAP, DHCP server diff --git a/EduNetworkBuilder/NetworkDevice.cs b/EduNetworkBuilder/NetworkDevice.cs index 62f8a67..bdce6da 100644 --- a/EduNetworkBuilder/NetworkDevice.cs +++ b/EduNetworkBuilder/NetworkDevice.cs @@ -14,19 +14,19 @@ namespace EduNetworkBuilder [Serializable] public class NetworkDevice : NetworkComponent { - protected List NICs = new List(); - protected NB_IPAddress DefaultGW = new NB_IPAddress(NB.ZeroIPString, NB.ZeroIPString, IPAddressType.gw); + public List NICs = new List(); + public NB_IPAddress DefaultGW = new NB_IPAddress(NB.ZeroIPString, NB.ZeroIPString, IPAddressType.gw); protected Image MyImage = null; - protected Point MyLocation; + public Point MyLocation; public int Size; protected List ArpTable = new List(); - protected NetworkComponentType myType = NetworkComponentType.none; - protected List RouteTable = new List(); - protected List DHCPRanges = new List(); + public NetworkComponentType myType = NetworkComponentType.none; + public List RouteTable = new List(); + public List DHCPRanges = new List(); protected List DHCPLeases = new List(); protected List IPConnections = new List(); - protected bool isDNSServer = false; - protected bool isDHCPServer = false; + public bool isDNSServer = false; + public bool isDHCPServer = false; public bool CanServeDHCP = false; public bool CanUseDHCP = false; public bool MustUseDHCP = false; @@ -688,7 +688,10 @@ namespace EduNetworkBuilder } return false; } - + public void SetImageFromType() + { + SetImageFromType(myType); + } private void SetImageFromType(NetworkComponentType what) { switch (what) @@ -1515,7 +1518,10 @@ namespace EduNetworkBuilder hostname = ndCopyFrom.hostname; Size = ndCopyFrom.Size; DefaultGW = ndCopyFrom.DefaultGW; - MyImage = new Bitmap(ndCopyFrom.MyImage); + if (ndCopyFrom.MyImage != null) + MyImage = new Bitmap(ndCopyFrom.MyImage); + else + MyImage = null; CanAddNics = ndCopyFrom.CanAddNics; CanServeDHCP = ndCopyFrom.CanServeDHCP; CanUseDHCP = ndCopyFrom.CanUseDHCP; diff --git a/EduNetworkBuilder/NetworkLink.cs b/EduNetworkBuilder/NetworkLink.cs index e148c1a..7df60fc 100644 --- a/EduNetworkBuilder/NetworkLink.cs +++ b/EduNetworkBuilder/NetworkLink.cs @@ -12,8 +12,8 @@ namespace EduNetworkBuilder [Serializable] public class NetworkLink : NetworkComponent { - HostNicID SrcNic; - HostNicID DstNic; + public HostNicID SrcNic; + public HostNicID DstNic; public LinkType theLinkType = LinkType.normal; public bool isVisibleLink = true; //False for wireless. Skip drawing a line if it is there diff --git a/EduNetworkBuilder/Resources/EduNetworkReplay.xml b/EduNetworkBuilder/Resources/EduNetworkReplay.xml index ac2b8ed..382c90c 100644 --- a/EduNetworkBuilder/Resources/EduNetworkReplay.xml +++ b/EduNetworkBuilder/Resources/EduNetworkReplay.xml @@ -16,14 +16,31 @@ 0 - 359 - 229 + 375 + 186 net_switch false + 117 net_switch0 + + + <_ip>0 + <_mask>0 + <_gw>0 + ip + + + 0 + 0 + 100 + none + + + false + false false true false @@ -55,7 +72,20 @@ none false + 127 + + 100 + 102 + pc0 + eth0 + + + 117 + 120 + net_switch0 + port1 + normal true @@ -78,7 +108,20 @@ none false + 128 + + 116 + 118 + pc2 + eth0 + + + 117 + 121 + net_switch0 + port2 + normal true @@ -101,7 +144,20 @@ none false + 129 + + 103 + 105 + pc1 + eth0 + + + 117 + 122 + net_switch0 + port3 + normal true @@ -109,6 +165,482 @@ true + + Level0_Power + + + changecomponent + 109 + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + none + + false + 109 + net_switch0 + + + 70E4C079D244 + + + + <_ip>2130706433 + <_mask>4278190080 + <_gw>0 + ip + + lo0 + + 109 + 110 + net_switch0 + lo0 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + false + false + lo + + 109 + 110 + net_switch0 + lo0 + + -1 + 110 + <_nic_name>lo0 + + + + + + B80FF42F3AFC + + + + <_ip>3232235780 + <_mask>4294967040 + <_gw>0 + ip + + management_interface0 + + 109 + 111 + net_switch0 + management_interface0 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + true + false + management_interface + + 109 + 111 + net_switch0 + management_interface0 + + -1 + 111 + <_nic_name>management_interface0 + + + + + + 7BADA9ED1527 + + + + <_ip>0 + <_mask>0 + <_gw>0 + ip + + port1 + + 109 + 112 + net_switch0 + port1 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + false + false + port + + 109 + 112 + net_switch0 + port1 + + 126 + 112 + <_nic_name>port1 + + + + + + 0299327A45F8 + + + + <_ip>0 + <_mask>0 + <_gw>0 + ip + + port2 + + 109 + 113 + net_switch0 + port2 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + false + false + port + + 109 + 113 + net_switch0 + port2 + + 127 + 113 + <_nic_name>port2 + + + + + + 3DC0D221DD41 + + + + <_ip>0 + <_mask>0 + <_gw>0 + ip + + port3 + + 109 + 114 + net_switch0 + port3 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + false + false + port + + 109 + 114 + net_switch0 + port3 + + 128 + 114 + <_nic_name>port3 + + + + + + 8F9FB28FE232 + + + + <_ip>0 + <_mask>0 + <_gw>0 + ip + + port4 + + 109 + 115 + net_switch0 + port4 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + false + false + port + + 109 + 115 + net_switch0 + port4 + + -1 + 115 + <_nic_name>port4 + + + + + + 8E3CA30D9C6A + + + + <_ip>0 + <_mask>0 + <_gw>0 + ip + + port5 + + 109 + 116 + net_switch0 + port5 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + false + false + port + + 109 + 116 + net_switch0 + port5 + + -1 + 116 + <_nic_name>port5 + + + + + + 7D531A8783CB + + + + <_ip>0 + <_mask>0 + <_gw>0 + ip + + port6 + + 109 + 117 + net_switch0 + port6 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + false + false + port + + 109 + 117 + net_switch0 + port6 + + -1 + 117 + <_nic_name>port6 + + + + + + 57A834AA16A4 + + + + <_ip>0 + <_mask>0 + <_gw>0 + ip + + port7 + + 109 + 118 + net_switch0 + port7 + + + + <_ID>1 + <_Tag>Untagged + 1 + Untagged + + + + + false + false + false + port + + 109 + 118 + net_switch0 + port7 + + -1 + 118 + <_nic_name>port7 + + + + + + + <_ip>3232235777 + <_mask>4294967040 + <_gw>0 + gw + + + 410 + 340 + + 100 + net_switch + + + false + false + false + true + false + false + false + false + + + false + 0 + + + + + ping + 100 + + <_ip>3232236034 + <_mask>4294967040 + <_gw>0 + ip + + + 0 + 0 + + + 0 + 0 + + + 0 + 0 + + none + + + true + true \ No newline at end of file