Get network links to use Actions

This commit is contained in:
Tim Young 2018-05-14 11:06:19 -05:00
parent 8b82150bbe
commit 617c5e2dc3
4 changed files with 41 additions and 8 deletions

View File

@ -146,7 +146,7 @@ namespace EduNetworkBuilder
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 NetworkComponent ChangedComponent = null;
public void DoAction()
{
@ -156,7 +156,21 @@ namespace EduNetworkBuilder
switch (Action)
{
case NBAction.changedevice:
case NBAction.changecomponent:
//This could be a link or a device we are changing.
if(ChangedComponent is NetworkDevice)
{
source.UpdateFromComponent(ChangedComponent); //Copy any changes across
}
else
{ //It is a link. Delete the old, make the new. Mark as linked
if(source != null)
myNet.RemoveComponent(source);
NetworkLink NL = (NetworkLink)ChangedComponent;
myNet.MarkAsLinked(NL.Src, NL.GetUniqueIdentifier);
myNet.MarkAsLinked(NL.Dst, NL.GetUniqueIdentifier);
myNet.AddItem(ChangedComponent);
}
break;
case NBAction.changelocation:
if (source != null)
@ -195,7 +209,7 @@ namespace EduNetworkBuilder
Point TopRight = new Point(TopLeft.X + myNet.itemsize, TopLeft.Y);
Point BottomRight = new Point(TopLeft.X + myNet.itemsize, TopLeft.Y + myNet.itemsize);
Point BottomLeft = new Point(TopLeft.X, TopLeft.Y + myNet.itemsize);
ChangedDevice = null; //if we cannot place it, this = null for reference
ChangedComponent = null; //if we cannot place it, this = null for reference
if (myNet.BlockedByTree(Location)) CanDo = false;
if (myNet.BlockedByTree(TopLeft)) CanDo = false;
if (myNet.BlockedByTree(TopRight)) CanDo = false;
@ -203,7 +217,7 @@ namespace EduNetworkBuilder
if (myNet.BlockedByTree(BottomLeft)) CanDo = false;
if (CanDo)
{
ChangedDevice = (NetworkDevice)myNet.AddItem(newItemType, Location);
ChangedComponent = (NetworkDevice)myNet.AddItem(newItemType, Location);
}
else
{

View File

@ -228,11 +228,17 @@ namespace EduNetworkBuilder
if(EditingLink != null)
{
Net.RemoveComponent(EditingLink); //get rid of the old one and put the new one in
EditingLink = null;
}
NetworkLink newLink = NewLinkFromSettings();
Net.AddItem(newLink);
//Net.AddItem(newLink);
int OldLinkID = -1;
if (EditingLink != null) OldLinkID = EditingLink.GetUniqueIdentifier;
NB.DoActionChangeComponent(OldLinkID,newLink);
if (EditingLink != null)
{
EditingLink = null;
}
Close();
}

View File

@ -104,7 +104,7 @@ namespace EduNetworkBuilder
public enum HowToBreak { PowerOff, EthernetBreak, EthernetCorrupt, EthernetRemoveLink, LockOutSwitch,
WirelessBreakSSID, WirelessBreakKey, DeviceChangeIP, DeviceChangeGW, StaticRouteClear,
StaticRouteCorrupt, VLANChange, VPNChangeEndpoint, VPNChangeKey, BreakDevice }
public enum NBAction { none, newdevice, changelocation, changedevice, deletecomponent,
public enum NBAction { none, newdevice, changelocation, changecomponent, deletecomponent,
ping, traceroute, arp, cleararp, dhcp }
@ -1408,7 +1408,7 @@ namespace EduNetworkBuilder
AC.DoAction();
return AC.ChangedDevice;
return AC.ChangedComponent;
}
public static void DoActionPingDevice(int HostID, NB_IPAddress Destination)
@ -1469,6 +1469,18 @@ namespace EduNetworkBuilder
AC.DoAction();
}
public static void DoActionChangeComponent(int HostID, NetworkComponent Changed)
{
ActionClass AC = new ActionClass();
AC.Action = NBAction.changecomponent;
AC.SourceID = HostID;
AC.ChangedComponent = Changed;
RegisterAction(AC);
AC.DoAction();
}
#endregion ActionFunctions

View File

@ -815,6 +815,7 @@ namespace EduNetworkBuilder
public void RemoveComponent(NetworkComponent tItem)
{
if (tItem == null) return; //Exit early if we are not removing anything
for (int i = NetComponents.Count -1; i >= 0; i--)
{
if (NetComponents[i] == tItem)