From f2b846465ea56799909b588b8299bc6ecffa4740 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Fri, 18 May 2018 08:23:03 -0500 Subject: [PATCH] replace as DoAction --- EduNetworkBuilder/ActionClass.cs | 32 ++++++++++++++++++++--- EduNetworkBuilder/NetworkBuilder.cs | 39 ++++++++++++++++------------- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/EduNetworkBuilder/ActionClass.cs b/EduNetworkBuilder/ActionClass.cs index c6617a4..a4fa856 100644 --- a/EduNetworkBuilder/ActionClass.cs +++ b/EduNetworkBuilder/ActionClass.cs @@ -168,7 +168,7 @@ namespace EduNetworkBuilder Network myNet = NB.GetNetwork(); NetworkDevice source = myNet.GetDeviceFromID(SourceID); NetworkComponent sourceC = myNet.GetComponentFromID(SourceID); - + NetworkLink sourceNL; switch (Action) { case NBAction.changecomponent: @@ -182,9 +182,9 @@ namespace EduNetworkBuilder { //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); + sourceNL = (NetworkLink)ChangedComponent; + myNet.MarkAsLinked(sourceNL.Src, sourceNL.GetUniqueIdentifier); + myNet.MarkAsLinked(sourceNL.Dst, sourceNL.GetUniqueIdentifier); myNet.AddItem(ChangedComponent); } break; @@ -261,6 +261,30 @@ namespace EduNetworkBuilder source.TracerouteFromHere(Destination); break; case NBAction.replace: + if(sourceC is NetworkDevice) + { + source.ClearIPs(); //reset the device + source.IsBurned = false; //If it had been burned before, it is no longer burned + source.PowerOff = true; + source.BadSprayCount = 0; + //Mark the replace test as "done" + myNet.RegisterDeviceReset(source.hostname); //replacing something powers it off + + myNet.RegisterDeviceReplaced(source.hostname); //replace it. + } + else if (sourceC is NetworkLink) + { + sourceNL = (NetworkLink)sourceC; + + if (sourceNL.theLinkType != LinkType.wireless) + { + HostNicID sourceID = sourceNL.Src; + HostNicID destID = sourceNL.Dst; + myNet.RemoveComponent(sourceNL); + NetworkLink nNL = new NetworkLink(sourceID, destID, LinkType.normal); + myNet.AddItem(nNL); + } + } break; case NBAction.replaceUPS: myNet.RegisterUPSAdded(source.hostname); diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index 959035d..2e3eca4 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -1194,16 +1194,18 @@ namespace EduNetworkBuilder { if (ItemClickedOn != null) { - if (ItemClickedOn == null) return; - ItemClickedOn.ClearIPs(); //reset the device - ItemClickedOn.IsBurned = false; //If it had been burned before, it is no longer burned - ItemClickedOn.PowerOff = true; - ItemClickedOn.BadSprayCount = 0; - NB.DoActionChangeComponent(ItemClickedOn); - //Mark the replace test as "done" - myNetwork.RegisterDeviceReset(ItemClickedOn.hostname); //replacing something powers it off - myNetwork.RegisterDeviceReplaced(ItemClickedOn.hostname); //replace it. + //ItemClickedOn.ClearIPs(); //reset the device + //ItemClickedOn.IsBurned = false; //If it had been burned before, it is no longer burned + //ItemClickedOn.PowerOff = true; + //ItemClickedOn.BadSprayCount = 0; + //NB.DoActionChangeComponent(ItemClickedOn); + ////Mark the replace test as "done" + //myNetwork.RegisterDeviceReset(ItemClickedOn.hostname); //replacing something powers it off + + //myNetwork.RegisterDeviceReplaced(ItemClickedOn.hostname); //replace it. + NB.DoActionReplaceDevice(ItemClickedOn.GetUniqueIdentifier); + UpdateVisuals(); } } @@ -1298,15 +1300,16 @@ namespace EduNetworkBuilder if (thing.Tag != null) { NetworkLink NL = (NetworkLink)thing.Tag; - //This may delete the old link and make a new one - if (NL.theLinkType != LinkType.wireless) - { - HostNicID source = NL.Src; - HostNicID dest = NL.Dst; - myNetwork.RemoveComponent(NL); - NetworkLink nNL = new NetworkLink(source, dest, LinkType.normal); - myNetwork.AddItem(nNL); - } + ////This may delete the old link and make a new one + //if (NL.theLinkType != LinkType.wireless) + //{ + // HostNicID source = NL.Src; + // HostNicID dest = NL.Dst; + // myNetwork.RemoveComponent(NL); + // NetworkLink nNL = new NetworkLink(source, dest, LinkType.normal); + // myNetwork.AddItem(nNL); + //} + NB.DoActionReplaceDevice(NL.GetUniqueIdentifier); } myNetwork.TestForCompletion(true); pbNetworkView.Update();