Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 发送消息到App
        /// </summary>
        /// <param name="appInfo">Ap信息</param>
        /// <param name="stdeviceServerMsgStructr">消息内容</param>
        protected void SendMsg2App(App_Info_Struct appInfo, DeviceServerMsgStruct deviceServerMsgStruct)
        {
            try
            {
                if ((string.IsNullOrEmpty(appInfo.Ip)) || (appInfo.Ip == MsgStruct.NullDevice))
                {
                    OnOutputLog(LogInfoType.INFO, string.Format("目的设备为Null,不向App发送信息!"));
                    return;
                }

                if (deviceServerMsgStruct.Body.type == ApMsgType.scanner)
                {
                    sendAppImsiMsgNum++;
                }

                string strJosn = JsonConvert.SerializeObject(deviceServerMsgStruct);
                byte[] buff    = System.Text.Encoding.Default.GetBytes(strJosn);

                if (appInfo.Ip == MsgStruct.AllDevice)
                {
                    OnOutputLog(LogInfoType.INFO, string.Format("目的设备为All,向所有App发送信息!"));
                    //HashSet<AsyncUserToken>  toKenList = MyDeviceList.GetConnList();
                    AsyncUserToken[] toKenList = MyDeviceList.GetConnListToArray();
                    if (toKenList.Length > 0)
                    {
                        foreach (AsyncUserToken appToKen in toKenList)
                        {
                            OnOutputLog(LogInfoType.INFO, string.Format("发送消息({0})给APP[{1}:{2}]!",
                                                                        deviceServerMsgStruct.Body.type, appToKen.IPAddress, appToKen.Port), LogCategory.S);
                            OnOutputLog(LogInfoType.DEBG, string.Format("消息内容:\n{0}", strJosn), LogCategory.S);
                            MySocket.SendMessage(appToKen, buff);
                        }
                    }
                }
                else
                {
                    AsyncUserToken appToKen = MyDeviceList.FindByIpPort(appInfo.Ip, appInfo.Port);
                    if (appToKen == null)
                    {
                        OnOutputLog(LogInfoType.WARN, string.Format("设备列表中未找到该App设备[{0}:{1}]信息!", appInfo.Ip, appInfo.Port));
                        return;
                    }

                    OnOutputLog(LogInfoType.INFO, string.Format("发送消息({0})给APP[{1}:{2}]!",
                                                                deviceServerMsgStruct.Body.type, appToKen.IPAddress, appToKen.Port), LogCategory.S);
                    OnOutputLog(LogInfoType.DEBG, string.Format("消息内容:\n{0}", strJosn), LogCategory.S);
                    MySocket.SendMessage(appToKen, buff);
                }

                buff    = null;
                strJosn = null;
            }
            catch (Exception ee)
            {
                OnOutputLog(LogInfoType.EROR, "发送消息到App出错。出错原因:" + ee.Message, LogCategory.I);
            }

            return;
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        /// <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);
        }