private DevAlarm CreateDevAlarm(UDPArchor item) { DevAlarm alarm = new DevAlarm(); alarm.Level = Abutment_DevAlarmLevel.低; alarm.Code = "基站离线"; alarm.Title = "基站离线"; alarm.Src = Abutment_DevAlarmSrc.人员定位;//其实应该加上“基站扫描”的 alarm.AlarmTime = DateTime.Now; alarm.AlarmTimeStamp = TimeConvert.ToStamp(alarm.AlarmTime); var clientIP = item.GetClientIP(); alarm.Msg = "基站离线:" + clientIP; var anchor = DbArchorList.Find(i => i.Ip == clientIP); if (anchor != null) { var devId = (int)anchor.DevId; var dev = devDict[devId]; alarm.DevInfo = dev; alarm.DevInfoId = devId; alarm.Device_desc = dev.Name; alarm.Title = string.Format("基站离线[{0},{1}]", anchor.Code.Trim(), anchor.Ip.Trim()); alarm.Msg = string.Format("基站离线[{0},{1}]", anchor.Code, anchor.Ip); //alarm.AreaId } alarm.DictKey = alarm.Msg; return(alarm); }
protected void OnDevAlarmReceived(DevAlarm alarm) { if (DevAlarmReceived != null) { DevAlarmReceived(alarm); } }
public AllAlarms GetAllAlarmsByPerson(AlarmSearchArgAll args) { AllAlarms alarms = new AllAlarms(); try { string sqlwhere1 = ""; string sqlwhere2 = ""; string personnels = ""; if (args != null) { if (args.personnels != null) { foreach (int person in args.personnels) { personnels += person.ToString() + ","; } personnels = personnels.Substring(0, personnels.Length - 1); sqlwhere1 += " and PersonnelId in (" + personnels + ")"; } if (args.startTime != null && args.endTime != null) { sqlwhere1 += string.Format(@" and AlarmTimeStamp>{0} and AlarmTimeStamp<{1}", args.startTime.ToStamp(), args.endTime.ToStamp()); sqlwhere2 += string.Format(@" and AlarmTimeStamp>{0} and AlarmTimeStamp<{1}", args.startTime.ToStamp(), args.endTime.ToStamp()); } } string sql1 = string.Format(@"select id,AlarmId,AlarmType,AlarmLevel,LocationCardId,PersonnelId,CardRoleId,AreaId,AuzId,AllAuzId,Content,AlarmTime,AlarmTimeStamp,HandleTime,HandleTimeStamp,`Handler`,HandleType from location.locationalarms where 1=1 " + sqlwhere1); string sql2 = string.Format(@"select id,AlarmId,AlarmType,AlarmLevel,LocationCardId,PersonnelId,CardRoleId,areadid,AuzId,AllAuzId,Content,AlarmTime,AlarmTimeStamp,HandleTime,HandleTimeStamp,`Handler`,HandleType, HistoryTime, HistoryTimeStamp from locationhistory.locationalarmhistories where 1=1 " + sqlwhere1); string sql3 = string.Format(@"select id,Abutment_Id,Title,Msg,`LEVEL`,`Code`,Src,DevInfoId,Device_desc,AlarmTime,AlarmTimeStamp from location.devalarms where 1=1 " + sqlwhere2); string sql4 = string.Format(@"select id,Abutment_Id,Title,Msg,`LEVEL`,`Code`,Src,DevInfoId,Device_desc,AlarmTime,AlarmTimeStamp,historyTime,historyTimeStamp from locationhistory.devalarmhistories where 1=1 " + sqlwhere2); List <DbModel.Location.Alarm.LocationAlarm> list1 = db.LocationAlarms.GetListBySql <DbModel.Location.Alarm.LocationAlarm>(sql1); List <LocationAlarmHistory> list2 = db.LocationAlarmHistorys.GetListBySql <LocationAlarmHistory>(sql2); List <DbModel.Location.Alarm.LocationAlarm> listalarm = new List <DbModel.Location.Alarm.LocationAlarm>(); listalarm.AddRange(list1); foreach (LocationAlarmHistory alarmHis in list2) { DbModel.Location.Alarm.LocationAlarm alarm = alarmHis.ConvertToAlarm(); listalarm.Add(alarm); } List <DevAlarm> list3 = db.DevAlarms.GetListBySql <DevAlarm>(sql3); List <DevAlarmHistory> devalarmHiss = db.DevAlarmHistorys.GetListBySql <DevAlarmHistory>(sql4); List <DevAlarm> devalarms = new List <DevAlarm>(); devalarms.AddRange(list3); foreach (DevAlarmHistory devalarmhis in devalarmHiss) { DevAlarm devalarm = devalarmhis.ConvertToDevAlarm(); devalarms.Add(devalarm); } alarms.alarmList = listalarm.ToTModel(); alarms.devAlarmList = devalarms.ToTModel(); } catch (Exception ex) { alarms.alarmList = new List <T_LocationAlarm>(); alarms.devAlarmList = new List <DeviceAlarm>(); Log.Error("AlarmService.GetAllAlarmsByPerson:" + ex.ToString()); } return(alarms); }
private List <DevAlarm> GenerateNewAlarm(UDPArchorList list1) { List <DevAlarm> alarms = new List <DevAlarm>(); foreach (var item in list1) { DevAlarm alarm = CreateDevAlarm(item); alarms.Add(alarm); } return(alarms); }
/// <summary>Handles a message.</summary> public void HandleMessage(IMessage message) { string msg = Encoding.UTF8.GetString(message.Body); events recv = JsonConvert.DeserializeObject <events>(msg); if (recv == null || recv.deviceId == null) { return; } DevInfo di = bll.DevInfos.DbSet.Where(p => p.Abutment_Id == recv.deviceId).FirstOrDefault(); if (di == null) { return; } DevAlarm da = bll.DevAlarms.DbSet.Where(p => p.Abutment_Id == recv.id).FirstOrDefault(); int nFlag = 0; if (da == null) { da = new DevAlarm(); nFlag = 1; } da.Abutment_Id = recv.id; da.Title = recv.title; da.Msg = recv.msg; da.Level = (Abutment_DevAlarmLevel)recv.level; da.Code = recv.code; da.Src = (Abutment_DevAlarmSrc)recv.src; da.DevInfoId = di.Id; da.Device_desc = recv.deviceDesc; da.AlarmTime = TimeConvert.TimeStampToDateTime(recv.t / 1000); da.AlarmTimeStamp = recv.t; if (nFlag == 1) { bll.DevAlarms.Add(da); } else { bll.DevAlarms.Edit(da); } OnDevAlarmReceived(da); return; }
private static DevAlarm CreateDevAlarm(events recv, DevInfo di, long lTimeStamp, Abutment_DevAlarmLevel adLevel) { DevAlarm da = new DevAlarm(); da.Abutment_Id = recv.id; da.Title = recv.title; da.Msg = recv.msg; da.Level = adLevel; da.Code = recv.code; da.Src = (Abutment_DevAlarmSrc)recv.src; da.DevInfoId = di.Id; da.DevInfo = di;//这个可能导致设备重复,奇怪 da.Device_desc = recv.device_desc; da.AlarmTime = TimeConvert.ToDateTime(lTimeStamp); da.AlarmTimeStamp = lTimeStamp; return(da); }
public DevAlarm ConvertToDevAlarm() { DevAlarm alarm = new DevAlarm(); alarm.Id = this.Id; alarm.Abutment_Id = this.Abutment_Id; alarm.Title = this.Title; alarm.Msg = this.Msg; if (this.Level == null) { alarm.Level = Abutment_DevAlarmLevel.无; } alarm.Level = (Abutment_DevAlarmLevel)this.Level; alarm.Code = this.Code; alarm.Src = this.Src; alarm.DevInfoId = this.DevInfoId; alarm.Device_desc = this.Device_desc; alarm.AlarmTime = this.AlarmTime; alarm.AlarmTimeStamp = this.AlarmTimeStamp; alarm.HistoryTime = (DateTime)this.HistoryTime; alarm.HistoryTimeStamp = (long)this.HistoryTimeStamp; return(alarm); }
void InitServerByDatabase() { try { using (var dataReader = DataHelper.Instance.ExecuteProcedureReader("InitServer", DataHelper.CreateParam("@TYPE", System.Data.SqlDbType.Int, 1))) { if (dataReader == null) { Environment.Exit(0); } //dataReader.Read(); dataReader.Read(); int count = dataReader.GetInt32(0); _list = new List <TagMetaData>(count); _mapping = new Dictionary <string, ITag>(count); dataReader.NextResult(); while (dataReader.Read()) { _list.Add(new TagMetaData(dataReader.GetInt16(0), dataReader.GetInt16(1), dataReader.GetString(2), dataReader.GetString(3), (DataType)dataReader.GetByte(4), (ushort)dataReader.GetInt16(5), dataReader.GetBoolean(6), dataReader.GetFloat(7), dataReader.GetFloat(8), dataReader.GetInt32(9))); //_list[i].Description = dataReader.GetSqlString(6).Value; } _list.Sort(); if (reader != null && group == null) { group = reader.AddGroup("Group1", 1, 0, 0, true) as ClientGroup; group.AddItems(_list); } dataReader.NextResult(); _conditions = new List <ICondition>(); _conditionList = new ObservableCollection <ICondition>(); while (dataReader.Read()) { int id = dataReader.GetInt32(0); AlarmType type = (AlarmType)dataReader.GetInt32(2); ICondition cond; string source = dataReader.GetString(1); if (_conditions.Count > 0) { cond = _conditions[_conditions.Count - 1]; if (cond.ID == id) { cond.AddSubCondition(new SubCondition((SubAlarmType)dataReader.GetInt32(9), dataReader.GetFloat(10), (Severity)dataReader.GetByte(11), dataReader.GetString(12), dataReader.GetBoolean(13))); continue; } } switch (type) { case AlarmType.Complex: cond = new ComplexCondition(id, source, dataReader.GetString(6), dataReader.GetFloat(7), dataReader.GetInt32(8)); break; case AlarmType.Level: cond = new LevelAlarm(id, source, dataReader.GetString(6), dataReader.GetFloat(7), dataReader.GetInt32(8)); break; case AlarmType.Dev: cond = new DevAlarm(id, (ConditionType)dataReader.GetByte(4), source, dataReader.GetString(6), dataReader.GetFloat(5), dataReader.GetFloat(7), dataReader.GetInt32(8)); break; case AlarmType.ROC: cond = new ROCAlarm(id, source, dataReader.GetString(6), dataReader.GetFloat(7), dataReader.GetInt32(8)); break; case AlarmType.Quality: cond = new QualitiesAlarm(id, source, dataReader.GetString(6)); break; default: cond = new DigitAlarm(id, source, dataReader.GetString(6), dataReader.GetInt32(8)); break; } cond.AddSubCondition(new SubCondition((SubAlarmType)dataReader.GetInt32(9), dataReader.GetFloat(10), (Severity)dataReader.GetByte(11), dataReader.GetString(12), dataReader.GetBoolean(13))); cond.IsEnabled = dataReader.GetBoolean(3); var simpcond = cond as SimpleCondition; if (simpcond != null) { simpcond.Tag = this[source]; } else { var complexcond = cond as ComplexCondition; if (complexcond != null) { var action = complexcond.SetFunction(reval.Eval(source)); if (action != null) { ValueChangedEventHandler handle = (s1, e1) => { action(); }; foreach (ITag tag in reval.TagList) { tag.ValueChanged += handle;// tag.Refresh(); } } } } cond.AlarmActive += new AlarmEventHandler(cond_SendAlarm); cond.AlarmAck += new EventHandler(cond_AckAlarm); //_conditions.Add(cond);// UpdateCondition(cond); _conditions.Add(cond); } dataReader.NextResult(); while (dataReader.Read()) { _scales.Add(new Scaling(dataReader.GetInt16(0), (ScaleType)dataReader.GetByte(1), dataReader.GetFloat(2), dataReader.GetFloat(3), dataReader.GetFloat(4), dataReader.GetFloat(5))); } } reval.Clear(); _scales.Sort(); _compare = new CompareCondBySource(); _conditions.Sort(_compare); } catch (Exception e) { App.AddErrorLog(e); Environment.Exit(0); } }
/// <summary>Handles a message.</summary> public void HandleMessage(IMessage message) { try { Init(); int count1 = bll.DevInfos.GetCount(); string msg = Encoding.UTF8.GetString(message.Body); events recv = JsonConvert.DeserializeObject <events>(msg); if (recv == null) { return; } int nsrc = recv.src; DevInfo di = null; if (nsrc == 1 || nsrc == 2) { if (recv.raw_id == null || recv.raw_id == "") { return; } di = DevList.Find(p => p.Abutment_DevID == recv.raw_id); } else if (nsrc == 3) { if (recv.node == null || recv.node == "") { return; } di = DevList.Find(p => p.Code == recv.node); } long lTimeStamp = recv.t * 1000; bool bFlag = false; int nLevel = (int)recv.level; Abutment_DevAlarmLevel adLevel = (Abutment_DevAlarmLevel)nLevel; if (nLevel == 0) { adLevel = Abutment_DevAlarmLevel.未定; } if (di == null) { //DevAlarm da2 = new DevAlarm(); //da2.Abutment_Id = recv.id; //da2.Title = recv.title; //da2.Msg = recv.msg; //da2.Level = adLevel; //da2.Code = recv.code; //da2.Src = (Abutment_DevAlarmSrc)recv.src; //da2.DevInfoId = 0;//未找到设备 //da2.Device_desc = recv.deviceDesc; //da2.AlarmTime = TimeConvert.ToDateTime(lTimeStamp); //da2.AlarmTimeStamp = lTimeStamp; //bll.DevAlarms.Add(da2);//未找到设备的告警也记录下来, //Log. bv //LogEvent.Info("RealAlarm", string.Format("没找到设备信息,json:{0}", msg)); //LogEvent.Info("RealAlarm", string.Format("没找到设备信息:{0}", recv.title)); SaveMessageToFile(msg, "noDev"); return;//没找到设备信息,则不做任何处理, } if (recv.title.Contains("防拆") || recv.msg.Contains("防拆")) { SaveMessageToFile(msg, "filter"); return;//过滤掉有“防拆”字段的告警,没有意义。 } LogEvent.Info("RealAlarm", string.Format("获取设备:{0}", recv.title)); SaveMessageToFile(msg, ""); DevAlarm da = DaList.Find(p => p.DevInfoId == di.Id && p.AlarmTimeStamp == lTimeStamp); if (da == null) { if (recv.state == 0) { da = CreateDevAlarm(recv, di, lTimeStamp, adLevel); bll.DevAlarms.Add(da); DaList.Add(da); bFlag = true; } } else { if (recv.state == 1 || recv.state == 2) { DevAlarmHistory da_history = da.RemoveToHistory(); DaList.Remove(da); bll.DevAlarms.DeleteById(da.Id); bll.DevAlarmHistorys.Add(da_history);//告警恢复 放到历史数据中 da.Level = Abutment_DevAlarmLevel.无; bFlag = true; } else if (adLevel != da.Level) { da.Level = adLevel; da.Title = recv.title; da.Msg = recv.msg; bll.DevAlarms.Edit(da); bFlag = true; } } if (bFlag) { OnDevAlarmReceived(da); } int count2 = bll.DevInfos.GetCount(); if (count2 > count1) { Log.Info(LogTags.RealAlarm, "添加了数据:" + count1 + "->" + count2); } return; } catch (Exception ex) { Log.Info(LogTags.RealAlarm, "HandleMessage:" + ex); } }
/// <summary> /// 获取告警事件列表 /// </summary> /// <param name="src"></param> /// <param name="level"></param> /// <param name="begin_t"></param> /// <param name="end_t"></param> /// <returns></returns> public BaseTran <events> GeteventsList(int?src, int?level, long?begin_t, long?end_t) { BaseTran <events> recv = new BaseTran <events>(); try { string path = "api/events"; string url = BaseUri + path; if (src != null) { url += "?src=" + Convert.ToString(src); } else { url += "?src"; } if (level != null) { url += "&level=" + Convert.ToString(level); } else { url += "&level"; } if (begin_t != null && end_t != null) { url += "&begin_t=" + Convert.ToString(begin_t) + "&end_t=" + Convert.ToString(end_t); } else { url += "&begin_t" + "&end_t"; } recv = GetEntityList <events>(url); if (recv.data == null) { recv.data = new List <events>(); } foreach (events item in recv.data) { if (item.device_id == null) { continue; } DevInfo di = bll.DevInfos.DbSet.Where(p => p.Abutment_Id == item.device_id).FirstOrDefault(); if (di == null) { continue; } DevAlarm da = bll.DevAlarms.DbSet.Where(p => p.Abutment_Id == item.id).FirstOrDefault(); int nFlag = 0; if (da == null) { da = new DevAlarm(); nFlag = 1; } da.Abutment_Id = item.id; da.Title = item.title; da.Msg = item.msg; da.Level = (Abutment_DevAlarmLevel)item.level; da.Code = item.code; da.Src = (Abutment_DevAlarmSrc)item.src; da.DevInfoId = di.Id; da.Device_desc = item.device_desc; da.AlarmTime = TimeConvert.TimeStampToDateTime(item.t); da.AlarmTimeStamp = item.t; if (nFlag == 1) { bll.DevAlarms.Add(da); } else { bll.DevAlarms.Edit(da); } } } catch (Exception ex) { string messgae = ex.Message; } return(recv); }
public DevAlarm Put(DevAlarm item) { return(service.Put(item)); }
/// <summary>Handles a message.</summary> public void HandleMessage(IMessage message) { string msg = Encoding.UTF8.GetString(message.Body); events recv = JsonConvert.DeserializeObject <events>(msg); if (recv == null || recv.raw_id == null || recv.raw_id == "" || recv.src != 1) { return; } DevInfo di = DevList.Find(p => p.Abutment_DevID == recv.raw_id); if (di == null) { return; } bool bFlag = false; int nLevel = (int)recv.level; Abutment_DevAlarmLevel adLevel = (Abutment_DevAlarmLevel)nLevel; long lTimeStamp = recv.t * 1000; if (nLevel == 0) { adLevel = Abutment_DevAlarmLevel.未定; } DevAlarm da = DaList.Find(p => p.DevInfoId == di.Id && p.AlarmTimeStamp == lTimeStamp); if (da == null) { if (recv.state == 0) { da = new DevAlarm(); da.Abutment_Id = recv.id; da.Title = recv.title; da.Msg = recv.msg; da.Level = adLevel; da.Code = recv.code; da.Src = (Abutment_DevAlarmSrc)recv.src; da.DevInfoId = di.Id; da.Device_desc = recv.device_desc; da.AlarmTime = TimeConvert.ToDateTime(lTimeStamp); da.AlarmTimeStamp = lTimeStamp; bll.DevAlarms.Add(da); DaList.Add(da); bFlag = true; } } else { if (recv.state == 1 || recv.state == 2) { DevAlarmHistory da_history = da.RemoveToHistory(); DaList.Remove(da); bll.DevAlarms.DeleteById(da.Id); bll.DevAlarmHistorys.Add(da_history); da.Level = Abutment_DevAlarmLevel.无; bFlag = true; } else if (adLevel != da.Level) { da.Level = adLevel; da.Title = recv.title; da.Msg = recv.msg; bll.DevAlarms.Edit(da); bFlag = true; } } if (bFlag) { OnDevAlarmReceived(da); } return; }
public DevAlarm Put(DevAlarm item) { return(null); }
public DevAlarm Post(DevAlarm item) { var result = db.DevAlarms.Add(item); return(result ? item : null); }