From d5a04c9d770d32aaa206a172a601412438ee2855 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Mon, 7 May 2018 10:37:27 -0500 Subject: [PATCH] Do delete device using DoActions --- EduNetworkBuilder/ActionClass.cs | 21 +++++++++++++++++++++ EduNetworkBuilder/NB.cs | 11 +++++++++++ EduNetworkBuilder/NetworkBuilder.cs | 25 +++++++++++++------------ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/EduNetworkBuilder/ActionClass.cs b/EduNetworkBuilder/ActionClass.cs index a87cd74..73d1a80 100644 --- a/EduNetworkBuilder/ActionClass.cs +++ b/EduNetworkBuilder/ActionClass.cs @@ -120,6 +120,7 @@ namespace EduNetworkBuilder { Network myNet = NB.GetNetwork(); NetworkDevice source = myNet.GetDeviceFromID(SourceID); + NetworkComponent sourceC = myNet.GetComponentFromID(SourceID); switch (Action) { @@ -133,6 +134,26 @@ namespace EduNetworkBuilder } break; case NBAction.deletecomponent: + //Deleting the item is easy, but we also need to delete any links to that item + List NicIDs = new List(); + if (source != null) + { + if (myNet.ItemIsCritical(source.hostname)) + return; //we cannot delete this + NicIDs = source.GetHostNicIDs(); + foreach (HostNicID nicID in NicIDs) + { + myNet.RemoveLinksToNic(nicID); + } + myNet.RemoveComponent(source); + } else if(sourceC != null && sourceC is NetworkLink) + { + if (myNet.ItemIsCritical(sourceC.hostname)) + return; //We cannot remove this link + NetworkLink SourceL = (NetworkLink)sourceC; + SourceL.Destroy(); //Mark both ends as being deleted + myNet.RemoveComponent(SourceL); //Get rid of this link + } break; case NBAction.newdevice: break; diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index c440cb3..7cce2c9 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -1430,6 +1430,17 @@ namespace EduNetworkBuilder AC.DoAction(); + } + public static void DoActionDeleteComponent(int HostID) + { + ActionClass AC = new ActionClass(); + AC.Action = NBAction.deletecomponent; + AC.SourceID = HostID; + + RegisterAction(AC); + + AC.DoAction(); + } #endregion ActionFunctions diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index 56cb2a0..b38aa71 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -1354,18 +1354,19 @@ namespace EduNetworkBuilder private void TryDeleteOneItem(NetworkDevice Item) { //Deleting the item is easy, but we also need to delete any links to that item - List NicIDs = new List(); - if (Item != null) - { - if (myNetwork.ItemIsCritical(Item.hostname)) - return; //we cannot delete this - NicIDs = Item.GetHostNicIDs(); - foreach (HostNicID nicID in NicIDs) - { - myNetwork.RemoveLinksToNic(nicID); - } - myNetwork.RemoveComponent(Item); - } + //List NicIDs = new List(); + //if (Item != null) + //{ + // if (myNetwork.ItemIsCritical(Item.hostname)) + // return; //we cannot delete this + // NicIDs = Item.GetHostNicIDs(); + // foreach (HostNicID nicID in NicIDs) + // { + // myNetwork.RemoveLinksToNic(nicID); + // } + // myNetwork.RemoveComponent(Item); + //} + NB.DoActionDeleteComponent(Item.GetUniqueIdentifier); } private void pbNetworkView_DeleteShape_Click(object sender, EventArgs e)