public List <AlarmThreadManagerOut> GetCurrentAlarms() { var result = new List <AlarmThreadManagerOut>(); for (var ai = 0; ai < _alarms.Count; ai++) { var tm = _cfgs.FirstOrDefault(x => x.TagId == _alarms[ai].TagId) ?? new AlarmThreadManagerConfig(); var outAlarm = new AlarmThreadManagerOut(); outAlarm.Id = _alarms[ai].Id; outAlarm.TagId = _alarms[ai].TagId; _alarms[ai].SVal = Math.Round(_alarms[ai].SVal, 2); _alarms[ai].EVal = Math.Round(_alarms[ai].EVal, 2); var sr = ""; switch (_alarms[ai].SRes) { case -2: sr = tm.LoloText; break; case -1: sr = tm.LoText; break; case 0: sr = tm.NormalText; break; case 1: sr = tm.HiText; break; case 2: sr = tm.HihiText; break; } outAlarm.StartReason = sr + " (" + Math.Round(_alarms[ai].SVal, 2) + ")"; //outAlarm.StartReason = _alarms[ai].SRes; outAlarm.StartValue = _alarms[ai].SVal; outAlarm.StartTime = _alarms[ai].STime; //outAlarm.StartValue = _alarms[ai].SVal; sr = ""; tm.Active = false; switch (_alarms[ai].ERes) { case -2: sr = tm.LoloText; break; case -1: sr = tm.LoText; break; case 0: sr = tm.NormalText; break; case 1: sr = tm.HiText; break; case 2: sr = tm.HihiText; break; case -10: sr = "Тревога активна"; outAlarm.Active = true; break; } outAlarm.EndReason = sr + " (" + Math.Round(_alarms[ai].EVal, 2) + ")"; //outAlarm.EndReason = _alarms[ai].ERes; outAlarm.EndValue = _alarms[ai].EVal; outAlarm.EndTime = _alarms[ai].ETime; //outAlarm.EndValue = _alarms[ai].EVal; outAlarm.AckTime = _alarms[ai].QTime; outAlarm.Ack = _alarms[ai].Qted; var Duration = new TimeSpan(); if (_alarms[ai].ETime == DateTime.MinValue) { Duration = DateTime.Now - _alarms[ai].STime; } else { Duration = _alarms[ai].ETime - _alarms[ai].STime; } outAlarm.Duration = new TimeSpan(Duration.Days, Duration.Hours, Duration.Minutes, Duration.Seconds); result.Add(outAlarm); } return(result.OrderBy(x => x.StartTime).ToList()); }
public List <AlarmThreadManagerOut> GetAlarmsReport(string dt1, string dt2) { var Sdate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); var Edate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 24, 0, 0); if (dt1 != null) { Sdate = Convert.ToDateTime(dt1); } if (dt2 != null) { Edate = Convert.ToDateTime(dt2); } var result = new List <AlarmThreadManagerOut>(); var alarmslist = context.Alarms.Where(x => x.STime >= Sdate && x.STime <= Edate).OrderByDescending(x => x.STime); var alarms = alarmslist.ToList(); for (var ai = 0; ai < _alarms.Count; ai++) { var tm = _cfgs.FirstOrDefault(x => x.TagId == _alarms[ai].TagId) ?? new AlarmThreadManagerConfig(); var outAlarm = new AlarmThreadManagerOut(); outAlarm.Id = _alarms[ai].Id; outAlarm.TagId = _alarms[ai].TagId; _alarms[ai].SVal = Math.Round(_alarms[ai].SVal, 2); _alarms[ai].EVal = Math.Round(_alarms[ai].EVal, 2); var sr = ""; switch (_alarms[ai].SRes) { case -2: sr = tm.LoloText; break; case -1: sr = tm.LoText; break; case 0: sr = tm.NormalText; break; case 1: sr = tm.HiText; break; case 2: sr = tm.HihiText; break; } //outAlarm.StartReason = _alarms[ai].SRes; outAlarm.StartReason = sr + " (" + Math.Round(_alarms[ai].SVal, 2) + ")"; outAlarm.StartValue = _alarms[ai].SVal; outAlarm.StartTime = _alarms[ai].STime; //outAlarm.StartValue = _alarms[ai].SVal; sr = ""; tm.Active = false; switch (_alarms[ai].ERes) { case -2: sr = tm.LoloText; break; case -1: sr = tm.LoText; break; case 0: sr = tm.NormalText; break; case 1: sr = tm.HiText; break; case 2: sr = tm.HihiText; break; case -10: // outAlarm.Message = "Тревога активна"; outAlarm.Active = true; break; } outAlarm.StartReason = sr + " (" + Math.Round(_alarms[ai].EVal, 2) + ")"; //outAlarm.EndReason = _alarms[ai].ERes; outAlarm.EndValue = _alarms[ai].EVal; outAlarm.EndTime = _alarms[ai].ETime; //outAlarm.EndValue = _alarms[ai].EVal; outAlarm.AckTime = _alarms[ai].QTime; outAlarm.Ack = _alarms[ai].Qted; result.Add(outAlarm); } return(result.OrderBy(x => x.StartTime).ToList()); }
public List <AlarmThreadManagerOut> GetCurrentAlarms(Int32?id = null) { var _alarms_ = new List <AlarmThreadManagerAlarm>(); if (id != null) { var list = GetChildTags(id); _alarms_ = _alarms.Where(x => list.Contains(x.TagId)).ToList(); } else { _alarms_ = _alarms; } logger.Logged("Info", id + ". Get alarm list . length" + _alarms_.Count, "AlarmThreadManager", "GetCurrentAlarms"); var result = new List <AlarmThreadManagerOut>(); for (var ai = 0; ai < _alarms_.Count; ai++) { var tm = _cfgs.FirstOrDefault(x => x.TagId == _alarms_[ai].TagId) ?? new AlarmThreadManagerConfig(); var outAlarm = new AlarmThreadManagerOut(); outAlarm.Id = _alarms_[ai].Id; outAlarm.TagId = _alarms_[ai].TagId; _alarms_[ai].SVal = Math.Round(_alarms_[ai].SVal, 2); _alarms_[ai].EVal = Math.Round(_alarms_[ai].EVal, 2); var sr = ""; switch (_alarms_[ai].SRes) { case -2: sr = tm.LoloText; break; case -1: sr = tm.LoText; break; case 0: sr = tm.NormalText; break; case 1: sr = tm.HiText; break; case 2: sr = tm.HihiText; break; } outAlarm.StartReason = sr + " (" + Math.Round(_alarms_[ai].SVal, 2) + ")"; //outAlarm.StartReason = _alarms[ai].SRes; outAlarm.StartValue = _alarms_[ai].SVal; outAlarm.StartTime = _alarms_[ai].STime; //outAlarm.StartValue = _alarms[ai].SVal; sr = ""; switch (_alarms_[ai].ERes) { case -2: sr = tm.LoloText; break; case -1: sr = tm.LoText; break; case 0: sr = tm.NormalText; break; case 1: sr = tm.HiText; break; case 2: sr = tm.HihiText; break; case -10: sr = "Тревога активна"; outAlarm.Active = true; break; } outAlarm.EndReason = sr + " (" + Math.Round(_alarms_[ai].EVal, 2) + ")"; //outAlarm.EndReason = _alarms[ai].ERes; outAlarm.EndValue = _alarms_[ai].EVal; outAlarm.EndTime = _alarms_[ai].ETime; //outAlarm.EndValue = _alarms[ai].EVal; outAlarm.AckTime = _alarms_[ai].QTime; outAlarm.Ack = _alarms_[ai].Qted; var Duration = new TimeSpan(); if (_alarms_[ai].ETime == DateTime.MinValue) { Duration = DateTime.Now - _alarms_[ai].STime; } else { Duration = _alarms_[ai].ETime - _alarms_[ai].STime; } outAlarm.Duration = Duration.Hours + ":" + Duration.Minutes + ":" + Duration.Seconds; if (Duration.Days > 0) { outAlarm.Duration = Duration.Days + "д. " + outAlarm.Duration; } result.Add(outAlarm); } return(result.OrderBy(x => x.StartTime).ToList()); }