Exemplo n.º 1
0
        public void GetConnectablesTest()
        {
            TECSystem    system    = new TECSystem();
            TECEquipment equipment = new TECEquipment();

            system.Equipment.Add(equipment);
            TECSubScope first  = new TECSubScope();
            TECSubScope second = new TECSubScope();

            equipment.SubScope.Add(first);
            equipment.SubScope.Add(second);
            TECProvidedController controller = new TECProvidedController(new TECControllerType(new TECManufacturer()));

            system.AddController(controller);

            var connectables = ConnectionHelper.GetConnectables(system, obj => true);

            Assert.IsTrue(connectables.Count == 3);
            Assert.IsTrue(connectables.Contains(first));
            Assert.IsTrue(connectables.Contains(second));
            Assert.IsTrue(connectables.Contains(controller));

            connectables = ConnectionHelper.GetConnectables(system, obj => obj is TECSubScope);

            Assert.IsTrue(connectables.Count == 2);
            Assert.IsTrue(connectables.Contains(first));
            Assert.IsTrue(connectables.Contains(second));
        }
Exemplo n.º 2
0
 public AddControllerVM(TECSystem parentSystem, IEnumerable <TECControllerType> controllerTypes, TECScopeManager scopeManager) : base(scopeManager)
 {
     setup(controllerTypes);
     parent    = parentSystem;
     isTypical = parent.IsTypical;
     add       = controller =>
     {
         parent.AddController(controller);
     };
 }
 public static void AssignRandomSystemProperties(this TECSystem sys, TECCatalogs catalogs, Random rand)
 {
     sys.AssignRandomScopeProperties(catalogs, rand);
     rand.RepeatAction(() => sys.Equipment.Add(ModelCreation.TestEquipment(catalogs, rand)), 5);
     rand.RepeatAction(() => sys.AddController(ModelCreation.TestProvidedController(catalogs, rand)), 5);
     rand.RepeatAction(() => sys.Panels.Add(ModelCreation.TestPanel(catalogs, rand)), 5);
     rand.RepeatAction(() => sys.MiscCosts.Add(ModelCreation.TestMisc(catalogs, rand, CostType.TEC)), 5);
     rand.RepeatAction(() => sys.MiscCosts.Add(ModelCreation.TestMisc(catalogs, rand, CostType.Electrical)), 5);
     rand.RepeatAction(() => sys.ScopeBranches.Add(ModelCreation.TestScopeBranch(rand, 3)), 5);
     rand.RepeatAction(() => ModelCreation.AddSystemConnections(sys, catalogs, rand), 5);
     rand.RepeatAction(() => sys.Panels.RandomElement(rand).Controllers.Add(sys.Controllers.RandomElement(rand)), 2);
 }
        public void AddControllerTest()
        {
            bool      raised = false;
            TECSystem system = new TECSystem();

            system.TECChanged += args =>
            {
                raised = true;
            };

            TECProvidedController controller = new TECProvidedController(new TECControllerType(new TECManufacturer()));

            system.AddController(controller);

            Assert.IsTrue(raised);
            Assert.IsTrue(system.Controllers.Contains(controller));
        }
Exemplo n.º 5
0
        public static void AddSystemConnections(TECSystem system, TECCatalogs catalogs, Random rand)
        {
            var hardwiredDevice = catalogs.Devices.Where(x => x.HardwiredConnectionTypes.Count > 0).RandomElement(rand) ??
                                  new TECDevice(catalogs.ConnectionTypes.RandomElements(rand, false), new List <TECProtocol>(), catalogs.Manufacturers.RandomElement(rand));

            if (!catalogs.Devices.Contains(hardwiredDevice))
            {
                catalogs.Add(hardwiredDevice);
            }
            var networkDevice = catalogs.Devices.Where(x => x.PossibleProtocols.Count > 0 && x != hardwiredDevice).RandomElement(rand) ??
                                new TECDevice(new List <TECConnectionType>(), new List <TECProtocol> {
                catalogs.Protocols.RandomElement(rand)
            }, catalogs.Manufacturers.RandomElement(rand));

            var hardwiredSubScope = new TECSubScope();

            hardwiredSubScope.Devices.Add(hardwiredDevice);
            hardwiredSubScope.AddPoint(TestPoint(rand));

            var hardwiredProtocol = hardwiredSubScope.AvailableProtocols.Where(x => x is TECHardwiredProtocol).RandomElement(rand) as TECHardwiredProtocol;

            var networkSubScope = new TECSubScope();

            networkSubScope.Devices.Add(networkDevice);
            networkSubScope.AddPoint(TestPoint(rand));

            var networkProtocol = networkSubScope.AvailableProtocols.Where(x => x is TECProtocol).RandomElement(rand) as TECProtocol;

            system.Equipment.RandomElement(rand).SubScope.Add(hardwiredSubScope);
            system.Equipment.RandomElement(rand).SubScope.Add(networkSubScope);

            var hardwiredControllerType = catalogs.ControllerTypes.Where(x => new TECProvidedController(x).CanConnect(hardwiredSubScope, hardwiredProtocol)).RandomElement(rand) ??
                                          new TECControllerType(catalogs.Manufacturers.RandomElement(rand));

            if (!catalogs.ControllerTypes.Contains(hardwiredControllerType))
            {
                catalogs.Add(hardwiredControllerType);
                hardwiredControllerType.IO.AddRange((hardwiredSubScope as IConnectable).HardwiredIO.ToList());
            }
            var hardwiredController = system.Controllers.Where(x => x is TECProvidedController y && y.Type == hardwiredControllerType && y.CanConnect(hardwiredSubScope, hardwiredProtocol)).RandomElement(rand) ??
                                      new TECProvidedController(hardwiredControllerType);

            if (!system.Controllers.Contains(hardwiredController))
            {
                system.AddController(hardwiredController);
            }

            var networkControllerType = catalogs.ControllerTypes.Where(x => new TECProvidedController(x).AvailableProtocols.Any(y => y == networkProtocol)).RandomElement(rand) ??
                                        new TECControllerType(catalogs.Manufacturers.RandomElement(rand));

            if (!catalogs.ControllerTypes.Contains(networkControllerType))
            {
                catalogs.Add(networkControllerType);
                networkControllerType.IO.Add(new TECIO(networkProtocol));
            }
            var networkController = system.Controllers.Where(x => x is TECProvidedController y && y.Type == networkControllerType && y.CanConnect(networkSubScope, networkProtocol)).RandomElement(rand) ??
                                    new TECProvidedController(networkControllerType);

            if (!system.Controllers.Contains(networkController))
            {
                system.AddController(networkController);
            }

            var hardwiredConnection = hardwiredController.Connect(hardwiredSubScope, hardwiredProtocol);
            var networkConnection   = networkController.Connect(networkSubScope, networkProtocol);

            hardwiredConnection.AssignRandomConnectionProperties(catalogs, rand);
            networkConnection.AssignRandomConnectionProperties(catalogs, rand);
        }