Пример #1
0
        public static IOCollection ToIOCollection(this IEnumerable <TECIOModule> modules)
        {
            IOCollection io = new IOCollection();

            modules.ForEach(mod => io.Add(mod.IO));
            return(io);
        }
Пример #2
0
        public static IOCollection operator +(IOCollection left, IOCollection right)
        {
            IOCollection newCollection = new IOCollection(left);

            newCollection.Add(right.ToList());
            return(newCollection);
        }
Пример #3
0
        public static IOCollection ToIOCollection(this IEnumerable <TECPoint> points)
        {
            IOCollection collection = new IOCollection();

            foreach (TECPoint point in points)
            {
                TECIO toAdd = new TECIO(point.Type);
                toAdd.Quantity = point.Quantity;
                collection.Add(toAdd);
            }
            return(collection);
        }
        public bool CanChangeType(TECControllerType newType)
        {
            if (newType == null)
            {
                return(false);
            }
            TECProvidedController possibleController = new TECProvidedController(newType);
            IOCollection          necessaryIO        = this.UsedIO;
            IOCollection          possibleIO         = possibleController.getPotentialIO() + possibleController.AvailableIO;

            return(possibleIO.Contains(necessaryIO));
        }
        /// <summary>
        /// Gets nessessary modules from potential modules to handle io.
        /// </summary>
        /// <param name="io"></param>
        /// <returns>Nessessary modules. Returns empty list if no collection of modules exists.</returns>
        private List <TECIOModule> getModulesForIO(IOCollection io)
        {
            IOCollection nessessaryIO        = new IOCollection(io);
            IOCollection relevantAvailableIO = (io | base.AvailableIO);

            if (!nessessaryIO.Remove(relevantAvailableIO))
            {
                throw new Exception("NessessaryIO collection is having trouble removing subset of itself.");
            }

            List <TECIOModule> potentialModules = getPotentialModules();

            //Check that any singular module can cover the nessessary io
            foreach (TECIOModule module in potentialModules)
            {
                if (module.IOCollection.Contains(io))
                {
                    return new List <TECIOModule>()
                           {
                               module
                           }
                }
                ;
            }

            //List of modules to return
            List <TECIOModule> returnModules = new List <TECIOModule>();

            foreach (TECIO type in io.ToList())
            {
                TECIO singularIO = new TECIO(type);
                singularIO.Quantity = 1;

                //Add the modules that contains the IOType we're checking
                foreach (TECIOModule module in potentialModules)
                {
                    if (module.IOCollection.Contains(singularIO))
                    {
                        returnModules.Add(module);
                        //If return modules satisfies our IO, return them
                        if (returnModules.ToIOCollection().Contains(io))
                        {
                            return(returnModules);
                        }
                    }
                }
            }

            return(new List <TECIOModule>());
        }
Пример #6
0
        public bool Contains(IEnumerable <TECIO> io)
        {
            //Normalize collections
            IOCollection thisCollection = new IOCollection(this);
            IOCollection ioCollection   = new IOCollection(io);

            foreach (TECIO ioToCheck in ioCollection.ToList())
            {
                if (!thisCollection.Remove(ioToCheck))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #7
0
        /// <summary>
        /// Gives the intersection of the left and right IOCollections
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns>The intersection</returns>
        public static IOCollection operator |(IOCollection left, IOCollection right)
        {
            IOCollection intersection = new IOCollection();

            foreach (TECIO leftIO in left.ToList())
            {
                foreach (TECIO rightIO in right.ToList())
                {
                    if (leftIO.Type == rightIO.Type && leftIO.Protocol == rightIO.Protocol)
                    {
                        intersection.Add(leftIO.Quantity < rightIO.Quantity ? leftIO : rightIO);
                    }
                }
            }
            return(intersection);
        }
        private IOCollection getInitialIO()
        {
            IOCollection io = new IOCollection();
            TECIO        ui = new TECIO(IOType.UI);

            ui.Quantity = 100;
            io.Add(ui);
            TECIO uo = new TECIO(IOType.UO);

            uo.Quantity = 100;
            io.Add(uo);
            foreach (TECProtocol prot in this.catalogs.Protocols)
            {
                io.Add(prot);
            }
            return(io);
        }
        /// <summary>
        /// Returns non actualized but potential IO. All IO compatible with the controller type that doesn't exist on this controller.
        /// </summary>
        private IOCollection getPotentialIO()
        {
            IOCollection potentialIO = new IOCollection();

            foreach (TECIOModule module in this.Type.IOModules)
            {
                potentialIO.Add(module.IO);
            }
            foreach (TECIOModule module in this.IOModules)
            {
                if (!potentialIO.Remove(module.IO))
                {
                    throw new Exception("Controller has incompatible IO with its controller type.");
                }
            }
            return(potentialIO);
        }
        public override IControllerConnection Connect(IConnectable connectable, IProtocol protocol)
        {
            IOCollection connectionIO = protocol is TECProtocol ? new IOCollection(protocol as TECProtocol) : new IOCollection(connectable.HardwiredIO);

            if (this.ChildrenConnections.OfType <TECNetworkConnection>().Any(x => x.Protocol == protocol))
            {
                return(base.Connect(connectable, protocol));
            }
            else if (base.AvailableIO.Contains(connectionIO))
            {
                return(base.Connect(connectable, protocol));
            }
            else
            {
                var modulesToAdd = getModulesForIO(connectionIO);
                if (modulesToAdd.Count == 0)
                {
                    return(null);
                }
                modulesToAdd.ForEach(x => this.AddModule(x));
                return(base.Connect(connectable, protocol));;
            }
        }
Пример #11
0
 public bool Remove(IOCollection ioCollection)
 {
     return(this.Remove(ioCollection.ToList()));
 }
Пример #12
0
 public bool Contains(IOCollection io)
 {
     return(this.Contains(io.ToList()));
 }
Пример #13
0
 public IOCollection(IOCollection collection) : this()
 {
     Add(collection.ToList());
 }
 /// <summary>
 /// Copy constructor for TECFBOController
 /// </summary>
 /// <param name="controllerSource"></param>
 /// <param name="guidDictionary"></param>
 public TECFBOController(TECFBOController controllerSource, Dictionary <Guid, Guid> guidDictionary = null) : base(controllerSource, guidDictionary)
 {
     this.catalogs = controllerSource.catalogs;
     this.IO       = getInitialIO();
     this.Points.CollectionChanged += pointsCollectionChanged;
 }
 /// <summary>
 /// General constructor for TECFBOController.
 /// </summary>
 /// <param name="guid"></param>
 public TECFBOController(Guid guid, TECCatalogs catalogs) : base(guid)
 {
     this.catalogs = catalogs;
     this.IO       = getInitialIO();
     this.Points.CollectionChanged += pointsCollectionChanged;
 }