예제 #1
0
 /// <summary>
 /// 针对响应数据回调处理
 /// </summary>
 /// <param name="cmConOpt"></param>
 /// <param name="command"></param>
 private static void RespCallBack(CmppConnectionOption cmConOpt, CmppCommand command)
 {
     //LogUtil.Info("接收运营商响应信息", command, CompModuleLogs.SmsExchangeRespLog);
     if (command.Response.MsgHeader.CommandType == CommandType.ConnectResp)
     {
         var resp = command.Response as ConnectResp;
         if (resp != null)
         {
             var result = resp.GetResult();
             if (result.Ret == ResultTypes.Success)
             {
                 LogUtil.Info("建立连接成功!", "connect_success");
             }
             else
             {
                 LogUtil.Info(result.Message, "connect_failed");
             }
         }
     }
     else if (command.Response.MsgHeader.CommandType != CommandType.ActiveTestResp &&
              command.Response.MsgHeader.CommandType != CommandType.ActiveTest)
     {
         if (cmConOpt.CallBack != null)
         {
             AsynUtil.Asyn(obj =>
             {
                 var com = obj.Item2;
                 var opt = obj.Item1;
                 opt.CallBack(com);
             }, Tuple.Create(cmConOpt, command));
         }
     }
 }
예제 #2
0
        /// <summary>
        ///   读处理
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="cmConOpt"></param>
        private static void ReadSocketResp(Socket socket, CmppConnectionOption cmConOpt)
        {
            try
            {
                var resp = GetSocketResp(socket);

                // 1.  获取上次发送请求command
                CmppCommand command = null;
                if (cmConOpt.WaitingCommand.ContainsKey(resp.MsgHeader.SequenceId))
                {
                    command = cmConOpt.WaitingCommand[resp.MsgHeader.SequenceId];
                    cmConOpt.WaitingCommand.Remove(resp.MsgHeader.SequenceId);
                }
                else
                {
                    command = new CmppCommand();
                }
                command.Response = resp;

                //  2. 激活测试
                if (resp.MsgHeader.CommandType == CommandType.ActiveTest)
                {
                    //  对方发送activetest   给出响应
                    cmConOpt.CommandQueue.Enqueue(new CmppCommand()
                    {
                        Request = new ActiveTestResp(resp.MsgHeader.SequenceId)
                    });
                }
                //  3. 连接结果响应
                else if (resp.MsgHeader.CommandType == CommandType.ConnectResp)
                {
                    var conResp = resp as ConnectResp;
                    cmConOpt.ConnectedStatu = conResp.Status == 0 ? ConnectionStatu.Success : ConnectionStatu.Failed;
                }

                // 4.  对响应设置回调处理
                RespCallBack(cmConOpt, command);
            }
            catch (Exception ex)
            {
                LogUtil.Info("接收运营商响应信息时出错", "sendreq_error");
#if DEBUG
                throw ex;
#endif
            }
        }
예제 #3
0
        /// <summary>
        ///  发送命令
        /// </summary>
        /// <param name="req"></param>
        public bool Send(BaseMsg req)
        {
            if (req.MsgHeader.CommandType == CommandType.Connect)
            {
                return(false);
            }

            req.MsgHeader.SequenceId = GetNextSequenceId();

            var command = new CmppCommand()
            {
                Request = req
            };

            Option.CommandQueue.Enqueue(command);

            return(true);
        }