コード例 #1
0
        public void AddList()
        {
            List <TECIO> io = new List <TECIO>
            {
                new TECIO(IOType.AI),
                new TECIO(IOType.AO),
                new TECIO(IOType.DI),
                new TECIO(IOType.DO)
            };
            IOCollection firstColletion   = new IOCollection(io);
            IOCollection secondCollection = new IOCollection(io);

            IOCollection resultCollection = new IOCollection();

            resultCollection.Add(firstColletion.ToList());
            resultCollection.Add(secondCollection.ToList());

            Assert.IsTrue(resultCollection.Contains(IOType.AI));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.AI));

            Assert.IsTrue(resultCollection.Contains(IOType.AO));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.AO));

            Assert.IsTrue(resultCollection.Contains(IOType.DI));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.DI));

            Assert.IsTrue(resultCollection.Contains(IOType.DO));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.DO));
        }
コード例 #2
0
        public void AddType()
        {
            TECIO ai = new TECIO(IOType.AI);

            ai.Quantity = 5;
            TECIO ao = new TECIO(IOType.AO);

            ao.Quantity = 5;
            TECIO di = new TECIO(IOType.DI);

            di.Quantity = 5;
            TECIO ioDO = new TECIO(IOType.DO);

            ioDO.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ai,
                ao,
                di,
                ioDO
            };
            IOCollection collection = new IOCollection(io);

            collection.Add(IOType.AI);

            Assert.AreEqual(6, collection.IONumber(IOType.AI));
        }
コード例 #3
0
        public void SpecificDoesntContainUniversalIO()
        {
            //Ex. 6 AI doesn't contain 5 UI, uses Contains(TECIO)
            TECIO ai = new TECIO(IOType.AI);

            ai.Quantity = 5;
            TECIO ao = new TECIO(IOType.AO);

            ao.Quantity = 5;
            TECIO di = new TECIO(IOType.DI);

            di.Quantity = 5;
            TECIO ioDO = new TECIO(IOType.DO);

            ioDO.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ai,
                ao,
                di,
                ioDO
            };
            IOCollection collection = new IOCollection(io);

            TECIO ui = new TECIO(IOType.UI);

            ui.Quantity = 3;
            TECIO uo = new TECIO(IOType.UO);

            uo.Quantity = 3;

            Assert.IsFalse(collection.Contains(ui));
            Assert.IsFalse(collection.Contains(uo));
        }
コード例 #4
0
        public void RemoveIO()
        {
            TECIO ai = new TECIO(IOType.AI);

            ai.Quantity = 5;
            TECIO ao = new TECIO(IOType.AO);

            ao.Quantity = 5;
            TECIO di = new TECIO(IOType.DI);

            di.Quantity = 5;
            TECIO ioDO = new TECIO(IOType.DO);

            ioDO.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ai,
                ao,
                di,
                ioDO
            };
            IOCollection collection = new IOCollection(io);

            TECIO toRemove = new TECIO(IOType.AI);

            toRemove.Quantity = 2;

            collection.Remove(toRemove);

            Assert.AreEqual(3, collection.IONumber(IOType.AI));
        }
コード例 #5
0
        public void UniversalContainsSpecificIO()
        {
            //Ex. 5 UI contains 3 AI and 3 DI separately, uses Contains(TECIO)
            TECIO ui = new TECIO(IOType.UI);

            ui.Quantity = 5;
            TECIO uo = new TECIO(IOType.UO);

            uo.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ui,
                uo
            };
            IOCollection collection = new IOCollection(io);

            TECIO aiX = new TECIO(IOType.AI);

            aiX.Quantity = 3;
            TECIO aoX = new TECIO(IOType.AO);

            aoX.Quantity = 3;
            TECIO diX = new TECIO(IOType.DI);

            diX.Quantity = 3;
            TECIO ioDOX = new TECIO(IOType.DO);

            ioDOX.Quantity = 3;

            Assert.IsTrue(collection.Contains(aiX));
            Assert.IsTrue(collection.Contains(aoX));
            Assert.IsTrue(collection.Contains(diX));
            Assert.IsTrue(collection.Contains(ioDOX));
        }
コード例 #6
0
        public void RemoveSpecificListFromUnivsersal()
        {
            List <TECIO> io = new List <TECIO>
            {
                new TECIO(IOType.AI),
                new TECIO(IOType.AO),
                new TECIO(IOType.DI),
                new TECIO(IOType.DO)
            };
            List <TECIO> otherIO = new List <TECIO>
            {
                new TECIO(IOType.UI),
                new TECIO(IOType.UI),
                new TECIO(IOType.UI),
                new TECIO(IOType.UI),
                new TECIO(IOType.UO),
                new TECIO(IOType.UO),
                new TECIO(IOType.UO),
                new TECIO(IOType.UO)
            };
            IOCollection firstColletion   = new IOCollection(io);
            IOCollection secondCollection = new IOCollection(otherIO);

            IOCollection resultCollection = new IOCollection(secondCollection);

            resultCollection.Remove(firstColletion.ToList());

            Assert.IsTrue(resultCollection.Contains(IOType.UI));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.UI));

            Assert.IsTrue(resultCollection.Contains(IOType.UO));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.UO));
        }
コード例 #7
0
        internal static bool addRequiredIOModules(TECProvidedController controller)
        {
            //The IO needed by the points connected to the controller
            IOCollection necessaryIO = new IOCollection();
            bool         needsSave   = false;

            foreach (TECHardwiredConnection ssConnect in
                     controller.ChildrenConnections.Where(con => con is TECHardwiredConnection))
            {
                foreach (TECIO io in ssConnect.Child.HardwiredIO.ToList())
                {
                    for (int i = 0; i < io.Quantity; i++)
                    {
                        //The point IO that exists on our controller at the moment.
                        IOCollection totalPointIO = getPointIO(controller);
                        necessaryIO.Add(io.Type);
                        //Check if our io that exists satisfies the IO that we need.
                        if (!totalPointIO.Contains(necessaryIO))
                        {
                            needsSave = true;
                            bool moduleFound = false;
                            //If it doesn't, we need to add an IO module that will satisfy it.
                            foreach (TECIOModule module in controller.Type.IOModules)
                            {
                                //We only need to check for the type of the last IO that we added.
                                if (module.IOCollection.Contains(io.Type) && controller.CanAddModule(module))
                                {
                                    controller.AddModule(module);
                                    moduleFound = true;
                                    break;
                                }
                            }
                            if (!moduleFound)
                            {
                                controller.DisconnectAll();
                                MessageBox.Show(string.Format("The controller type of the controller '{0}' is incompatible with the connected points. Please review the controller's connections.",
                                                              controller.Name));

                                return(true);
                            }
                        }
                    }
                }
            }
            return(needsSave);

            IOCollection getPointIO(TECController con)
            {
                IOCollection pointIOCollection = new IOCollection();

                foreach (TECIO pointIO in controller.IO.ToList().Where(io => (TECIO.PointIO.Contains(io.Type) || TECIO.UniversalIO.Contains(io.Type))))
                {
                    pointIOCollection.Add(pointIO);
                }
                return(pointIOCollection);
            }
        }
コード例 #8
0
        /// <summary>
        /// Returns the io which make up existing network connections on a controller
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        public static IOCollection ExistingNetworkIO(TECController controller)
        {
            IOCollection existingNetwork = new IOCollection();

            foreach (TECNetworkConnection connection in controller.ChildrenConnections.Where(x => x is TECNetworkConnection))
            {
                existingNetwork.Add(connection.NetworkProtocol);
            }
            return(existingNetwork);
        }
コード例 #9
0
        public static int IONumber(this IOCollection collection, IOType type)
        {
            int ioNum = 0;

            foreach (TECIO io in collection.ToList())
            {
                if (io.Type == type)
                {
                    ioNum += io.Quantity;
                }
            }
            return(ioNum);
        }
コード例 #10
0
        public void UnivseralContainsSpecificType()
        {
            //Ex. UI contains AI and DI, uses Contains(IOType)
            List <TECIO> io = new List <TECIO>
            {
                new TECIO(IOType.UI),
                new TECIO(IOType.UO)
            };
            IOCollection collection = new IOCollection(io);

            Assert.IsTrue(collection.Contains(IOType.AI));
            Assert.IsTrue(collection.Contains(IOType.AO));
            Assert.IsTrue(collection.Contains(IOType.DI));
            Assert.IsTrue(collection.Contains(IOType.DO));
        }
コード例 #11
0
        public void SpecificDoesntContainUniversalType()
        {
            //Ex. AI and DI don't contain UI, uses Contains(IOType)
            List <TECIO> io = new List <TECIO>
            {
                new TECIO(IOType.AI),
                new TECIO(IOType.AO),
                new TECIO(IOType.DI),
                new TECIO(IOType.DO)
            };
            IOCollection collection = new IOCollection(io);

            Assert.IsFalse(collection.Contains(IOType.UI));
            Assert.IsFalse(collection.Contains(IOType.UO));
        }
コード例 #12
0
        public void ContainsSameCollection()
        {
            //Ex. 5 AI, 3 DI contains 4 AI, 2 DI. Uses Contains(IOCollection)
            TECIO ai = new TECIO(IOType.AI);

            ai.Quantity = 5;
            TECIO ao = new TECIO(IOType.AO);

            ao.Quantity = 5;
            TECIO di = new TECIO(IOType.DI);

            di.Quantity = 5;
            TECIO ioDO = new TECIO(IOType.DO);

            ioDO.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ai,
                ao,
                di,
                ioDO
            };
            IOCollection collection = new IOCollection(io);

            TECIO aix = new TECIO(IOType.AI);

            aix.Quantity = 3;
            TECIO aox = new TECIO(IOType.AO);

            aox.Quantity = 2;
            TECIO dix = new TECIO(IOType.DI);

            dix.Quantity = 4;
            TECIO ioDOx = new TECIO(IOType.DO);

            ioDOx.Quantity = 5;
            List <TECIO> subjectIo = new List <TECIO>
            {
                aix,
                aox,
                dix,
                ioDOx
            };
            IOCollection subjectCollection = new IOCollection(subjectIo);


            Assert.IsTrue(collection.Contains(subjectCollection));
        }
コード例 #13
0
        public void ContainsSameType()
        {
            //Ex. AI contains AI, uses Contains(IOType)
            List <TECIO> io = new List <TECIO>
            {
                new TECIO(IOType.AI),
                new TECIO(IOType.AO),
                new TECIO(IOType.DI),
                new TECIO(IOType.DO)
            };
            IOCollection collection = new IOCollection(io);

            Assert.IsTrue(collection.Contains(IOType.AI));
            Assert.IsTrue(collection.Contains(IOType.AO));
            Assert.IsTrue(collection.Contains(IOType.DI));
            Assert.IsTrue(collection.Contains(IOType.DO));
        }
コード例 #14
0
        public void RemoveSpecificIOFromUniversal()
        {
            TECIO ui = new TECIO(IOType.UI);

            ui.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ui
            };
            IOCollection collection = new IOCollection(io);

            TECIO toRemove = new TECIO(IOType.DI);

            toRemove.Quantity = 2;

            collection.Remove(toRemove);

            Assert.AreEqual(3, collection.IONumber(IOType.UI));
        }
コード例 #15
0
        public void ContainsSameIO()
        {
            //Ex. 5 AI contains 3 AI, uses Contains(TECIO)
            TECIO ai = new TECIO(IOType.AI);

            ai.Quantity = 5;
            TECIO ao = new TECIO(IOType.AO);

            ao.Quantity = 5;
            TECIO di = new TECIO(IOType.DI);

            di.Quantity = 5;
            TECIO ioDO = new TECIO(IOType.DO);

            ioDO.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ai,
                ao,
                di,
                ioDO
            };
            IOCollection collection = new IOCollection(io);

            TECIO aiX = new TECIO(IOType.AI);

            aiX.Quantity = 3;
            TECIO aoX = new TECIO(IOType.AO);

            aoX.Quantity = 3;
            TECIO diX = new TECIO(IOType.DI);

            diX.Quantity = 3;
            TECIO ioDOX = new TECIO(IOType.DO);

            ioDOX.Quantity = 3;

            Assert.IsTrue(collection.Contains(aiX));
            Assert.IsTrue(collection.Contains(aoX));
            Assert.IsTrue(collection.Contains(diX));
            Assert.IsTrue(collection.Contains(ioDOX));
        }
コード例 #16
0
        public void SpecificDoesntContainUniversalCollection()
        {
            //Ex. 3 AI, 2 DI, 3 AO, 2 DO doesn't contain 2 UI, 2 UO. Uses Contains(IOCollection)
            TECIO ai = new TECIO(IOType.AI);

            ai.Quantity = 5;
            TECIO ao = new TECIO(IOType.AO);

            ao.Quantity = 5;
            TECIO di = new TECIO(IOType.DI);

            di.Quantity = 5;
            TECIO ioDO = new TECIO(IOType.DO);

            ioDO.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ai,
                ao,
                di,
                ioDO
            };
            IOCollection collection = new IOCollection(io);

            TECIO ui = new TECIO(IOType.UI);

            ui.Quantity = 2;
            TECIO uo = new TECIO(IOType.UO);

            uo.Quantity = 2;
            List <TECIO> subjectIO = new List <TECIO>
            {
                ui,
                uo
            };
            IOCollection subjectCollection = new IOCollection(subjectIO);


            Assert.IsFalse(collection.Contains(subjectCollection));
        }
コード例 #17
0
        public void UniversalContainsSpecificCollection()
        {
            //Ex. 5 UI, 5 UO contains 3 AI, 2 DI, 3 AO, 2 DO. Uses Contains(IOCollection)
            TECIO ui = new TECIO(IOType.UI);

            ui.Quantity = 5;
            TECIO uo = new TECIO(IOType.UO);

            uo.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ui,
                uo
            };
            IOCollection collection = new IOCollection(io);

            TECIO ai = new TECIO(IOType.AI);

            ai.Quantity = 3;
            TECIO ao = new TECIO(IOType.AO);

            ao.Quantity = 2;
            TECIO di = new TECIO(IOType.DI);

            di.Quantity = 2;
            TECIO ioDO = new TECIO(IOType.DO);

            ioDO.Quantity = 3;
            List <TECIO> subjectIo = new List <TECIO>
            {
                ai,
                ao,
                di,
                ioDO
            };
            IOCollection subjectCollection = new IOCollection(subjectIo);

            Assert.IsTrue(collection.Contains(subjectCollection));
        }
コード例 #18
0
 /// <summary>
 /// Used to set the abstract IO property.
 /// </summary>
 /// <param name="io"></param>
 public void SetIO(IOCollection io)
 {
     this._io = io;
 }
コード例 #19
0
 public void SetHardwiredIO(IOCollection io)
 {
     this._hardwiredIO = io;
 }