From 51087c1119fa01ad28b90537de9efd2228537537 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Fri, 4 May 2018 06:35:01 -0500 Subject: [PATCH] Have a move location action --- EduNetworkBuilder/ActionClass.cs | 39 ++++++++++++++++++++++++++++---- EduNetworkBuilder/NB.cs | 22 ++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/EduNetworkBuilder/ActionClass.cs b/EduNetworkBuilder/ActionClass.cs index 1fa0171..cdfc8f4 100644 --- a/EduNetworkBuilder/ActionClass.cs +++ b/EduNetworkBuilder/ActionClass.cs @@ -107,10 +107,41 @@ namespace EduNetworkBuilder public class ActionClass { - public int SourceID = -1; - public int DestID = -1; - public Point Location; - public NetworkComponentType newItemType = NetworkComponentType.none; + public NBAction Action = NBAction.none; + public int SourceID = -1; //used for basically everything + public int DestID = -1; //used for pinging, arp, traceroute + public HostNicID SourceNIC; //used for links + public HostNicID DestNic; //Used for links + public Point Location; //Used when making a new device or moving an old device + public NetworkComponentType newItemType = NetworkComponentType.none; //Making new device public NetworkDevice ChangedDevice = null; + + public void DoAction() + { + Network myNet = NB.GetNetwork(); + NetworkDevice source = myNet.GetDeviceFromID(SourceID); + NetworkDevice dest = myNet.GetDeviceFromID(DestID); + + switch (Action) + { + case NBAction.changedevice: + break; + case NBAction.changelocation: + if (source != null) source.ChangeLocation(Location); + break; + case NBAction.deletecomponent: + break; + case NBAction.newdevice: + break; + case NBAction.dhcp: + break; + case NBAction.arp: + break; + case NBAction.ping: + break; + case NBAction.traceroute: + break; + } + } } } diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index eeea095..3d0d4dc 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -1359,6 +1359,28 @@ namespace EduNetworkBuilder } #endregion + #region ActionFunctions + public static void RegisterAction(ActionClass What) + { + if (What == null) return; + NBSettings mySettings = GetSettings(); + if (mySettings == null) return; + mySettings.RegisterActionDone(What); + } + + public static void DoActionMoveDevice(int HostID, Point Location) + { + //Make an action for the location, register the action, and do the action + ActionClass AC = new ActionClass(); + AC.Action = NBAction.changelocation; + AC.SourceID = HostID; + AC.Location = Location; + + RegisterAction(AC); + + AC.DoAction(); + } + #endregion ActionFunctions } }