示例#1
0
        public static PlcDTO MapPlc(PLC plc, int?totalCount = null, int?alarmCount = null)
        {
            if (plc == null)
            {
                return(null);
            }

            var plcDTO = new PlcDTO();

            plcDTO.Id                = plc.Id;
            plcDTO.Name              = plc.Name;
            plcDTO.FullName          = plc.FullName;
            plcDTO.Description       = plc.Description;
            plcDTO.LastEventDateTime = plc.LastEventDateTime;

            plcDTO.FactoryId = plc.FactoryId;
            if (plc.Factory != null)
            {
                plcDTO.FactoryNumber   = plc.Factory.Number;
                plcDTO.FactoryName     = plc.Factory.Description;
                plcDTO.FactoryFullName = plc.Factory.FullName;
            }
            plcDTO.OrderIndex   = plc.OrderIndex;
            plcDTO.ProtocolType = plc.ProtocolType != null ? plc.ProtocolType.Value : 0;

            plcDTO.EventCount = totalCount;
            plcDTO.AlarmCount = alarmCount;

            return(plcDTO);
        }
示例#2
0
        public static IEnumerable <PlcDTO> GetPlcDTOList(this MPTEntities db, DateTime?fromDT = null, DateTime?toDT = null)
        {
            if (fromDT == null)
            {
                fromDT = DateTime.Now.Date;
            }
            if (toDT == null)
            {
                toDT = DateTime.Now.AddDays(1).Date;
            }
            if (fromDT > toDT)
            {
                fromDT = toDT;
            }

            var plcEventsCountDict = db.GetPlcEventsCount(fromDT.Value, toDT.Value, severity: 2).ToDictionary(x => x.PlcId, y => y);

            return(db.GetPLCs(protocolOnly: true).ToList().Select(x => PlcDTO.MapPlc(x, plcEventsCountDict)));
        }