public void RemoveInstanceWithGlobalConnectionToController() { TECBid bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand); TECControllerType type = bid.Catalogs.ControllerTypes.RandomElement(rand); TECController controller = new TECProvidedController(type); bid.AddController(controller); TECTypical typical = new TECTypical(); TECController typicalController = new TECProvidedController(type); typical.AddController(typicalController); bid.Systems.Add(typical); TECSystem system = typical.AddInstance(); TECController instanceController = typical.GetInstancesFromTypical(typicalController).First(); Assert.IsTrue(controller.CanConnect(instanceController)); IControllerConnection connection = controller.Connect(instanceController, instanceController.AvailableProtocols.First()); Assert.IsTrue(connection is TECNetworkConnection); typical.Instances.Remove(system); Assert.IsTrue((connection as TECNetworkConnection).Children.Count == 0); }
/// <summary> /// Removes the connectable from controller and parent connection. /// </summary> /// <param name="connectable">Child</param> /// <returns>Parent network connnection if applicable</returns> public TECNetworkConnection Disconnect(IConnectable connectable) { IControllerConnection connectionToRemove = null; foreach (IControllerConnection connection in ChildrenConnections) { if (connection is TECHardwiredConnection hardwiredConnection) { if (hardwiredConnection.Child == connectable) { connectionToRemove = hardwiredConnection; connectable.SetParentConnection(null); break; } } else if (connection is TECNetworkConnection netConnect) { if (netConnect.Children.Contains(connectable)) { netConnect.RemoveChild(connectable); connectable.SetParentConnection(null); return(netConnect); } } } if (connectionToRemove != null) { this.ChildrenConnections.Remove(connectionToRemove); } return(null); }
private void deleteConnectionExecute(IControllerConnection obj) { if (obj is TECHardwiredConnection hardConn) { SelectedController.Disconnect(hardConn.Child); } else if (obj is TECNetworkConnection netConn) { SelectedController.RemoveNetworkConnection(netConn); } }
private CostBatch removeConnection(IControllerConnection connection) { CostBatch deltas = new CostBatch(); foreach (TECConnectionType connectionType in connection.Protocol.ConnectionTypes) { deltas += (WireSummaryVM.RemoveRun(connectionType, connection.Length, connection.IsPlenum)); } if (connection.ConduitType != null) { deltas += (ConduitSummaryVM.RemoveRun(connection.ConduitType, connection.ConduitLength)); } return(deltas); }
private static void linkConnectionToConduitType(IControllerConnection connection, IEnumerable <TECElectricalMaterial> conduitTypes) { if (connection.ConduitType != null) { foreach (TECElectricalMaterial type in conduitTypes) { if (connection.ConduitType.Guid == type.Guid) { connection.ConduitType = type; return; } } } }
public void RemoveInstanceWithGlobalConnectionToSubScope() { TECBid bid = new TECBid(); bid.Catalogs = ModelCreation.TestCatalogs(rand); TECController controller = ModelCreation.TestProvidedController(bid.Catalogs, rand); bid.AddController(controller); TECTypical typical = new TECTypical(); TECEquipment equipment = new TECEquipment(); TECSubScope subScope = new TECSubScope(); TECDevice device = null; foreach (TECDevice item in bid.Catalogs.Devices) { foreach (TECProtocol prot in item.PossibleProtocols) { if (controller.AvailableProtocols.Contains(prot)) { device = item; break; } } if (device != null) { break; } } if (device == null) { throw new NullReferenceException("Device is Null"); } subScope.Devices.Add(device); equipment.SubScope.Add(subScope); typical.Equipment.Add(equipment); bid.Systems.Add(typical); TECSystem system = typical.AddInstance(); TECSubScope instanceSubScope = typical.GetInstancesFromTypical(subScope).First(x => x.AvailableProtocols.Any(y => y is TECProtocol && controller.AvailableProtocols.Contains(y))); IControllerConnection connection = controller.Connect(instanceSubScope, instanceSubScope.AvailableProtocols.First(y => controller.AvailableProtocols.Contains(y))); Assert.IsTrue(connection is TECNetworkConnection); typical.Instances.Remove(system); Assert.IsTrue((connection as TECNetworkConnection).Children.Count == 0); }
private bool connectionContainsItem(IControllerConnection connection, IConnectable item) { if (connection is TECHardwiredConnection hardConnect) { return(hardConnect.Child == item); } else if (connection is TECNetworkConnection netConnect) { return(netConnect.Children.Contains(item)); } else { return(false); } }
private bool addCanExecute() { IControllerConnection connection = parent.Connection; if (connection == null) { return(true); } else { TECIO proposedIO = new TECIO(ToAdd.Type); proposedIO.Quantity = ToAdd.Quantity; bool containsIO = connection.ParentController.AvailableIO.Contains(proposedIO); bool isNetworkIO = connection is TECNetworkConnection netConnect; return(containsIO || isNetworkIO); } }
public void AddConnection() { //Arrange TECControllerType controllerType = new TECControllerType(bid.Catalogs.Manufacturers[0]); bid.Catalogs.Add(controllerType); TECTypical typical = new TECTypical(); bid.Systems.Add(typical); TECController controller = new TECProvidedController(controllerType); typical.AddController(controller); TECEquipment typEquip = new TECEquipment(); typical.Equipment.Add(typEquip); TECSubScope typSS = new TECSubScope(); typEquip.SubScope.Add(typSS); ObservableCollection <TECConnectionType> connectionTypes = new ObservableCollection <TECConnectionType>(); connectionTypes.Add(bid.Catalogs.ConnectionTypes[0]); TECDevice dev = new TECDevice(connectionTypes, new List <TECProtocol>(), bid.Catalogs.Manufacturers[0]); bid.Catalogs.Add(dev); typSS.Devices.Add(dev); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act IControllerConnection connection = controller.Connect(typSS, (typSS as IConnectable).AvailableProtocols.First()); connection.Length = 50; connection.ConduitLength = 50; connection.ConduitType = bid.Catalogs.ConduitTypes[0]; TECSystem instance = typical.AddInstance(); TECSubScope instanceSubScope = instance.GetAllSubScope()[0]; //Assert AssertMaterialVMMatchesCostBatch(matVM, connection.CostBatch); }
void IConnectable.SetParentConnection(IControllerConnection connection) { if (connection == null) { ParentConnection = null; raisePropertyChanged("ParentConnection"); } else if (connection is TECNetworkConnection networkConnection) { ParentConnection = networkConnection; raisePropertyChanged("ParentConnection"); } else { throw new Exception("Controller must have network parent connection."); } }
private CostBatch addConnection(IControllerConnection connection) { if (!connection.IsTypical) { CostBatch deltas = new CostBatch(); foreach (TECConnectionType connectionType in connection.Protocol.ConnectionTypes) { deltas += (WireSummaryVM.AddRun(connectionType, connection.Length, connection.IsPlenum)); } if (connection.ConduitType != null) { deltas += (ConduitSummaryVM.AddRun(connection.ConduitType, connection.ConduitLength)); } return(deltas); } else { return(new CostBatch()); } }
public void AddTypicalSubScopeConnectionToController() { //Arrange TECControllerType controllerType = new TECControllerType(bid.Catalogs.Manufacturers[0]); bid.Catalogs.Add(controllerType); TECController controller = new TECProvidedController(controllerType); bid.AddController(controller); TECTypical typical = new TECTypical(); TECEquipment equip = new TECEquipment(); typical.Equipment.Add(equip); TECSubScope ss = new TECSubScope(); equip.SubScope.Add(ss); TECDevice dev = bid.Catalogs.Devices[0]; ss.Devices.Add(dev); bid.Systems.Add(typical); MaterialSummaryVM matVM = new MaterialSummaryVM(bid, cw); //Act IControllerConnection connection = controller.Connect(ss, (ss as IConnectable).AvailableProtocols.First(y => y is TECHardwiredProtocol)); connection.Length = 100; connection.ConduitLength = 100; connection.ConduitType = bid.Catalogs.ConduitTypes[0]; AssertMaterialVMMatchesCostBatch(matVM, connection.CostBatch); }
public void RemoveDeviceFromConnectedNetwork() { TECControllerType type = new TECControllerType(new TECManufacturer()); TECProtocol protocol = new TECProtocol(new List <TECConnectionType>()); type.IO.Add(new TECIO(protocol)); TECProvidedController controller = new TECProvidedController(type); TECDevice device = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol> { protocol }, new TECManufacturer()); TECSubScope subScope = new TECSubScope(); subScope.Devices.Add(device); IControllerConnection connection = controller.Connect(subScope, protocol); subScope.RemoveDevice(device); Assert.IsNull((subScope as IConnectable).GetParentConnection()); Assert.IsTrue(controller.ChildrenConnections.Contains(connection)); }
public void SetParentConnection(IControllerConnection connection) { throw new NotImplementedException(); }
private void addTypicalExecute() { TECTypical typical = new TECTypical(); typical.Name = "test"; TECEquipment equipment = new TECEquipment(); equipment.Name = "test equipment"; TECSubScope ss = new TECSubScope(); ss.Name = "Test Subscope"; ss.AddDevice(bid.Catalogs.Devices[0]); TECPoint point = new TECPoint(); point.Type = IOType.AI; point.Quantity = 1; ss.AddPoint(point); equipment.SubScope.Add(ss); typical.Equipment.Add(equipment); TECSubScope connected = new TECSubScope(); connected.Name = "Connected"; connected.AddDevice(bid.Catalogs.Devices[0]); TECPoint point2 = new TECPoint(); point2.Type = IOType.AI; point2.Quantity = 1; connected.AddPoint(point2); equipment.SubScope.Add(connected); TECSubScope toConnect = new TECSubScope(); toConnect.Name = "To Connect"; toConnect.AddDevice(bid.Catalogs.Devices[0]); TECPoint point3 = new TECPoint(); point3.Type = IOType.AI; point3.Quantity = 1; toConnect.AddPoint(point3); equipment.SubScope.Add(toConnect); TECControllerType controllerType = new TECControllerType(new TECManufacturer()); controllerType.IOModules.Add(bid.Catalogs.IOModules[0]); TECIO io = new TECIO(IOType.AI); io.Quantity = 10; controllerType.IO.Add(io); bid.Catalogs.IOModules[0].IO.Add(io); controllerType.Name = "Test Type"; TECProvidedController controller = new TECProvidedController(controllerType); controller.IOModules.Add(bid.Catalogs.IOModules[0]); controller.Name = "Test Controller"; typical.AddController(controller); TECProvidedController otherController = new TECProvidedController(controllerType); otherController.Name = "Other Controller"; typical.AddController(otherController); IControllerConnection connection = controller.Connect(connected, (connected as IConnectable).AvailableProtocols.First()); connection.Length = 10; connection.ConduitLength = 20; connection.ConduitType = bid.Catalogs.ConduitTypes[1]; TECPanelType panelType = new TECPanelType(new TECManufacturer()); panelType.Name = "test type"; TECPanel panel = new TECPanel(panelType); panel.Name = "Test Panel"; typical.Panels.Add(panel); TECMisc misc = new TECMisc(CostType.TEC); misc.Name = "test Misc"; typical.MiscCosts.Add(misc); bid.Systems.Add(typical); typical.AddInstance(); }
public static IControllerConnection FindConnectionInController(TECController controller, IControllerConnection reference) { foreach (IControllerConnection connection in controller.ChildrenConnections) { if (connection.Guid == reference.Guid) { return(connection); } } return(null); }
public static TECBid CreateTestBid() { TECBid bid = new TECBid(); //Bid Info bid.Name = "Bid Name"; bid.BidNumber = "1701-117"; bid.DueDate = DateTime.Now; bid.Salesperson = "Mrs. Test"; bid.Estimator = "Mr. Test"; //Bid Objects bid.ExtraLabor = CreateTestExtraLabor(bid.Guid); bid.Parameters = CreateTestParameters(bid.Guid); bid.Catalogs = CreateTestCatalogs(); //Internal Notes TECInternalNote internalNote = new TECInternalNote(); internalNote.Label = "Test internal"; internalNote.Body = "Test body"; bid.InternalNotes.Add(internalNote); //Locations var cellar = new TECLocation(); cellar.Name = "Cellar"; cellar.Label = "C"; var location1 = new TECLocation(); location1.Name = "1st Floor"; location1.Label = "1"; var location2 = new TECLocation(); location2.Name = "2nd Floor"; location2.Label = "2"; var location3 = new TECLocation(); location3.Name = "3rd Floor"; location3.Label = "3"; bid.Locations.Add(cellar); bid.Locations.Add(location1); bid.Locations.Add(location2); bid.Locations.Add(location3); //Scope Branches var branch1 = new TECScopeBranch(false); branch1.Label = "Branch 1"; var branch2 = new TECScopeBranch(false); branch2.Label = "Branch 2"; var branch3 = new TECScopeBranch(false); branch3.Label = "Branch 3"; bid.ScopeTree.Add(branch1); branch1.Branches.Add(branch2); branch2.Branches.Add(branch3); //Notes var note1 = new TECLabeled(); note1.Label = "Note 1"; bid.Notes.Add(note1); //Exclusions var exclusion1 = new TECLabeled(); exclusion1.Label = "Exclusion 1"; bid.Exclusions.Add(exclusion1); //Controller TECController expectedController = new TECProvidedController(Guid.NewGuid(), bid.Catalogs.ControllerTypes[0], false); expectedController.Name = "Test Controller"; expectedController.Description = "Test description"; bid.AddController(expectedController); //Misc Cost TECMisc cost = new TECMisc(CostType.TEC, false); cost.Name = "Test Cost"; cost.Cost = 69.69; cost.Quantity = 69; bid.MiscCosts.Add(cost); //Misc wiring TECMisc wiring = new TECMisc(CostType.Electrical, false); wiring.Name = "Test Wiring"; wiring.Cost = 69.69; wiring.Quantity = 69; bid.MiscCosts.Add(wiring); //Panels TECPanel panel = new TECPanel(bid.Catalogs.PanelTypes[0], false); panel.Name = "Test Panel"; panel.Controllers.Add(expectedController); panel.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); panel.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); bid.Panels.Add(panel); //Systems var system1 = CreateTestTypical(bid.Catalogs); system1.Name = "System 1"; system1.Description = "Locations all the way"; system1.Location = cellar; var system2 = CreateTestTypical(bid.Catalogs); system2.Name = "System 2"; system2.Description = "Description 2"; var system3 = CreateTestTypical(bid.Catalogs); system3.Name = "System 3"; system3.Description = ""; bid.Systems.Add(system1); bid.Systems.Add(system2); bid.Systems.Add(system3); system1.AddInstance(bid); system2.AddInstance(bid); system3.AddInstance(bid); system1.AddInstance(bid); system2.AddInstance(bid); system3.AddInstance(bid); //Equipment var equipment1 = new TECEquipment(true); equipment1.Name = "Equipment 1"; equipment1.Description = "Description 1"; var equipment2 = new TECEquipment(true); equipment2.Name = "Equipment 2"; equipment2.Description = "Description 2"; system1.Equipment.Add(equipment1); system3.Equipment.Add(equipment2); //SubScope var subScope1 = new TECSubScope(true); subScope1.Name = "SubScope 1"; subScope1.Description = "Description 1"; subScope1.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); subScope1.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); subScope1.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); var subScope2 = new TECSubScope(true); subScope2.Name = "Empty SubScope"; subScope2.Description = "Description 2"; subScope2.AssociatedCosts.Add(bid.Catalogs.AssociatedCosts[0]); equipment1.SubScope.Add(subScope1); equipment2.SubScope.Add(subScope2); //Points var point1 = new TECPoint(true); point1.Label = "Point 1"; point1.Type = IOType.AI; point1.Quantity = 2; subScope1.Points.Add(point1); var point2 = new TECPoint(true); point2.Label = "Point 2"; point2.Type = IOType.AI; point2.Quantity = 2; subScope2.Points.Add(point2); //Devices subScope1.Devices.Add(bid.Catalogs.Devices[0]); //Connections TECSubScope instanceSubScope = system1.GetInstancesFromTypical(subScope1)[0]; IControllerConnection testConnection = expectedController.Connect(instanceSubScope, (instanceSubScope as IConnectable).AvailableProtocols.First()); testConnection.ConduitType = bid.Catalogs.ConduitTypes[0]; testConnection.Length = 42; AssignAllSecondaryProperties(bid); TECTypical noLocation = new TECTypical(); noLocation.Name = "No Location"; noLocation.Equipment.Add(new TECEquipment(true)); noLocation.Equipment[0].SubScope.Add(new TECSubScope(true)); bid.Systems.Add(noLocation); return(bid); }
private static void linkConnectionToCatalogs(IControllerConnection connection, TECCatalogs catalogs) { linkConnectionToConduitType(connection, catalogs.ConduitTypes); }
bool IConnectable.CanSetParentConnection(IControllerConnection connection) { return(((IConnectable)this).AvailableProtocols.Contains(connection.Protocol)); }
void IConnectable.SetParentConnection(IControllerConnection connection) { Connection = connection; raisePropertyChanged("Connection"); }
bool IConnectable.CanSetParentConnection(IControllerConnection connection) { return(connection is TECNetworkConnection); }
private bool canDeleteConnection(IControllerConnection arg) { return(arg != null && SelectedController != null); }
public void ConnectTest6() { TECProtocol firstProtocol = new TECProtocol(new List <TECConnectionType>()); TECProtocol secondProtocol = new TECProtocol(new List <TECConnectionType>()); TECProtocol thirdProtocol = new TECProtocol(new List <TECConnectionType>()); TECProtocol fourthProtocol = new TECProtocol(new List <TECConnectionType>()); TECConnectionType connectionType = new TECConnectionType(); TECDevice hardDevice = new TECDevice(new List <TECConnectionType> { connectionType }, new List <TECProtocol>(), new TECManufacturer()); TECSubScope hSubScope1 = new TECSubScope(); hSubScope1.Devices.Add(hardDevice); hSubScope1.Points.Add(new TECPoint { Type = IOType.AI }); TECSubScope hSubScope2 = new TECSubScope(); hSubScope2.Devices.Add(hardDevice); hSubScope2.Points.Add(new TECPoint { Type = IOType.AI }); TECSubScope hSubScope3 = new TECSubScope(); hSubScope3.Devices.Add(hardDevice); hSubScope3.Points.Add(new TECPoint { Type = IOType.AI }); TECSubScope hSubScope4 = new TECSubScope(); hSubScope4.Devices.Add(hardDevice); hSubScope4.Points.Add(new TECPoint { Type = IOType.AI }); TECSubScope hSubScope5 = new TECSubScope(); hSubScope5.Devices.Add(hardDevice); hSubScope5.Points.Add(new TECPoint { Type = IOType.AI }); TECDevice compatibleDevice = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>() { secondProtocol, firstProtocol, fourthProtocol }, new TECManufacturer()); TECSubScope subScope1 = new TECSubScope(); subScope1.Devices.Add(compatibleDevice); TECSubScope subScope2 = new TECSubScope(); subScope2.Devices.Add(compatibleDevice); TECSubScope subScope3 = new TECSubScope(); subScope3.Devices.Add(compatibleDevice); TECSubScope subScope4 = new TECSubScope(); subScope4.Devices.Add(compatibleDevice); List <IConnectable> connectables = new List <IConnectable> { subScope1, subScope2, subScope3, subScope4, hSubScope1, hSubScope2, hSubScope3, hSubScope4, hSubScope5 }; TECControllerType type = new TECControllerType(new TECManufacturer()); TECIOModule module = new TECIOModule(new TECManufacturer()); module.IO.Add(new TECIO(firstProtocol)); TECIOModule hModule = new TECIOModule(new TECManufacturer()); hModule.IO.Add(new TECIO(IOType.AI) { Quantity = 2 }); type.IOModules.Add(module); type.IOModules.Add(hModule); type.IOModules.Add(hModule); type.IOModules.Add(hModule); TECProvidedController controller = new TECProvidedController(type); foreach (var subScope in connectables) { IProtocol protocol = subScope.HardwiredProtocol() as IProtocol ?? firstProtocol; IControllerConnection connection = controller.Connect(subScope, protocol); bool containsChild = connection is TECNetworkConnection netConnect? netConnect.Children.Contains(subScope) : (connection as TECHardwiredConnection).Child == subScope; Assert.IsTrue(containsChild); Assert.IsTrue(controller.ChildrenConnections.Contains(connection)); Assert.IsTrue((subScope as IConnectable).GetParentConnection() == connection); Assert.AreEqual(connection.Protocol, protocol); } }