Esempio n. 1
0
        public ActionResult MT_Handle()
        {
            #region # Get data from QueryString #

            string app_id     = Request.QueryString["app-id"];
            string to         = Request.QueryString["to"];
            string msg        = Request.QueryString["msg"];
            string time       = Request.QueryString["time"];
            string state      = Request.QueryString["state"];
            string error      = Request.QueryString["error"];
            string reason     = Request.QueryString["reason"];
            string retry      = Request.QueryString["retry"];
            string app_msg_id = Request.QueryString["app-msg-id"];

            if (string.IsNullOrEmpty(app_id))
            {
                Log.Error("NOTIFICATION_MT:: app-id is not set!");
                return(new HttpStatusCodeResult(HttpStatusCode.Ambiguous));
            }

            Service service = GetServiceByAppID(app_id);
            if (service == null)
            {
                Log.Error(string.Format("NOTIFICATION_MT:: Service could not be loaded by app_id='{0}'", app_id));
                return(new HttpStatusCodeResult(HttpStatusCode.Ambiguous));
            }

            #endregion

            int?_trackingID = this.TryPxidReportFromPreviousMessage(this.TryFindCustomer(service, to, null));

            #region # Insert/Update messages in database #

            MobiChat.Web.Data.Message       message       = null;
            MobiChat.Web.Data.MessageStatus messageStatus = Web.Data.MessageStatus.Delivered;
            Guid messageReference = Guid.Empty;

            switch (state)
            {
            case "DELIVRD":
                messageStatus = Web.Data.MessageStatus.Delivered;
                if (Guid.TryParse(app_msg_id, out messageReference))
                {
                    message = Message.CreateManager().Load(messageReference);
                }
                break;

            case "UNDELIV":
            case "EXPIRED":
            case "REJECTED":
                messageStatus = Web.Data.MessageStatus.Not_delivered;
                if (Guid.TryParse(app_msg_id, out messageReference))
                {
                    message = Message.CreateManager().Load(messageReference);
                }
                break;
            }

            if (message == null)
            {
                //messageStatus = (string.IsNullOrEmpty(error)) ? Web.Data.MessageStatus.Not_delivered : Web.Data.MessageStatus.Delivered;
                //message = new Message(-1,
                //  Guid.NewGuid(),
                //  this.TryParseInt(app_msg_id),
                //  service,
                //  this.TryFindCustomer(service, to, null),
                //  string.Empty, // operator string
                //  null, // mobileOperator
                //  MobiChat.Web.Data.MessageDirection.Outgoing,
                //  MobiChat.Web.Data.MessageType.MT,
                //  messageStatus,
                //  string.Empty, //text
                //  null, //shortcode,
                //  string.Empty, // keyword
                //  _trackingID,  // trackingID
                //  DateTime.Now, DateTime.Now);
                //message.Insert();
            }

            message.MessageStatus = messageStatus;
            message.Update();

            MTMessage mtMessage = new MTMessage(-1, message, app_id, to, msg, time, state, error, reason, retry, app_msg_id, DateTime.Now, DateTime.Now);
            mtMessage.Insert();
            #endregion

            Log.Info(string.Format("NOTIFICATION_MT:: Success messageID='{0}', mtMessageID={1}", message.ID, mtMessage.ID));
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Esempio n. 2
0
        public virtual bool Send()
        {
            List <Data.Message> oldMessages = Data.Message.CreateManager().Load(this.GetCustomer(), Data.MessageType.MT_Free);

            if (oldMessages.Count > 0)
            {
                Log.Error(string.Format("SendNumber:: Message is not sent due customer allready received it. (to number='{0}') ({1})", this.Msisnd, oldMessages.ElementAt(0).ID));
                this.Status  = false;
                this.Message = this._messageAllreadySent;
                return(false);
            }

            try
            {
                foreach (string message in this.Map.SmsMessages)
                {
                    SendSmsResponse response = this.GetRespone(message) as SendSmsResponse;
                    if (response.Status.Code == MessageStatusCode.Success)
                    {
                        Log.Info(string.Format("SendNumber:: Message successfuly sent. (message='{0} to number='{1}'", message, this.Msisnd));
                        this._smsSent++;
                    }
                    else
                    {
                        Log.Error(string.Format("ISendNumber:: Cashflow returned us error on first message (SubCode='{0}', Message='{1}'",
                                                response.Status.SubCode.ToString(),
                                                response.Status.Message));

                        this.Status  = false;
                        this.Message = this._errorMessage;
                        return(true);
                    }
                }

                #region # Insert messages in database #

                MobiChat.Web.Data.Message dataMessage = new Message(-1,
                                                                    this._refenceGuid,
                                                                    null, /// externalID
                                                                    this._service,
                                                                    this.GetCustomer(),
                                                                    this.MobileOperator.Name,
                                                                    this.MobileOperator,
                                                                    MessageDirection.Outgoing,
                                                                    Web.Data.MessageType.MT_Free,
                                                                    Web.Data.MessageStatus.Sent,
                                                                    this.Map.SmsMessages.FirstOrDefault(),
                                                                    this._serviceConfigurationEntry.Shortcode, // shorcode
                                                                    this._serviceConfigurationEntry.Keyword,   // keyword
                                                                    this.TryGetPxid(),
                                                                    DateTime.Now, DateTime.Now);
                dataMessage.Insert();

                MTMessage mtMessage = new MTMessage(-1,
                                                    dataMessage,
                                                    this._service.ServiceConfiguration.ExternalID,
                                                    this.Msisnd,
                                                    string.Empty,
                                                    DateTime.Now.ToString(),
                                                    "MOBICHAT_WEB",
                                                    string.Empty,                 //error
                                                    string.Empty,                 //reasonCode
                                                    string.Empty,                 //retry
                                                    this._refenceGuid.ToString(), //appMsgID
                                                    DateTime.Now, DateTime.Now);
                mtMessage.Insert();
                #endregion

                this.Status  = true;
                this.Message = this._successMessage;
                return(false);
            }
            catch (Exception e)
            {
                Log.Fatal(string.Format("ISendNumber:: Fatal error on send"), e);
                this.Status  = false;
                this.Message = this._errorMessage;
                return(true);
            }
        }
Esempio n. 3
0
        // SUMMARY: Send Welcome message from ISendMessage manager for specific Service
        public void SendWelcomeMessage(Message message)
        {
            ServiceSendNumberMap serviceSendNumberMap = ServiceSendNumberMap.CreateManager().Load(message.Service).FirstOrDefault();

            if (serviceSendNumberMap == null)
            {
                Log.Error("NOTIFICATION_MOMT:: ServiceSendNumberMap could not be loaded by ServiceID:" + message.Service.ID);
                return;
            }

            if (message.MobileOperator == null)
            {
                Log.Error("NOTIFICATION_MOMT:: MobileOperator is null for number:" + message.Customer.Msisdn);
                return;
            }

            try
            {
                string smsMessage = serviceSendNumberMap.SmsMessages.FirstOrDefault();

                SendSmsResponse response         = null;
                Guid            messageReference = Guid.NewGuid();

                #region # Get cashflow SendSmsResponse #

                SendSmsRequest smsRequest = new SendSmsRequest(RequestMode.Default,
                                                               messageReference.ToString(),
                                                               message.Service.ServiceConfiguration.PaymentConfiguration.PaymentCredentials.Username,                       // username
                                                               message.Service.ServiceConfiguration.PaymentConfiguration.PaymentCredentials.Password,                       // password
                                                               message.Service.ServiceConfiguration.PaymentConfiguration.BehaviorModel.Guid,                                //bm
                                                               message.Service.Product.ExternalProductGuid,                                                                 //product
                                                               message.Service.ServiceConfiguration.PaymentConfiguration.PaymentInterface.ExternalPaymentInterfaceGuid,     //interface
                                                               message.Service.FallbackCountry.TwoLetterIsoCode,
                                                               message.Service.ServiceConfiguration.PaymentConfiguration.PaymentProvider.ExternalPaymentProviderGuid.Value, //provider
                                                               message.MobileOperator.ExternalMobileOperatorID.ToString(),
                                                               message.Customer.Msisdn,
                                                               smsMessage,
                                                               messageReference.ToString(), // "send sms ref."
                                                               string.Empty,
                                                               null);
                response = (new Cashflow.Client.MobileExtensionClient("http://v10.api.cashflow-payment.com/mobile.svc/soap12")).SendSms(smsRequest);

                #endregion

                if (response.Status.Code == MessageStatusCode.Success)
                {
                    Log.Info(string.Format("NOTIFICATION_MOMT::SendNumber:: Message successfuly sent. (message='{0} to number='{1}'", smsMessage, message.Customer.Msisdn));
                    #region # Insert messages in database #
                    MobiChat.Web.Data.Message dataMessage = new Message(-1,
                                                                        messageReference,
                                                                        null, /// externalID
                                                                        message.Service,
                                                                        message.Customer,
                                                                        message.MobileOperator.Name,
                                                                        message.Customer.MobileOperator,
                                                                        MessageDirection.Outgoing,
                                                                        Web.Data.MessageType.MT_Free,
                                                                        Web.Data.MessageStatus.Sent,
                                                                        smsMessage,
                                                                        null,               // shorcode
                                                                        string.Empty,       // keyword
                                                                        message.TrackingID, // pxid
                                                                        DateTime.Now, DateTime.Now);
                    dataMessage.Insert();

                    MTMessage mtMessage = new MTMessage(-1,
                                                        dataMessage,
                                                        message.Service.ServiceConfiguration.ExternalID,
                                                        message.Customer.Msisdn,
                                                        string.Empty, // msgID
                                                        DateTime.Now.ToString(),
                                                        "MOBICHAT_NOTIFICATION",
                                                        string.Empty, //error
                                                        string.Empty, //reasonCode
                                                        string.Empty, //retry
                                                        string.Empty, //appMsgID
                                                        DateTime.Now, DateTime.Now);
                    mtMessage.Insert();
                    #endregion
                }
                else
                {
                    Log.Error(string.Format("NOTIFICATION_MOMT::SendWelcomeMessage - Cashlfow returned us error (SubCode='{0}', Message='{1}'",
                                            response.Status.SubCode.ToString(),
                                            response.Status.Message));
                }
            }
            catch (Exception e)
            {
                Log.Error(string.Format("NOTIFICATION_MOMT::SendWelcomeMessage - FATAL", e));
            }
        }