public List <DeviceType> GetAllDeviceTypeOfController(ControllerModel controller) { List <DeviceType> lstDeviceType = new List <DeviceType>(); ControllerConfig8021 config = new ControllerConfig8021(); if (controller != null) { if (controller.Loops != null) { foreach (var loop in controller.Loops) { IEnumerable <DeviceInfo8021> lstDistinceInfo = loop.GetDevices <DeviceInfo8021>().Distinct(new CollectionEqualityComparer <DeviceInfo8021>((x, y) => x.TypeCode == y.TypeCode)).ToList(); foreach (var device in lstDistinceInfo) { DeviceType dType = config.GetDeviceTypeViaDeviceCode(device.TypeCode); lstDeviceType.Add(dType); } } } } return(lstDeviceType); }
/// <summary> /// 获取控制器内不同器件类型的数量 /// </summary> /// <param name="controller"></param> /// <returns></returns> public override Dictionary <string, int> GetAmountOfDifferentDeviceType(ControllerModel controller) { Dictionary <string, int> dictDeviceTypeStatistic = new Dictionary <string, int>(); ControllerConfig8021 config = new ControllerConfig8021(); if (controller != null) { if (controller.Loops != null) { foreach (var loop in controller.Loops) { IEnumerable <DeviceInfo8021> lstDistinceInfo = loop.GetDevices <DeviceInfo8021>().Distinct(new CollectionEqualityComparer <DeviceInfo8021>((x, y) => x.TypeCode == y.TypeCode)).ToList(); int deviceCountInLoop = loop.GetDevices <DeviceInfo8021>().Count; //int deviceCountInStatistic = 0; foreach (var device in lstDistinceInfo) { DeviceType dType = config.GetDeviceTypeViaDeviceCode(device.TypeCode); int typeCount = loop.GetDevices <DeviceInfo8021>().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); }