Ejemplo n.º 1
0
        // SUMMARY: Try to find PXID from previous messages from this customer
        public int?TryPxidReportFromPreviousMessage(Customer customer)
        {
            if (customer == null)
            {
                return(null);
            }

            MobiChat.Web.Data.Message message = Message.CreateManager().Load(customer, MobiChat.Web.Data.MessageType.MT_Free).FirstOrDefault();
            if (message != null && message.TrackingID.HasValue)
            {
                return(message.TrackingID);
            }

            return(null);
        }
Ejemplo n.º 2
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));
        }