Exemple #1
0
        /// <summary>
        /// 向Ap发送Main模块过来的消息
        /// </summary>
        /// <param name="MainMsg"></param>
        private void Send2ap_RecvMainMsg(InterModuleMsgStruct MainMsg)
        {
            AsyncUserToken apToKen = MyDeviceList.FindByApInfo(MainMsg.ApInfo);

            if (apToKen == null)
            {
                OnOutputLog(LogInfoType.WARN, string.Format("在线AP列表中找不到Ap[{0}:{1}]设备({2})!",
                                                            MainMsg.ApInfo.IP, MainMsg.ApInfo.Port.ToString(), MainMsg.ApInfo.Fullname));
                return;
            }

            MsgId2App msgId2App = new MsgId2App();

            msgId2App.id      = ApMsgIdClass.addNormalMsgId();
            msgId2App.AppInfo = MainMsg.AppInfo;

            if (!MyDeviceList.AddMsgId2App(apToKen, msgId2App))
            {
                OnOutputLog(LogInfoType.EROR, string.Format("添加消息Id到设备列表出错!"));
                Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type,
                                      string.Format("添加消息Id到设备列表出错!"));
                return;
            }

            if (!SendMsg2Ap(apToKen, msgId2App.id, MainMsg.Body))
            {
                Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type,
                                      string.Format("封装向AP发送的XML消息({0})出错!", MainMsg.Body.type));
            }
        }
Exemple #2
0
        /// <summary>
        /// 增加一条消息Id与App信息对应关系
        /// </summary>
        /// <param name="toKen">Ap信息</param>
        /// <param name="msgId2App">id与App对应关系</param>
        /// <returns>成功:true ;失败:false</returns>
        public bool AddMsgId2App(AsyncUserToken toKen, MsgId2App msgId2App)
        {
            lock (locker1)
            {
                DeviceDicKey dicKey = new DeviceDicKey(toKen.IPAddress.ToString(), toKen.Port);

                if (connList.ContainsKey(dicKey))
                {
                    msgId2App.AddTime = DateTime.Now;
                    connList[dicKey].msgId2App.Add(msgId2App);
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
 /// <summary>
 /// 增加一条消息Id与App信息对应关系
 /// </summary>
 /// <param name="toKen">Ap信息</param>
 /// <param name="msgId2App">id与App对应关系</param>
 /// <returns>成功:true ;失败:false</returns>
 public bool AddMsgId2App(AsyncUserToken toKen, MsgId2App msgId2App)
 {
     lock (locker1)
     {
         foreach (AsyncUserToken x in connList)
         {
             if (CompApInfo(x, toKen))
             {
                 msgId2App.AddTime = DateTime.Now;
                 x.msgId2App.Add(msgId2App);
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #4
0
        /// <summary>
        /// 透传MainController模块过来的消息给设备
        /// </summary>
        /// <param name="MainMsg"></param>
        private void Send2ap_TransparentMsg(InterModuleMsgStruct MainMsg)
        {
            AsyncUserToken apToKen = MyDeviceList.FindByApInfo(MainMsg.ApInfo);

            if (apToKen == null)
            {
                OnOutputLog(LogInfoType.WARN, string.Format("在线AP列表中找不到Ap[{0}:{1}]设备({2})!",
                                                            MainMsg.ApInfo.IP, MainMsg.ApInfo.Port.ToString(), MainMsg.ApInfo.Fullname));
                return;
            }

            string sendMsg = GetMsgStringValueInList("transparent_msg", MainMsg.Body);

            if (string.IsNullOrEmpty(sendMsg))
            {
                OnOutputLog(LogInfoType.EROR, string.Format("透传XML消息为空!"));
                Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type,
                                      string.Format("透传XML消息为空!"));
                return;
            }

            if (!Regex.IsMatch(sendMsg, "<\\s*id\\s*>.+<\\s*/\\s*id\\s*>"))
            {
                OnOutputLog(LogInfoType.EROR, string.Format("透传的XML消息中没有id项!"));
                Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type,
                                      string.Format("透传的XML消息中没有id项!"));
                return;
            }
            UInt16 id = ApMsgIdClass.addTransparentMsgId();

            sendMsg = Regex.Replace(sendMsg, "<\\s*id\\s*>.+<\\s*/\\s*id\\s*>", string.Format("<id>{0}</id>", id));

            MsgId2App msgId2App = new MsgId2App();

            msgId2App.id      = id;
            msgId2App.AppInfo = MainMsg.AppInfo;

            if (!MyDeviceList.AddMsgId2App(apToKen, msgId2App))
            {
                OnOutputLog(LogInfoType.EROR, string.Format("添加消息Id到设备列表出错!"));
                Send2APP_GeneralError(MainMsg.ApInfo, MainMsg.AppInfo, MainMsg.Body.type,
                                      string.Format("添加消息Id到设备列表出错!"));
                return;
            }

            SendMsg2Ap(apToKen, MainMsg.Body.type, sendMsg);
        }