Example #1
0
        public void OnSent(SentEventArgs args)
        {
            Error = args.Result ? 0 : ++Error;
            args.SmsInfo.State = args.Result ? 0 : 1;
            _result.Add(args.SmsInfo);


            EventHandler<SentEventArgs> handler = Sent;
            if (handler != null) handler(this, args);
        }
Example #2
0
        public void OnSent(SentEventArgs args)
        {
            Error = args.Result ? 0 : ++Error;
            args.SmsInfo.State = args.Result ? 0 : 1;
            _result.Add(args.SmsInfo);


            EventHandler <SentEventArgs> handler = Sent;

            if (handler != null)
            {
                handler(this, args);
            }
        }
Example #3
0
        /// <summary>
        /// recursion get message to send.
        /// </summary>
        private void RecursionSend()
        {
            while (_runing && _smsQueue.Count > 0)
            {
                SMSSendInfo smsInfo = _smsQueue.Dequeue();
                //
                System.Console.WriteLine("弹出:{0}", smsInfo);

                string        phone         = smsInfo.Phone;
                string        message       = smsInfo.Message;
                bool          result        = SendMsg(phone, message);
                SentEventArgs sentEventArgs = new SentEventArgs();
                sentEventArgs.SmsInfo = smsInfo;
                if (result)
                {
                    sentEventArgs.Result = true;
                    OnSent(sentEventArgs);
                }
                else
                {
                    if ((++smsInfo.Reply) < _maxReply)
                    {
                        _smsQueue.Enqueue(smsInfo);
                    }
                    else
                    {
                        sentEventArgs.Result = false;
                        OnSent(sentEventArgs);
                    }
                }
                //检查SIM卡信息
                if (_smsQueue.Count == 0)
                {
                    PublishMessage();
                    //wait time set 3000
                    Thread.Sleep(3000);
                }
            }
            _runing = false;
        }
Example #4
0
        /// <summary>
        /// recursion get message to send.
        /// </summary>
        private void RecursionSend()
        {
            while (_runing && _smsQueue.Count > 0)
            {
                SMSSendInfo smsInfo = _smsQueue.Dequeue();
                //
                System.Console.WriteLine("弹出:{0}", smsInfo);

                string phone = smsInfo.Phone;
                string message = smsInfo.Message;
                bool result = SendMsg(phone, message);
                SentEventArgs sentEventArgs = new SentEventArgs();
                sentEventArgs.SmsInfo = smsInfo;
                if (result)
                {
                    sentEventArgs.Result = true;
                    OnSent(sentEventArgs);
                }
                else
                {
                    if ((++smsInfo.Reply) < _maxReply)
                    {
                        _smsQueue.Enqueue(smsInfo);
                    }
                    else
                    {
                        sentEventArgs.Result = false;
                        OnSent(sentEventArgs);
                    }
                }
                //检查SIM卡信息
                if (_smsQueue.Count == 0)
                {
                    PublishMessage();
                    //wait time set 3000
                    Thread.Sleep(3000);
                }
            }
            _runing = false;
        }
        public void OnSent(SentEventArgs args)
        {
            InvokeEventLog(String.Format("状态:{0}:{1}", args.SmsInfo, args.Result));

            _smsQueue.Set(args.SmsInfo, args.Result ? 500 : 501);

            EventHandler<SentEventArgs> handler = Sent;
            if (handler != null) handler(this, args);

            
            #region 故障处理

            //TODO:16:32 2011-12-07 临时代码 // 重新设置 Modem
            if (args.Result == false)
            {
                //设备重置次数
                const int MAX_RESET = 3;

                string com = args.SmsInfo.Com;
                if (_smsPool.ContainsKey(args.SmsInfo.Com))
                {
                    SMSSender smsSender = _smsPool[args.SmsInfo.Com];
                    if (smsSender.HasError)
                    {
                        int reset = ++smsSender.Reset;
                        if (reset < MAX_RESET)
                        {
                            InvokeEventLog(String.Format("重置:{0}", com));

                            Queue<SMSSendInfo> smsSendInfos = smsSender.Stop();

                            foreach (SMSSendInfo sendInfo in _smsPool[com].Result)
                            {
                                if (sendInfo.State == 1)
                                {
                                    smsSendInfos.Enqueue(sendInfo);
                                }
                            }

                            RemoveModem(com);

                           
                            ////Create
                            smsSender = CreateModem(com, 9600);
                            if (smsSender != null)
                            {
                                foreach (SMSSendInfo sendInfo in smsSendInfos)
                                {
                                    args.SmsInfo.State = 0;
                                    //smsSender.AsyncSend(sendInfo);
                                    AsyncSend(sendInfo);
                                }
                                _smsPool[com].Reset = reset;
                            }
                        }
                        else
                        {
                            //drive has a error .
                            InvokeEventLog(String.Format("设备错误:{0}", com));
                            RemoveModem(com);
                        }
                    }

                }
            }
            //TODO:End

            #endregion
        }
 void smsSender_Sent(object o, SentEventArgs sentEventArgs)
 {
     OnSent(sentEventArgs);
 }
Example #7
0
        public void OnSent(SentEventArgs args)
        {
            InvokeEventLog(String.Format("状态:{0}:{1}", args.SmsInfo, args.Result));

            _smsQueue.Set(args.SmsInfo, args.Result ? 500 : 501);

            EventHandler <SentEventArgs> handler = Sent;

            if (handler != null)
            {
                handler(this, args);
            }


            #region 故障处理

            //TODO:16:32 2011-12-07 临时代码 // 重新设置 Modem
            if (args.Result == false)
            {
                //设备重置次数
                const int MAX_RESET = 3;

                string com = args.SmsInfo.Com;
                if (_smsPool.ContainsKey(args.SmsInfo.Com))
                {
                    SMSSender smsSender = _smsPool[args.SmsInfo.Com];
                    if (smsSender.HasError)
                    {
                        int reset = ++smsSender.Reset;
                        if (reset < MAX_RESET)
                        {
                            InvokeEventLog(String.Format("重置:{0}", com));

                            Queue <SMSSendInfo> smsSendInfos = smsSender.Stop();

                            foreach (SMSSendInfo sendInfo in _smsPool[com].Result)
                            {
                                if (sendInfo.State == 1)
                                {
                                    smsSendInfos.Enqueue(sendInfo);
                                }
                            }

                            RemoveModem(com);


                            ////Create
                            smsSender = CreateModem(com, 9600);
                            if (smsSender != null)
                            {
                                foreach (SMSSendInfo sendInfo in smsSendInfos)
                                {
                                    args.SmsInfo.State = 0;
                                    //smsSender.AsyncSend(sendInfo);
                                    AsyncSend(sendInfo);
                                }
                                _smsPool[com].Reset = reset;
                            }
                        }
                        else
                        {
                            //drive has a error .
                            InvokeEventLog(String.Format("设备错误:{0}", com));
                            RemoveModem(com);
                        }
                    }
                }
            }
            //TODO:End

            #endregion
        }
Example #8
0
 void smsSender_Sent(object o, SentEventArgs sentEventArgs)
 {
     OnSent(sentEventArgs);
 }