예제 #1
0
        public List <DeviceType> GetAllDeviceTypeOfController(ControllerModel controller)
        {
            List <DeviceType>    lstDeviceType = new List <DeviceType>();
            ControllerConfig8000 config        = new ControllerConfig8000();

            if (controller != null)
            {
                if (controller.Loops != null)
                {
                    foreach (var loop in controller.Loops)
                    {
                        IEnumerable <DeviceInfo8000> lstDistinceInfo = loop.GetDevices <DeviceInfo8000>().Distinct(new CollectionEqualityComparer <DeviceInfo8000>((x, y) => x.TypeCode == y.TypeCode)).ToList();
                        foreach (var device in lstDistinceInfo)
                        {
                            DeviceType dType = config.GetDeviceTypeViaDeviceCode(device.TypeCode);
                            lstDeviceType.Add(dType);
                        }
                    }
                }
            }
            return(lstDeviceType);
        }
예제 #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>();
            ControllerConfig8000     config = new ControllerConfig8000();

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

                        int deviceCountInLoop = loop.GetDevices <DeviceInfo8000>().Count;
                        // int deviceCountInStatistic = 0;
                        foreach (var device in lstDistinceInfo)
                        {
                            DeviceType dType     = config.GetDeviceTypeViaDeviceCode(device.TypeCode);
                            int        typeCount = loop.GetDevices <DeviceInfo8000>().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);
        }