Пример #1
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);
        }
Пример #2
0
        public static void AddBidConnections(TECBid bid, IEnumerable <TECTypical> typicals, TECCatalogs catalogs, Random rand)
        {
            var typ    = typicals.Where(x => x.Instances.Count > 0).RandomElement(rand);
            var system = typ.Instances.RandomElement(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;

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

            networkSubScope   = system.GetAllSubScope().First(x => typ.GetInstancesFromTypical(networkSubScope).Contains(x));
            hardwiredSubScope = system.GetAllSubScope().First(x => typ.GetInstancesFromTypical(hardwiredSubScope).Contains(x));

            var hardwiredControllerType = catalogs.ControllerTypes.Where(x => new TECProvidedController(x).AvailableIO.Contains((hardwiredSubScope as IConnectable).HardwiredIO)).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 = bid.Controllers.Where(x => x is TECProvidedController y && y.Type == hardwiredControllerType).RandomElement(rand) ??
                                      new TECProvidedController(hardwiredControllerType);

            if (!bid.Controllers.Contains(hardwiredController))
            {
                bid.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 = bid.Controllers.Where(x => x is TECProvidedController y && y.Type == networkControllerType && y.AvailableProtocols.Contains(networkProtocol)).RandomElement(rand) ??
                                    new TECProvidedController(networkControllerType);

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

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

            hardwiredConnection.AssignRandomConnectionProperties(catalogs, rand);
            networkConnection.AssignRandomConnectionProperties(catalogs, rand);
        }
Пример #3
0
        public static TECCatalogs TestCatalogs(Random rand, int maxEachItem = 3)
        {
            TECCatalogs catalogs = new TECCatalogs();

            //Tags
            rand.RepeatAction(() => catalogs.Add(TestTag(rand)), maxEachItem);

            //Associated Costs
            rand.RepeatAction(() => catalogs.Add(TestCost(catalogs, rand, CostType.TEC)), maxEachItem);
            rand.RepeatAction(() => catalogs.Add(TestCost(catalogs, rand, CostType.Electrical)), maxEachItem);

            //Conduit Types
            rand.RepeatAction(() => catalogs.Add(TestElectricalMaterial(catalogs, rand, "Conduit Type")), maxEachItem);

            //ConnectionTypes
            rand.RepeatAction(() => catalogs.Add(TestConnectionType(catalogs, rand)), maxEachItem);

            //Manufacturers
            rand.RepeatAction(() => catalogs.Add(TestManufacturer(rand)), maxEachItem);

            //Protocols
            rand.RepeatAction(() => catalogs.Add(TestProtocol(catalogs, rand)), maxEachItem);

            //Devices
            rand.RepeatAction(() => catalogs.Add(TestDevice(catalogs, rand)), maxEachItem);

            //IO Modules
            rand.RepeatAction(() => catalogs.Add(TestIOModule(catalogs, rand)), maxEachItem);

            //Controller Types
            rand.RepeatAction(() => catalogs.Add(TestControllerType(catalogs, rand)), maxEachItem);

            //Panel Types
            rand.RepeatAction(() => catalogs.Add(TestPanelType(catalogs, rand)), maxEachItem);

            //Valves
            rand.RepeatAction(() => catalogs.Add(TestValve(catalogs, rand)), maxEachItem);

            return(catalogs);
        }