/// <summary> /// 处理传感器采集超时和评分告警 /// </summary> /// <param name="warningmsg"></param> /// <returns></returns> private int SensorOrGradeWarningHandler(WarnningMsg warningmsg) { var request = JsonConvert.DeserializeObject <RequestWarningReceivedMessage>(warningmsg.Msg); if (request == null) { return(0); } try { // 检测消息中“DeviceId”是否存在于数据库,并限制告警等级 if (!DbAccessor.Exists(request.DeviceTypeId, request.DeviceId)) { // 日志记录未正确插入数据库中的数据 this.logger.Info("数据库insert操作失败:"); string errLog = string.Format( "接收到的告警数据: WarningTypeId={0}, StructId={1}, DeviceTypeId={2}, DeviceId={3}, WarningContent={4}, WarningTime={5}", request.WarningTypeId, request.StructId, request.DeviceTypeId, request.DeviceId, request.WarningContent, request.WarningTime); this.logger.Error(errLog); return(0); } // 将告警消息保存至数据库 int rowcount; if (_toClient == "true") { rowcount = DbAccessor.SaveWarningMsg(request, 4, 3); } else { rowcount = DbAccessor.SaveWarningMsg(request, 1, 1); } // rowcount = DbAccessor.SaveWarningMsg(request); // Process message Console.WriteLine(); Console.WriteLine("Text message received : WarningTypeId={0}; WarningTime={1}", request.WarningTypeId, request.WarningTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); Console.WriteLine("Source application : {0}", warningmsg.Sender); return(rowcount); } catch (Exception ex) { // 日志记录未正确插入数据库中的数据 this.logger.Info("数据库insert操作失败:"); string errLog = string.Format( "接收到的告警数据: WarningTypeId={0}, StructId={1}, DeviceTypeId={2}, DeviceId={3}, WarningContent={4}, WarningTime={5}", request.WarningTypeId, request.StructId, request.DeviceTypeId, request.DeviceId, request.WarningContent, request.WarningTime); this.logger.Error(errLog, ex); return(0); } }
/// <summary> /// This method handles received messages from other applications via DotNetMQ. /// </summary> /// <param name="sender">sender</param> /// <param name="e">Message parameters</param> public int MDSClient_MessageReceived(WarnningMsg warningmsg) { if (warningmsg == null) { return(0); } if (warningmsg.R.EndsWith("sensor", StringComparison.OrdinalIgnoreCase) || warningmsg.R.EndsWith("grade", StringComparison.OrdinalIgnoreCase)) { return(this.SensorOrGradeWarningHandler(warningmsg)); } else if (warningmsg.R.EndsWith("dtu", StringComparison.OrdinalIgnoreCase)) { return(this.DtuWarningHandler(warningmsg)); } else if (warningmsg.R.EndsWith("datacontinu", StringComparison.OrdinalIgnoreCase)) { return(this.DataContinuWarningHandler(warningmsg)); } return(0); }
/// <summary> /// 数据连续性告警 /// </summary> /// <param name="warningmsg"></param> /// <returns></returns> private int DataContinuWarningHandler(WarnningMsg warningmsg) { var request = JsonConvert.DeserializeObject <DataContinuWarningMsg>(warningmsg.Msg); if (request == null) { return(0); } logger.InfoFormat("传感器 {0} 的数据在 {1} {2}", request.DeviceId, request.DateTime.ToString("U"), request.DataStatus ? "恢复" : "中断"); int rowcount; if (_toClient == "true") { rowcount = DbAccessor.UpdateDataState(request, 4, 3); } else { rowcount = DbAccessor.UpdateDataState(request, 1, 1); } //return DbAccessor.UpdateDataState(request); return(rowcount); }
/// <summary> /// 处理dtu上下线告警 /// </summary> /// <param name="warningmsg"></param> /// <returns></returns> private int DtuWarningHandler(WarnningMsg warningmsg) { var request = JsonConvert.DeserializeObject <DTUStatusChangedMsg>(warningmsg.Msg); if (request == null) { return(0); } logger.InfoFormat("DTU{0}在 {1} {2}", request.DTUID, request.TimeStatusChanged.ToString("F"), request.IsOnline ? "上线" : "下线"); int rowcount; if (_toClient == "true") { rowcount = DbAccessor.UpdateDtuState(request, 4, 3); } else { rowcount = DbAccessor.UpdateDtuState(request, 1, 1); } //return DbAccessor.UpdateDtuState(request); return(rowcount); }