예제 #1
0
        private void smppclient_DeliverEvent(string mobile_no, string short_no, string text_message, string text_language)
        {
            if (mobile_no.StartsWith("967"))
            {
                mobile_no = mobile_no.Substring(3);
            }
            if (short_no.StartsWith("967"))
            {
                short_no = short_no.Substring(3);
            }

            // Commit comming message ...
            try
            {
                Regex re = new Regex("[;\\/:*?\"<>|&']");
                text_message = re.Replace(text_message, string.Empty);

                RegexOptions options = RegexOptions.None;
                Regex        regex   = new Regex("[ ]{2,}", options);
                text_message = regex.Replace(text_message, " ");



                var SMSReception = new SMSIn();
                SMSReception.Sender   = mobile_no;
                SMSReception.Receiver = short_no;
                SMSReception.Message  = text_message;
                SMSReception.Lang     = text_language;
                new SMSInRepo(db).Create(SMSReception);
            }
            catch (Exception ex)
            {
                CurrentLogMessage c = new CurrentLogMessage("", SharedParams.Short_Code.ToString(), "", "Exception in deliver event when trying commit comming message[" + ex.Message + "]", "error");
                WriteLog(c);
            }
            //---------------------------------------------------------
            try
            {
                if (short_no == SharedParams.Short_Code.ToString() && mobile_no.StartsWith("70"))
                {
                    DeliverMessage.Delivered_Message DelMsg = new DeliverMessage.Delivered_Message(mobile_no, short_no, text_message, text_language, CurrentInterface.Channel);
                    CurrentLogMessage c = new CurrentLogMessage("R", short_no, mobile_no, text_message, "deliver");
                    WriteLog(c);
                    if (SharedParams.Application_Status == "stop")
                    {
                        CurrentLogMessage c1 = new CurrentLogMessage("S", short_no, mobile_no, SharedParams.Application_Stop_Message, "sender");
                        WriteLog(c1);

                        var ReplayMessage = new SMSOut();
                        ReplayMessage.Message  = SharedParams.Application_Stop_Message;
                        ReplayMessage.Receiver = mobile_no;
                        bool res = new OutSMSRepo(db).Create(ReplayMessage).Success;
                        if (res == false)
                        {
                            CurrentLogMessage c2 = new CurrentLogMessage("", short_no, mobile_no, "could NOT create message [" + SharedParams.Application_Stop_Message + "]", "error");
                            WriteLog(c2);
                        }
                    }
                    else
                    {
                        bw_Delivery = new BackgroundWorker();
                        bw_Delivery.WorkerReportsProgress      = true;
                        bw_Delivery.WorkerSupportsCancellation = true;
                        bw_Delivery.DoWork             += new DoWorkEventHandler(bw_Delivery_DoWork);
                        bw_Delivery.ProgressChanged    += new ProgressChangedEventHandler(bw_Delivery_ProgressChanged);
                        bw_Delivery.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_Delivery_RunWorkerCompleted);
                        if (bw_Delivery.IsBusy != true)
                        {
                            bw_Delivery.RunWorkerAsync(DelMsg);
                        }
                        else
                        {
                            string            Msg = "عذرا النظام مشغول بمعالجة طلب اخر يرجى المحاولة لاحقا";
                            CurrentLogMessage c1  = new CurrentLogMessage("S", short_no, mobile_no, Msg, "sender");
                            WriteLog(c1);
                            var ReplayMessage = new SMSOut();
                            ReplayMessage.Message  = Msg;
                            ReplayMessage.Receiver = mobile_no;
                            bool res = new OutSMSRepo(db).Create(ReplayMessage).Success;
                            if (res == false)
                            {
                                CurrentLogMessage c2 = new CurrentLogMessage("", short_no, mobile_no, "could NOT create message [" + Msg + "]", "error");
                                WriteLog(c2);
                            }
                        }
                    }
                }
                else
                {
                    CurrentLogMessage c = new CurrentLogMessage("R", short_no, mobile_no, text_message, "invaliddeliver");
                    WriteLog(c);
                }
            }
            catch (Exception ex)
            {
                CurrentLogMessage c = new CurrentLogMessage("", SharedParams.Short_Code.ToString(), "", "Exception in deliver event [" + ex.Message + "]", "error");
                WriteLog(c);
            }
        }
예제 #2
0
        private void bw_Delivery_DoWork(object sender, DoWorkEventArgs e)
        {       // Delivered message start parsing ...
            try
            {
                bool res;

                CurrentLogMessage c2 = null;
                DeliverMessage.Delivered_Message delmsg = (DeliverMessage.Delivered_Message)e.Argument;
                if (delmsg.Short_code == SharedParams.Short_Code.ToString())
                {
                    DeliverMessage DeliverMsg = new DeliverMessage(db, partnerManager, partnerActivityRepo, _logger);
                    DeliverMessage.RequestReturnValue RQretuenvalue = new DeliverMessage.RequestReturnValue();
                    var RQpack  = new PartnerRequest();
                    var queueNo = getCurrentChannelNo();
                    RQretuenvalue = DeliverMsg.Parse_Request(delmsg, queueNo, out RQpack);
                    if (RQretuenvalue.Ret_Status == true)
                    {
                        c2 = new CurrentLogMessage("", SharedParams.Short_Code.ToString(), RQpack.MobileNo,
                                                   RQpack.RequestName + " - " + RQpack.Shortcode + " - " + RQpack.ReplayDesc + " success (" + RQpack.Id + ") Q(" + queueNo + ")", "partnerok");
                        bw_Delivery.ReportProgress(0, c2);
                        if (RQpack.RequestId == 3)
                        {
                            var result = new PartnerRequestRepo(db).Create(RQpack);
                        }
                    }
                    else
                    {
                        if (RQretuenvalue.Ret_ID == -1)
                        {
                            CurrentLogMessage c = new CurrentLogMessage("S", SharedParams.Short_Code.ToString(), RQpack.MobileNo, RQretuenvalue.Ret_Message_to_Client, "partnererror");
                            e.Result = c;
                            var BadRequest = new PartnerRequest();
                            BadRequest.MobileNo      = RQpack.MobileNo;
                            BadRequest.Shortcode     = SharedParams.Short_Code.ToString();
                            BadRequest.Content       = RQpack.Content;
                            BadRequest.Error         = RQretuenvalue.Ret_Message;
                            BadRequest.AccessChannel = "sms";
                            BadRequest.QueueNo       = 1;
                            BadRequest.RequestId     = RQpack.RequestId;
                            BadRequest.ReplayDesc    = RQretuenvalue.Ret_Message_to_Client;
                            BadRequest.ReplayTime    = DateTime.Now;
                            BadRequest.Status        = 2;

                            res = (new PartnerRequestRepo(db).Create(BadRequest).Success);

                            if (res == false)
                            {
                                c2       = new CurrentLogMessage("", SharedParams.Short_Code.ToString(), RQpack.MobileNo, "failed to create bad request [" + RQretuenvalue.Ret_Message_to_Client + "]", "error");
                                e.Result = c2;
                            }
                            if (!string.IsNullOrEmpty(RQretuenvalue.Ret_Message_to_Client))
                            {
                                var outmessage = new SMSOut();
                                outmessage.Message  = RQretuenvalue.Ret_Message_to_Client;
                                outmessage.Receiver = RQpack.MobileNo;
                                res = (new OutSMSRepo(db).Create(outmessage).Success);
                                if (res == false)
                                {
                                    c2       = new CurrentLogMessage("", SharedParams.Short_Code.ToString(), RQpack.MobileNo, "failed to create sms to client [" + RQretuenvalue.Ret_Message_to_Client + "]", "error");
                                    e.Result = c2;
                                }
                            }
                        }
                        else if (RQretuenvalue.Ret_ID == -2)
                        {
                            CurrentLogMessage c = new CurrentLogMessage("", SharedParams.Short_Code.ToString(), RQpack.MobileNo, RQretuenvalue.Ret_Message, "partnererror");
                            e.Result = c;
                        }
                    }//res==true
                }
                delmsg = null;
            }
            catch (Exception ex)
            {
                CurrentLogMessage c1 = new CurrentLogMessage("", SharedParams.Short_Code.ToString(), "", ex.Message, "error");
                WriteLog(c1);
            }
        } // bw_Delivery_DoWork