コード例 #1
0
ファイル: AppManager.cs プロジェクト: jiangboh/CS
        /// <summary>
        /// 向AP发送透传消息
        /// </summary>
        /// <param name="appToKen"></param>
        /// <param name="ApInfo"></param>
        /// <param name="TypeKeyValue"></param>
        protected void OnSendTransparentMsg2Main(AsyncUserToken appToKen, Ap_Info_Struct ApInfo, 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.TRANSPARENT.ToString();

            msg.AppInfo.User   = appToKen.User;
            msg.AppInfo.Group  = appToKen.Group;
            msg.AppInfo.Domain = appToKen.Domain;
            msg.AppInfo.Ip     = appToKen.IPAddress.ToString();
            msg.AppInfo.Port   = appToKen.Port;
            msg.AppInfo.Type   = DeviceType;

            msg.ApInfo = ApInfo;

            string sData = GetMsgStringValueInList("transparent_msg", TypeKeyValue);
            //sData = Regex.Replace(sData, "<\\s*id\\s*>.+<\\s*/\\s*id\\s*>", string.Format("<id>{0}</id>", ApMsgIdClass.addTransparentMsgId()));
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("transparent_msg", sData);

            TypeKeyValue.dic = dic;
            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);

            AppManager.sendMsg_2_MainController(mt, mb);
        }
コード例 #2
0
ファイル: AppManager.cs プロジェクト: jiangboh/CS
        /// <summary>
        /// 发送消息到MainContrller模块
        /// </summary>
        /// <param name="appToKen">App连接信息</param>
        /// <param name="ApInfo">Ap信息</param>
        /// <param name="TypeKeyValue">发送内容</param>
        protected void OnSendMsg2Main(AsyncUserToken appToKen, Ap_Info_Struct ApInfo, 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.CONFIG.ToString();

            msg.AppInfo.User   = appToKen.User;
            msg.AppInfo.Group  = appToKen.Group;
            msg.AppInfo.Domain = appToKen.Domain;
            msg.AppInfo.Ip     = appToKen.IPAddress.ToString();
            msg.AppInfo.Port   = appToKen.Port;
            msg.AppInfo.Type   = DeviceType;

            msg.ApInfo = ApInfo;

            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);

            AppManager.sendMsg_2_MainController(mt, mb);
        }
コード例 #3
0
        protected void Send2APP_GeneralError(Ap_Info_Struct apInfo, 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 = apInfo;

            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);
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        /// <summary>
        /// 根据apinfo查询apToKen信息。首先通过ip+Prot查询,若查不到,再通过fullname查询
        /// </summary>
        /// <param name="ApInfo">apinfo信息</param>
        /// <returns>apToKen信息,若未找到,返回null</returns>
        public AsyncUserToken FindByApInfo(Ap_Info_Struct ApInfo)
        {
            AsyncUserToken apToKen = this.FindByIpPort(ApInfo.IP, ApInfo.Port);

            if (apToKen == null)
            {
                Xml_codec.StaticOutputLog(LogInfoType.DEBG,
                                          string.Format("在线AP列表中找不到Ap[{0}:{1}]设备,通过FullName重新查询设备!",
                                                        ApInfo.IP, ApInfo.Port.ToString()),
                                          "DeviceList");
                apToKen = this.FindByFullname(ApInfo.Fullname);
            }

            if (apToKen == null)
            {
                Xml_codec.StaticOutputLog(LogInfoType.WARN,
                                          string.Format("在线AP列表中找不到Ap[{0}:{1}],FullName:{2}。无法向AP发送消息!",
                                                        ApInfo.IP, ApInfo.Port.ToString(), ApInfo.Fullname),
                                          "DeviceList");
            }

            return(apToKen);
        }