Do delete device using DoActions

This commit is contained in:
Tim Young 2018-05-07 10:37:27 -05:00
parent 06ca7c59f3
commit d5a04c9d77
3 changed files with 45 additions and 12 deletions

View File

@ -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<HostNicID> NicIDs = new List<HostNicID>();
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;

View File

@ -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

View File

@ -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<HostNicID> NicIDs = new List<HostNicID>();
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<HostNicID> NicIDs = new List<HostNicID>();
//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)