Exemplo n.º 1
0
        /// <summary>
        /// Flush any pending replies
        /// </summary>
        void Flush()
        {
            // All the requests run in the same context as the TwilioController.
            using (new TenantAdministratorContext(RequestContext.TenantId))
            {
                lock (_replies)
                {
                    if (_replies.Any())
                    {
                        foreach (var sms in _replies)
                        {
                            _receiver.HandleStatusUpdate(_notifier.Id, sms.MessageSid, "delivered", null);
                        }

                        foreach (var sms in _replies)
                        {
                            _receiver.HandleStatusUpdate(_notifier.Id, sms.MessageSid, "sent", null);
                        }

                        foreach (var sms in _replies)
                        {
                            _receiver.HandleRequest(_notifier.Id, sms);
                        }

                        _replies.Clear();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage UpdateStatus([FromUri] string tenant, [FromUri] string notifierId, SmsStatus request)
        {
            string messageSid    = request.SmsSid;
            string messageStatus = request.MessageStatus;
            string errorCode     = request.ErrorCode;

            // Run service
            using (Profiler.Measure("TwilioController.UpdateStatus"))
            {
                try
                {
                    long notifierIdNum;

                    try
                    {
                        notifierIdNum = Int64.Parse(notifierId);
                    }
                    catch
                    {
                        throw new UnmatchedNotifierException();
                    }

                    bool handled = false;

                    using (WebApiHelpers.GetTenantContext(tenant))
                    {
                        handled = _receiver.HandleStatusUpdate(notifierIdNum, messageSid, messageStatus, errorCode);
                    }

                    return(new HttpResponseMessage(handled ? HttpStatusCode.Accepted : HttpStatusCode.NotFound));
                }
                catch (TwilioValidationException)
                {
                    EventLog.Application.WriteError($"Request failed validation. URL:{System.Web.HttpContext.Current.Request.Url}");
                    return(new HttpResponseMessage(HttpStatusCode.BadRequest));
                }
            }
        }