/// <summary> /// 向APP返回通用错误消息 /// </summary> /// <param name="appToken">app信息</param> /// <param name="type">app发送过来的消息类型</param> /// <param name="str">错误描述</param> protected void Send2APP_GeneralError(AsyncUserToken appToken, string type, string str) { MessageType mt = MessageType.MSG_JSON; MessageBody mb = new MessageBody(); InterModuleMsgStruct msg = new InterModuleMsgStruct(); msg.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); msg.MsgType = MsgStruct.MsgType.CONFIG.ToString(); msg.ApInfo = null; msg.AppInfo.Type = string.Empty; msg.AppInfo.Ip = appToken.IPAddress.ToString(); msg.AppInfo.Port = appToken.Port; msg.AppInfo.Group = appToken.Group; msg.AppInfo.User = appToken.User; msg.AppInfo.Domain = appToken.Domain; Msg_Body_Struct TypeKeyValue = new Msg_Body_Struct(AppMsgType.general_error_result, "ErrStr", str, "RecvType", type); msg.Body = TypeKeyValue; mb.bJson = JsonConvert.SerializeObject(msg); OnOutputLog(LogInfoType.INFO, string.Format("发送消息({0})给MainController模块!", TypeKeyValue.type), LogCategory.S); OnOutputLog(LogInfoType.DEBG, string.Format("消息内容:\n{0}", mb.bJson), LogCategory.S); ApManager.sendMsg_2_MainController(mt, mb); }
protected void Send2APP_GeneralError(Ap_Info_Struct apInfo, App_Info_Struct appInfo, string type, string str) { MessageType mt = MessageType.MSG_JSON; MessageBody mb = new MessageBody(); InterModuleMsgStruct msg = new InterModuleMsgStruct(); msg.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); msg.MsgType = MsgStruct.MsgType.CONFIG.ToString(); msg.ApInfo = apInfo; msg.AppInfo = appInfo; Msg_Body_Struct TypeKeyValue = new Msg_Body_Struct(AppMsgType.general_error_result, "ErrStr", str, "RecvType", type); msg.Body = TypeKeyValue; mb.bJson = JsonConvert.SerializeObject(msg); OnOutputLog(LogInfoType.INFO, string.Format("发送消息({0})给MainController模块!", TypeKeyValue.type), LogCategory.S); OnOutputLog(LogInfoType.DEBG, string.Format("消息内容:\n{0}", mb.bJson), LogCategory.S); ApManager.sendMsg_2_MainController(mt, mb); //OnReceiveMainMsg(mt, mb); }
/// <summary> /// 检测数所库保存的Ap上下线状态是否正确,若不正确,向其发送正状态 /// </summary> /// <param name="status">数据库保存状态</param> /// <param name="apToKen">ap信息</param> protected void Send2main_OnOffLineCheck(string status, Ap_Info_Struct ApInfo) { string MainControllerStatus = OffLine; AsyncUserToken apToKen = MyDeviceList.FindByIpPort(ApInfo.IP, ApInfo.Port); if (apToKen == null) { apToKen = MyDeviceList.FindByFullname(ApInfo.Fullname); } if (apToKen == null) { MainControllerStatus = OffLine; } else { MainControllerStatus = apToKen.MainControllerStatus; } OnOutputLog(LogInfoType.DEBG, "保存的状态为:" + MainControllerStatus + ";接收到状态为:" + status); if (String.Compare(MainControllerStatus, status, true) != 0) { Msg_Body_Struct TypeKeyValue = new Msg_Body_Struct(Main2ApControllerMsgType.OnOffLine, "AllOnLineNum", MyDeviceList.GetCount().ToString(), "Status", MainControllerStatus, "mode", apToKen.Mode, "timestamp", DateTime.Now.ToLocalTime().ToString()); //向Main模块发消息 MessageType mt = MessageType.MSG_JSON; MessageBody mb = new MessageBody(); InterModuleMsgStruct msg = new InterModuleMsgStruct(); msg.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); msg.MsgType = MsgStruct.MsgType.NOTICE.ToString(); msg.ApInfo = ApInfo; App_Info_Struct appInfo = new App_Info_Struct(); appInfo.Ip = AllDevice; msg.AppInfo = appInfo; msg.Body = TypeKeyValue; mb.bJson = JsonConvert.SerializeObject(msg); OnOutputLog(LogInfoType.INFO, string.Format("发送消息({0})给MainController模块!", TypeKeyValue.type), LogCategory.S); OnOutputLog(LogInfoType.DEBG, string.Format("消息内容:\n{0}", mb.bJson), LogCategory.S); ApManager.sendMsg_2_MainController(mt, mb); } }
/// <summary> /// 发送消息给MainController模块 /// </summary> /// <param name="msgId">Ap返回的消息Id</param> /// <param name="msgType">Main模块消息类型</param> /// <param name="apToKen">Ap信息</param> /// <param name="TypeKeyValue">消息内容</param> public void OnSendMsg2Main(UInt16 msgId, MsgStruct.MsgType msgType, AsyncUserToken apToKen, Msg_Body_Struct TypeKeyValue) { MessageType mt = MessageType.MSG_JSON; MessageBody mb = new MessageBody(); InterModuleMsgStruct msg = new InterModuleMsgStruct(); msg.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); msg.MsgType = msgType.ToString(); msg.ApInfo.SN = apToKen.Sn; msg.ApInfo.Fullname = apToKen.FullName; msg.ApInfo.IP = apToKen.IPAddress.ToString(); msg.ApInfo.Port = apToKen.Port; msg.ApInfo.Type = DeviceType; App_Info_Struct appInfo = new App_Info_Struct(); if ((msgType == MsgType.NOTICE) || (msgId == 0)) { appInfo.Ip = AllDevice; } else { //通过消息id查找AppInfo AsyncUserToken ListToken = MyDeviceList.FindByIpPort(apToKen.IPAddress.ToString(), apToKen.Port); if (ListToken == null) { String str = string.Format( "未找到设备[{0}:{1}]消息ID({2})对应的APP信息,不发送消息给MainController模块!", apToKen.IPAddress.ToString(), apToKen.Port, msgId); OnOutputLog(LogInfoType.EROR, str); return; } HashSet <MsgId2App> msgId2App = new HashSet <MsgId2App>(); msgId2App = ListToken.msgId2App; foreach (MsgId2App x in msgId2App) { if (x.id == msgId) { appInfo = x.AppInfo; break; } } //删除保存的消息Id列表(目前实现的方法是120秒后自动删除) //MyDeviceList.RemoveMsgId2App(apToKen, msgId); } if (string.IsNullOrEmpty(appInfo.Ip)) { String str = string.Format( "未找到设备[{0}:{1}]消息ID({2})对应的APP信息,不发送消息给MainController模块!", apToKen.IPAddress.ToString(), apToKen.Port, msgId); OnOutputLog(LogInfoType.EROR, str); return; } msg.AppInfo = appInfo; msg.Body = TypeKeyValue; mb.bJson = JsonConvert.SerializeObject(msg); //当设备状态为在线时再发送消息给Main模块 if ((String.Compare(MyDeviceList.GetMainControllerStatus(apToKen), OnLine, true) != 0) && (!TypeKeyValue.type.Equals(Main2ApControllerMsgType.OnOffLine))) { OnOutputLog(LogInfoType.WARN, string.Format("设备[{0}:{1}]在线状态为:{2},OnLine状态才向Main模块发送消息{3}!", apToKen.IPAddress.ToString(), apToKen.Port.ToString(), MyDeviceList.GetMainControllerStatus(apToKen), TypeKeyValue.type)); if (TypeKeyValue.type == ApMsgType.scanner) { noSendMainImsiNum++; } return; } if (TypeKeyValue.type == ApMsgType.scanner) { sendMainImsiMsgNum++; } OnOutputLog(LogInfoType.INFO, string.Format("发送消息({0})给MainController模块!", TypeKeyValue.type), LogCategory.S); OnOutputLog(LogInfoType.DEBG, string.Format("消息内容:\n{0}", mb.bJson), LogCategory.S); ApManager.sendMsg_2_MainController(mt, mb); }