コード例 #1
0
 public void Add(TECIO io)
 {
     if (io.Type == IOType.Protocol)
     {
         if (protocolDictionary.ContainsKey(io.Protocol))
         {
             protocolDictionary[io.Protocol].Quantity += io.Quantity;
         }
         else
         {
             protocolDictionary.Add(io.Protocol, new TECIO(io));
         }
     }
     else
     {
         if (ioDictionary.ContainsKey(io.Type))
         {
             ioDictionary[io.Type].Quantity += io.Quantity;
         }
         else
         {
             ioDictionary.Add(io.Type, new TECIO(io));
         }
     }
 }
コード例 #2
0
 public static IOCollection ToIOCollection(this TECIO io)
 {
     return(new IOCollection(new List <TECIO>()
     {
         io
     }));
 }
コード例 #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);
        }
コード例 #4
0
 public TECControllerType(TECControllerType typeSource) : this(typeSource.Manufacturer)
 {
     copyPropertiesFromHardware(typeSource);
     foreach (TECIO io in typeSource.IO)
     {
         TECIO ioToAdd = new TECIO(io);
         IO.Add(new TECIO(io));
     }
     foreach (TECIOModule module in typeSource.IOModules)
     {
         IOModules.Add(module);
     }
 }
コード例 #5
0
        /// <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
 private bool remove(TECProtocol protocol)
 {
     if (protocolDictionary.ContainsKey(protocol))
     {
         TECIO io = protocolDictionary[protocol];
         io.Quantity--;
         if (io.Quantity < 1)
         {
             protocolDictionary.Remove(io.Protocol);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #7
0
        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);
        }
コード例 #8
0
 private bool remove(IOType type)
 {
     if (type == IOType.Protocol)
     {
         throw new Exception("Cannot remove Protocol as IOType");
     }
     if (ioDictionary.ContainsKey(type))
     {
         TECIO io = ioDictionary[type];
         io.Quantity--;
         if (io.Quantity < 1)
         {
             ioDictionary.Remove(io.Type);
         }
         return(true);
     }
     else
     {
         if (TECIO.PointIO.Contains(type))
         {
             IOType universalType = TECIO.GetUniversalType(type);
             if (ioDictionary.ContainsKey(universalType))
             {
                 TECIO universalIO = ioDictionary[universalType];
                 universalIO.Quantity--;
                 if (universalIO.Quantity < 1)
                 {
                     ioDictionary.Remove(universalIO.Type);
                 }
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
 }
コード例 #9
0
 public bool AddPoint(TECPoint point)
 {
     if (this.Connection == null || !(this.Connection is TECHardwiredConnection))
     {
         this.Points.Add(point);
         return(true);
     }
     else
     {
         TECIO io = new TECIO(point.Type)
         {
             Quantity = point.Quantity
         };
         if (this.Connection.ParentController.AvailableIO.Contains(io))
         {
             this.Points.Add(point);
             return(true);
         }
     }
     raisePropertyChanged("PointNumber");
     return(false);
 }
コード例 #10
0
 public bool Remove(TECIO io)
 {
     if (!this.Contains(io))
     {
         return(false);
     }
     if (io.Type == IOType.Protocol)
     {
         for (int x = 0; x < io.Quantity; x++)
         {
             remove(io.Protocol);
         }
     }
     else
     {
         for (int x = 0; x < io.Quantity; x++)
         {
             remove(io.Type);
         }
     }
     return(true);
 }
コード例 #11
0
 public bool Contains(TECIO io)
 {
     if (TECIO.UniversalIO.Contains(io.Type))
     {
         return(ioDictionary.ContainsKey(io.Type) ? ioDictionary[io.Type].Quantity >= io.Quantity : false);
     }
     else if (io.Protocol != null)
     {
         return(protocolDictionary.ContainsKey(io.Protocol) ? protocolDictionary[io.Protocol].Quantity >= io.Quantity : false);
     }
     else if (TECIO.PointIO.Contains(io.Type))
     {
         IOType universalType = TECIO.GetUniversalType(io.Type);
         int    quantity      = ioDictionary.ContainsKey(io.Type) ? ioDictionary[io.Type].Quantity : 0;
         quantity += ioDictionary.ContainsKey(universalType) ? ioDictionary[universalType].Quantity : 0;
         return(quantity >= io.Quantity);
     }
     else
     {
         throw new Exception("IO condition not recognized.");
     }
 }
コード例 #12
0
 public IOCollection(TECIO io) : this(new List <TECIO> {
     io
 })
 {
 }
コード例 #13
0
 public TECIO(TECIO ioSource) : this(ioSource.Type)
 {
     _quantity = ioSource.Quantity;
     _protocol = ioSource.Protocol;
 }