public void Controller_RemoveAllConnections()
        {
            TECControllerType type = new TECControllerType(new TECManufacturer());

            type.IO.Add(new TECIO(IOType.AI));
            type.IO.Add(new TECIO(IOType.AI));

            TECController controller         = new TECProvidedController(type);
            TECController childController    = new TECProvidedController(type);
            TECController childestController = new TECProvidedController(type);

            TECProtocol protocol = new TECProtocol(new List <TECConnectionType> {
            });

            type.IO.Add(new TECIO(protocol));

            TECNetworkConnection connection = controller.AddNetworkConnection(protocol);

            connection.AddChild(childController);

            TECNetworkConnection childConnection = childController.AddNetworkConnection(protocol);

            childConnection.AddChild(childestController);

            childController.DisconnectAll();

            Assert.AreEqual(0, childController.ChildrenConnections.Count, "Connection not removed from controller");
            Assert.AreEqual(null, childController.ParentConnection, "Connection not removed from child");
            Assert.AreEqual(null, childestController.ParentConnection, "Connection not removed from childest");
        }
        public void CanConnectToNetworkTest1()
        {
            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>());

            TECDevice compatibleDevice = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>()
            {
                secondProtocol, firstProtocol, fourthProtocol
            }, new TECManufacturer());
            TECSubScope subScope = new TECSubScope();

            subScope.Devices.Add(compatibleDevice);

            TECControllerType type = new TECControllerType(new TECManufacturer());

            type.IO.Add(new TECIO(firstProtocol));
            type.IO.Add(new TECIO(secondProtocol));
            type.IO.Add(new TECIO(thirdProtocol));

            TECProvidedController controller = new TECProvidedController(type);
            TECNetworkConnection  connection = controller.AddNetworkConnection(thirdProtocol);

            Assert.IsFalse(subScope.CanConnectToNetwork(connection));
        }
        public void RemoveNetworkConnectionTest()
        {
            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>());

            TECDevice compatibleDevice = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>()
            {
                secondProtocol, firstProtocol, fourthProtocol
            }, new TECManufacturer());
            TECSubScope subScope = new TECSubScope();

            subScope.Devices.Add(compatibleDevice);

            TECControllerType type = new TECControllerType(new TECManufacturer());

            type.IO.Add(new TECIO(firstProtocol));
            type.IO.Add(new TECIO(secondProtocol));
            type.IO.Add(new TECIO(thirdProtocol));

            TECProvidedController controller = new TECProvidedController(type);

            TECNetworkConnection connection = controller.Connect(subScope, firstProtocol) as TECNetworkConnection;

            controller.RemoveNetworkConnection(connection);

            Assert.IsFalse(connection.Children.Contains(subScope));
            Assert.IsFalse(controller.ChildrenConnections.Contains(connection));
            Assert.IsNull((subScope as IConnectable).GetParentConnection());
        }
Beispiel #4
0
 private static void linkNetworkConnections(IEnumerable <TECController> controllers, IEnumerable <IConnectable> children,
                                            Dictionary <Guid, Guid> guidDictionary = null)
 {
     foreach (TECController controller in controllers)
     {
         foreach (IControllerConnection connection in controller.ChildrenConnections)
         {
             if (connection is TECNetworkConnection)
             {
                 TECNetworkConnection netConnect = connection as TECNetworkConnection;
                 ObservableCollection <IConnectable> controllersToAdd = new ObservableCollection <IConnectable>();
                 foreach (IConnectable child in netConnect.Children)
                 {
                     foreach (IConnectable item in children)
                     {
                         bool isCopy = (guidDictionary != null && guidDictionary[child.Guid] == guidDictionary[item.Guid]);
                         if (child.Guid == item.Guid || isCopy)
                         {
                             controllersToAdd.Add(item);
                             item.SetParentConnection(netConnect);
                         }
                     }
                 }
                 netConnect.Children = controllersToAdd;
             }
         }
     }
 }
        public void RemoveAllChildHardwiredConnectionsTest()
        {
            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>());

            TECDevice compatibleDevice = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>()
            {
                secondProtocol, firstProtocol, fourthProtocol
            }, new TECManufacturer());
            TECSubScope subScope = new TECSubScope();

            subScope.Devices.Add(compatibleDevice);

            TECControllerType type = new TECControllerType(new TECManufacturer());

            type.IO.Add(new TECIO(firstProtocol));
            type.IO.Add(new TECIO(secondProtocol));
            type.IO.Add(new TECIO(thirdProtocol));

            TECProvidedController controller = new TECProvidedController(type);

            TECNetworkConnection connection = controller.Connect(subScope, firstProtocol) as TECNetworkConnection;

            TECDevice   compatibleHardDevice = new TECDevice(new List <TECConnectionType>(), new List <TECProtocol>(), new TECManufacturer());
            TECSubScope hardSubScope         = new TECSubScope();

            hardSubScope.Devices.Add(compatibleDevice);
            TECPoint point = new TECPoint();

            point.Type = IOType.AI;
            hardSubScope.Points.Add(point);

            type.IO.Add(new TECIO(IOType.AI));

            TECHardwiredConnection hardConnection = controller.Connect(hardSubScope, hardSubScope.HardwiredProtocol()) as TECHardwiredConnection;


            TECController parentController = new TECProvidedController(type);

            parentController.Connect(controller, secondProtocol);

            Assert.IsNotNull(controller.ParentConnection);

            controller.RemoveAllChildHardwiredConnections();

            Assert.IsTrue(connection.Children.Contains(subScope));
            Assert.IsTrue(controller.ChildrenConnections.Contains(connection));
            Assert.AreEqual((subScope as IConnectable).GetParentConnection(), connection);

            Assert.IsFalse(controller.ChildrenConnections.Contains(hardConnection));
            Assert.IsNull((hardSubScope as IConnectable).GetParentConnection());

            Assert.IsNotNull(controller.ParentConnection);
        }
        public NetworkConnectionVM(TECNetworkConnection connection, IEnumerable <TECElectricalMaterial> conduitTypes)
        {
            noneConduit      = new TECElectricalMaterial();
            noneConduit.Name = "None";

            Connection = connection;
            Connection.PropertyChanged += handleConnectionChanged;
            ConduitTypes = conduitTypes != null ? new List <TECElectricalMaterial>(conduitTypes) : new List <TECElectricalMaterial>();
            ConduitTypes.Insert(0, noneConduit);
        }
Beispiel #7
0
        public void ConnectTest5()
        {
            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>());

            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
            };


            TECControllerType type   = new TECControllerType(new TECManufacturer());
            TECIOModule       module = new TECIOModule(new TECManufacturer());

            module.IO.Add(new TECIO(firstProtocol));
            type.IOModules.Add(module);

            TECProvidedController controller = new TECProvidedController(type);

            foreach (var subScope in connectables)
            {
                TECNetworkConnection connection = controller.Connect(subScope, firstProtocol) as TECNetworkConnection;

                Assert.IsTrue(connection.Children.Contains(subScope));
                Assert.IsTrue(controller.ChildrenConnections.Contains(connection));
                Assert.IsTrue((subScope as IConnectable).GetParentConnection() == connection);
                Assert.IsTrue(connection.Protocol == firstProtocol);
            }
        }
Beispiel #8
0
        private void testNetworkExecute()
        {
            TECControllerType type = new TECControllerType(bid.Catalogs.Manufacturers[0]);

            type.Name = "Controller Type";
            type.IO.Add(new TECIO(IOType.AI));

            bid.Catalogs.Add(type);

            TECProvidedController controller = new TECProvidedController(type);

            controller.Name        = "Test Server";
            controller.Description = "For testing.";
            controller.IsServer    = true;

            bid.AddController(controller);

            TECProvidedController child = new TECProvidedController(type);

            child.Name = "Child";

            bid.AddController(child);

            TECProvidedController emptyController = new TECProvidedController(type);

            emptyController.Name = "EmptyController";

            bid.AddController(emptyController);

            TECNetworkConnection connection = controller.AddNetworkConnection(bid.Catalogs.Protocols[0]);

            connection.AddChild(child);

            TECTypical   typical = new TECTypical();
            TECEquipment equip   = new TECEquipment();
            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);
            equip.SubScope.Add(ss);
            typical.Equipment.Add(equip);

            bid.Systems.Add(typical);
            typical.AddInstance();
        }
        public void Controller_RemoveSubScope()
        {
            //Arrange
            TECCatalogs   catalogs   = ModelCreation.TestCatalogs(rand);
            TECController controller = ModelCreation.TestProvidedController(catalogs, rand);
            TECSubScope   subScope   = new TECSubScope();
            TECDevice     dev        = catalogs.Devices.First();

            subScope.Devices.Add(dev);

            controller.Connect(subScope, subScope.AvailableProtocols.First(y => controller.AvailableProtocols.Contains(y)));

            //Act
            TECNetworkConnection netConnect = controller.Disconnect(subScope);

            //Assert
            Assert.AreEqual(0, netConnect.Children.Count(), "SubScope not removed from connection");
            Assert.AreEqual(null, subScope.Connection, "Connection not removed from subscope");
        }
        public void AddNetworkConnectionTest1()
        {
            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>());

            TECControllerType type = new TECControllerType(new TECManufacturer());

            type.IO.Add(new TECIO(firstProtocol));
            type.IO.Add(new TECIO(secondProtocol));
            type.IO.Add(new TECIO(thirdProtocol));

            TECProvidedController controller = new TECProvidedController(type);

            TECNetworkConnection connection = controller.AddNetworkConnection(fourthProtocol);

            Assert.IsFalse(controller.ChildrenConnections.Contains(connection));
            Assert.IsNull(connection);
        }
        public void Controller_AddNetworkConnection()
        {
            TECControllerType type = new TECControllerType(new TECManufacturer());

            type.IO.Add(new TECIO(IOType.AI));

            TECController controller      = new TECProvidedController(type);
            TECController childController = new TECProvidedController(type);

            TECProtocol protocol = new TECProtocol(new List <TECConnectionType> {
            });

            type.IO.Add(new TECIO(protocol));

            TECNetworkConnection connection = controller.AddNetworkConnection(protocol);

            connection.AddChild(childController);

            Assert.AreEqual(1, controller.ChildrenConnections.Count, "Connection not added to controller");
            Assert.AreEqual(connection, childController.ParentConnection, "Connection not added to child");
        }
        //Checks every controller in network connections for a two-way connection.
        public void NetworkConnectionLinking()
        {
            List <TECController> allControllers = new List <TECController>();

            foreach (TECTypical typical in bid.Systems)
            {
                foreach (TECSystem instance in typical.Instances)
                {
                    foreach (TECController controller in instance.Controllers)
                    {
                        allControllers.Add(controller);
                    }
                }
            }
            foreach (TECController controller in bid.Controllers)
            {
                allControllers.Add(controller);
            }

            foreach (TECController controller in allControllers)
            {
                foreach (IControllerConnection connection in controller.ChildrenConnections)
                {
                    TECNetworkConnection netConnect = connection as TECNetworkConnection;
                    if (netConnect != null)
                    {
                        Assert.IsTrue(netConnect.ParentController == controller);
                        foreach (TECController childControl in netConnect.Children)
                        {
                            Assert.IsTrue(childControl.ParentConnection == netConnect);
                            Assert.IsTrue(allControllers.Contains(childControl));
                        }
                    }
                }
            }
        }