public HttpResponseMessage Get( [FromUri] string tenant, // Our stuff [FromUri] string notifierId, [FromUri] TwilioSms sms) { // Run service using (Profiler.Measure("TwilioController.Get")) { try { long notifierIdNum; try { notifierIdNum = Int64.Parse(notifierId); } catch { throw new UnmatchedNotifierException(); } using (WebApiHelpers.GetTenantContext(tenant)) { _receiver.HandleRequest(notifierIdNum, sms); } return(new HttpResponseMessage(HttpStatusCode.Accepted)); } catch (TwilioValidationException) { EventLog.Application.WriteError($"Request failed validation. URL:{System.Web.HttpContext.Current.Request.Url}"); return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } } }
/// <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(); } } } }