public LocationAlarm(Position p, int area, AreaAuthorizationRecord aar, string content, LocationAlarmLevel level) { SetTime(); AlarmType = LocationAlarmType.区域告警; AlarmLevel = level; LocationCardId = p.CardId; PersonnelId = p.PersonnelID; CardRoleId = p.RoleId ?? 0; //if (p.AreaId == 0) //{ // Log.Info("p.AreaId == 0"); //} if (aar != null) { AreaId = aar.AreaId; AuzId = aar.Id;//触发告警的权限规则 AllAuzId += aar.Id; } else { AreaId = area; } Content = content; AlarmId = Guid.NewGuid().ToString(); }
//List<Position> noAlarmPos = new List<Position>(); private LocationAlarm AddAlarm(Position p, int area, AreaAuthorizationRecord arr, string content, LocationAlarmLevel level) { LocationAlarm alarm = new LocationAlarm(p, area, arr, content, level); //alarms.Add(alarm); return(alarm); }
/// <summary> /// 功能:1、去除重复的正常告警,2、当卡片有正常告警和异常告警时,去除正常告警 /// </summary> /// <param name="p"></param> /// <param name="area"></param> /// <param name="arr"></param> /// <param name="content"></param> /// <param name="level"></param> /// /// <param name="newAlarmList"></param> private void RemoveDuplicateAlarms(Position p, int area, AreaAuthorizationRecord arr, string content, LocationAlarmLevel level, ref List <LocationAlarm> newAlarmList) { if (level == LocationAlarmLevel.正常) { //如果缓存中 没有正常告警,添加正常告警;如果缓存中有正常告警,添加正常告警规则Id int nCount = newAlarmList.FindAll(i => i.LocationCardId == p.CardId && i.AlarmLevel != LocationAlarmLevel.正常).Count(); LocationAlarm alarm = newAlarmList.Find(i => i.LocationCardId == p.CardId && i.AlarmLevel == LocationAlarmLevel.正常); if (nCount == 0 && alarm == null) { alarm = AddAlarm(p, area, arr, content, level); newAlarmList.Add(alarm); } else if (nCount == 0 && alarm != null) { if (arr != null) { alarm.AllAuzId += ";" + arr.Id; } else { Log.Error("AuthorizationBuffer.RemoveDuplicateAlarms", "arr==null"); } } } else { //如果缓存中有正常告警,去除正常告警,再添加异常告警 int nCount = newAlarmList.FindAll(i => i.LocationCardId == p.CardId && i.AlarmLevel == LocationAlarmLevel.正常).Count(); if (nCount > 0) { newAlarmList.RemoveAll(i => i.LocationCardId == p.CardId && i.AlarmLevel == LocationAlarmLevel.正常); } LocationAlarm alarm = AddAlarm(p, area, arr, content, level); newAlarmList.Add(alarm); } return; }
public void SendUdpAlarm(List <LocationAlarm> SendAlarm, List <LocationAlarm> SendAlarm2) { if (SendAlarm == null || SendAlarm.Count <= 0) { return; } //using() if (lcList == null) { using (var bll = GetLocationBll()) { lcList = bll.LocationCards.ToList(); } } DateTime dtNow = DateTime.Now; long timeStamp = 0; long timeStamp2 = Location.TModel.Tools.TimeConvert.ToStamp(DateTime.Now); long timeStampCha = 3500; List <LocationAlarm> lst = new List <LocationAlarm>(); List <LocationAlarm> lst2 = new List <LocationAlarm>(); foreach (LocationAlarm item in SendAlarm2) { int alarmId = item.Id; LocationAlarm la = SendAlarm.Find(p => p.Id == alarmId); if (la != null) { timeStamp = item.AlarmTimeStamp; long lc = timeStamp2 - timeStamp; if (lc >= timeStampCha) { item.AlarmTimeStamp = timeStamp2; } else { SendAlarm.Remove(la); } } else { lst.Add(item); } } foreach (LocationAlarm item in lst) { SendAlarm2.Remove(item); } foreach (LocationAlarm item in SendAlarm) { int alarmId = item.Id; LocationAlarm la = SendAlarm2.Find(p => p.Id == alarmId); if (la == null) { SendAlarm2.Add(item); } } foreach (LocationAlarm item in SendAlarm) { LocationAlarmLevel level = item.AlarmLevel; if (level == LocationAlarmLevel.正常) { continue; } int?id = item.LocationCardId; if (id == null) { continue; } int id2 = (int)id; String strData = GetUdpAlarmInfo(id2, lcList); if (strData == "") { continue; } Log.Info("打印Udp告警信号信号:" + Convert.ToString(item.Id) + " " + dtNow.ToString()); engineDa.SendAlarm(strData); } }