Пример #1
0
 public void SendSMSOTP()
 {
     try
     {
         ThreadPool.SetMaxThreads(100, int.MaxValue);
         while (true)
         {
             QueueServiceProvider provider = new QueueServiceProvider();
             List <QueueService>  listSend = provider.GetByPriority(ConfigType.QueueService_Priority_OTP);
             if (listSend.Count > 0)
             {
                 List <ManualResetEvent> handles = new List <ManualResetEvent>();
                 while (listSend.Count > 0)
                 {
                     ManualResetEvent handle = new ManualResetEvent(false);
                     CSendSMS         srv    = new CSendSMS(handle);
                     handles.Add(handle);
                     List <QueueService> tmp = new List <QueueService>();
                     if (listSend.Count > NUMBER_TAKE)
                     {
                         tmp.AddRange(listSend.Take(NUMBER_TAKE).ToList());
                         listSend.RemoveRange(0, NUMBER_TAKE);
                     }
                     else
                     {
                         tmp.AddRange(listSend);
                         listSend.RemoveRange(0, listSend.Count);
                     }
                     ThreadPool.QueueUserWorkItem(srv.SendSMSFormList, tmp);
                 }
                 WaitHandle.WaitAll(handles.ToArray());
             }
             Thread.Sleep(10);
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex);
         Thread.Sleep(1000);
         SendSMSOTP();
     }
 }
Пример #2
0
        public string SendMT(string xmlreq)
        {
            logger.Info("xmlreq befor:" + xmlreq);
            xmlreq = Server.HtmlDecode(xmlreq);
            logger.Info("xmlreq after:" + xmlreq);
            SMSRS response = new SMSRS();

            try
            {
                SMSRQ request = ConvertXML.XMLToModel <SMSRQ>(xmlreq);
                response.HEADER = new HEADERRES()
                {
                    DEST      = request.HEADER.DEST,
                    PWD       = request.HEADER.PWD,
                    SOURCE    = request.HEADER.SOURCE,
                    TRANSID   = request.HEADER.TRANSID,
                    TRANSTIME = request.HEADER.TRANSTIME,
                    USER      = request.HEADER.USER,
                };
                if (ValidateUser.CheckUser(request.HEADER.USER, request.HEADER.PWD))
                {
                    DateTime             transTime = DateTime.ParseExact(request.HEADER.TRANSTIME, "yyyyMMddHHmmss", null);
                    QueueServiceProvider provider  = new QueueServiceProvider();
                    EncryptAndDecrypt    ead       = new EncryptAndDecrypt();
                    foreach (var item in request.DATA.SMS)
                    {
                        QueueService model = new QueueService()
                        {
                            Content        = item.CONTENT,
                            Dest           = request.HEADER.DEST,
                            Password       = request.HEADER.PWD,
                            Priority       = item.PRIORITY,
                            ProcessingCode = item.PROCESSINGCODE,
                            Receiver       = item.RECEIVER,
                            Source         = request.HEADER.SOURCE,
                            TransID        = request.HEADER.TRANSID,
                            TransTime      = transTime,
                            DateCreate     = DateTime.Now,
                            User           = request.HEADER.USER,
                            SMSID          = item.SMSID
                        };
                        provider.Insert(model);
                    }
                    response.DATA = new DATARES()
                    {
                        ERROR = new ERRORRES()
                        {
                            ERRCODE = ConfigType.RS_SUCCESS,
                            ERRDESC = ConfigType.RS_SUCCESS_MESS
                        }
                    };
                }
                else
                {
                    response.DATA = new DATARES()
                    {
                        ERROR = new ERRORRES()
                        {
                            ERRCODE = ConfigType.RS_PASSWORD_FAIL,
                            ERRDESC = ConfigType.RS_PASSWORD_FAIL_MESS
                        }
                    };
                }
            }
            catch (Exception ex)
            {
                response.DATA = new DATARES()
                {
                    ERROR = new ERRORRES()
                    {
                        ERRCODE = ConfigType.RS_SYSTEM_ERROR,
                        ERRDESC = ConfigType.RS_SYSTEM_ERROR_MESS
                    }
                };
                logger.Error(ex);
            }
            string responseXML = ConvertXML.ModelToXMLString <SMSRS>(response);

            logger.Info("Response: " + responseXML);
            //ResultModel result = new ResultModel()
            //{
            //    xmlres = Server.UrlEncode(responseXML),
            //};
            //return result;
            return(Server.HtmlEncode(responseXML));
        }
Пример #3
0
        public void SendSMSFormList(object obj)
        {
            try
            {
                List <QueueService>   listSend      = (List <QueueService>)obj;
                MTQueueReportProvider providerMTR   = new MTQueueReportProvider();
                MTProvider            providerMT    = new MTProvider();
                QueueServiceProvider  qsProvider    = new QueueServiceProvider();
                EncryptAndDecrypt     ead           = new EncryptAndDecrypt();
                SubTelcoProvider      stProvider    = new SubTelcoProvider();
                RouteTelcoProvider    routeProvider = new RouteTelcoProvider();
                while (listSend != null && listSend.Count > 0)
                {
                    //string str_result = "0:NONE_ROUTE";
                    QueueService model = listSend[0];
                    //if(model.Receiver.Contains("904993309") || model.Receiver.Contains("988018028"))
                    //{
                    //    str_result = SendSMS(model, false, ead, stProvider, routeProvider);
                    //}
                    string str_result = SendSMS(model, false, ead, stProvider, routeProvider);
                    var    results    = str_result.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    int    result     = Convert.ToInt32(results[0]);
                    if (result == 501 || result == 502 || result == 503 || result == 555)
                    {
                        //FAIL
                        MT mt = new MT()
                        {
                            Content        = model.Content,
                            DateCreate     = model.DateCreate,
                            Dest           = model.Dest,
                            Password       = model.Password,
                            Priority       = model.Priority,
                            ProcessingCode = model.ProcessingCode,
                            Receiver       = model.Receiver,
                            Source         = model.Source,
                            Status         = ConfigType.MT_STATUS_NOT_NOTIFY_ERROR,
                            TimeSend       = DateTime.Now,
                            TransID        = model.TransID,
                            TransTime      = model.TransTime,
                            User           = model.User,
                            Result         = result,
                            SMSID          = model.SMSID,
                            RouteName      = results[1]
                        };
                        providerMT.Insert(mt);
                    }
                    else
                    {
                        //SUCCESS
                        MTQueueReport mt = new MTQueueReport()
                        {
                            Content        = model.Content,
                            DateCreate     = model.DateCreate,
                            Dest           = model.Dest,
                            Password       = model.Password,
                            Priority       = model.Priority,
                            ProcessingCode = model.ProcessingCode,
                            Receiver       = model.Receiver,
                            Source         = model.Source,
                            Status         = ConfigType.MT_STATUS_NOT_NOTIFY,
                            TimeSend       = DateTime.Now,
                            TransID        = model.TransID,
                            TransTime      = model.TransTime,
                            User           = model.User,
                            Result         = result,
                            SMSID          = model.SMSID,
                            RouteName      = results[1]
                        };
                        providerMTR.Insert(mt);
                    }
                    logger.Info("SendSMS [" + results[1] + "] : " + model.Receiver + " | " + model.Content + " | " + result);
                    listSend.RemoveAt(0);
                    qsProvider.DeleteById(model.Id);

                    Thread.Sleep(10);
                }
                _doneEvent.Set();
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                _doneEvent.Set();
                Thread.Sleep(1000);
                //SendSMSFormList(listSend);
            }
        }