Example #1
0
        public List <DeviceType> GetAllDeviceTypeOfController(ControllerModel controller)
        {
            List <DeviceType>    lstDeviceType = new List <DeviceType>();
            ControllerConfig8007 config        = new ControllerConfig8007();

            if (controller != null)
            {
                if (controller.Loops != null)
                {
                    foreach (var loop in controller.Loops)
                    {
                        IEnumerable <DeviceInfo8007> lstDistinceInfo = loop.GetDevices <DeviceInfo8007>().Distinct(new CollectionEqualityComparer <DeviceInfo8007>((x, y) => x.TypeCode == y.TypeCode)).ToList();
                        foreach (var device in lstDistinceInfo)
                        {
                            DeviceType dType = config.GetDeviceTypeViaDeviceCode(device.TypeCode);
                            lstDeviceType.Add(dType);
                        }
                    }
                }
            }
            return(lstDeviceType);
        }
Example #2
0
        /// <summary>
        /// 获取控制器内不同器件类型的数量
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        public override Dictionary <string, int> GetAmountOfDifferentDeviceType(ControllerModel controller)
        {
            Dictionary <string, int> dictDeviceTypeStatistic = new Dictionary <string, int>();
            ControllerConfig8007     config = new ControllerConfig8007();

            if (controller != null)
            {
                if (controller.Loops != null)
                {
                    foreach (var loop in controller.Loops)
                    {
                        IEnumerable <DeviceInfo8007> lstDistinceInfo = loop.GetDevices <DeviceInfo8007>().Distinct(new CollectionEqualityComparer <DeviceInfo8007>((x, y) => x.TypeCode == y.TypeCode)).ToList();

                        int deviceCountInLoop = loop.GetDevices <DeviceInfo8007>().Count;
                        //int deviceCountInStatistic = 0;
                        foreach (var device in lstDistinceInfo)
                        {
                            DeviceType dType     = config.GetDeviceTypeViaDeviceCode(device.TypeCode);
                            int        typeCount = loop.GetDevices <DeviceInfo8007>().Count((d) => d.TypeCode == dType.Code); //记录器件类型的数量
                            if (!dictDeviceTypeStatistic.ContainsKey(dType.Name))
                            {
                                dictDeviceTypeStatistic.Add(dType.Name, typeCount);
                            }
                            else
                            {
                                dictDeviceTypeStatistic[dType.Name] += typeCount;
                            }
                            //deviceCountInStatistic += typeCount;
                            //if (deviceCountInStatistic == deviceCountInLoop)
                            //{
                            //    break;
                            //}
                        }
                    }
                }
            }
            return(dictDeviceTypeStatistic);
        }