protected override System.Threading.Tasks.Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { WorkflowRuleNotification receivedNotification = null; IAuthenticatedWho authenticatedWho = null; INotifier emailNotifier = null; Guid tenantGuid = Guid.Empty; String tenantId = null; String mode = null; String email = null; try { // Get the mode from the request uri mode = BaseHttpUtils.GetModeFromQuery(request.RequestUri); // Get any provided notification email email = BaseHttpUtils.GetEmailFromQuery(request.RequestUri); // Check to make sure the incoming request has enough segments // Deployed we have an extra segment for the deployment sub-directory, hence this is one more than you would have thought if (request.RequestUri.Segments.Length < 9) { throw new ArgumentNullException("Request.Segments", "The incoming request is not a valid Url for outbound messages."); } // Get the segments from the call so we know which tenant we're executing against tenantId = request.RequestUri.Segments[8].Replace("/", ""); // Check to make sure we've received valid guids if (Guid.TryParse(tenantId, out tenantGuid) == false) { throw new ArgumentNullException("Request.Segments", "The incoming request does not contain a valid tenant identifier. You provided: " + tenantId); } // Create a basic authenticated who for the notifier authenticatedWho = AuthenticationUtils.CreatePublicUser(tenantId); authenticatedWho.Email = email; // Create the notifier emailNotifier = EmailNotifier.GetInstance(tenantId, authenticatedWho, null, "WorkflowRuleListenerMessageHandler"); // ExtractData would populate notification class' variables, which can be used to get desired data. receivedNotification = new WorkflowRuleNotification(); receivedNotification.ExtractData(emailNotifier, request.Content.ReadAsStringAsync().Result, mode); // Now send ManyWho the notification that something has changed on a set of records, but only if ManyWho actually cares about them this.Execute(emailNotifier, tenantId, mode, receivedNotification); // Send the debug log if the user is running in debug mode if (SettingUtils.IsDebugging(mode)) { ErrorUtils.SendAlert(emailNotifier, null, ErrorUtils.ALERT_TYPE_WARNING, "Debug Log Entries"); } // Send a response back to SFDC // Note: since we are not calling base class' SendAsync function, the request will return from here, and will not reach our POST function. return(Task.FromResult(receivedNotification.PrepareResponse(request))); } catch (Exception exception) { // Send the debug log if the user is running in debug mode if (SettingUtils.IsDebugging(mode)) { ErrorUtils.SendAlert(emailNotifier, null, ErrorUtils.ALERT_TYPE_WARNING, BaseHttpUtils.GetExceptionMessage(exception)); } throw BaseHttpUtils.GetWebException(HttpStatusCode.BadRequest, BaseHttpUtils.GetExceptionMessage(exception)); } }
protected override System.Threading.Tasks.Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { WorkflowRuleNotification receivedNotification = null; IAuthenticatedWho authenticatedWho = null; INotifier emailNotifier = null; Guid tenantGuid = Guid.Empty; Guid flowGuid = Guid.Empty; String tenantId = null; String flowId = null; String player = null; String mode = null; String email = null; String reportingMode = null; try { // Get the mode from the request uri mode = BaseHttpUtils.GetModeFromQuery(request.RequestUri); // Get the reporting mode from the request uri reportingMode = BaseHttpUtils.GetReportingModeFromQuery(request.RequestUri); // Get any provided notification email email = BaseHttpUtils.GetEmailFromQuery(request.RequestUri); // Check to make sure the incoming request has enough segments if (request.RequestUri.Segments.Length < 9) { throw new ArgumentNullException("Request.Segments", "The incoming request is not a valid Url for outbound messages."); } // Get the segments from the call so we know which tenant we're executing against tenantId = request.RequestUri.Segments[7].Replace("/", ""); flowId = request.RequestUri.Segments[8].Replace("/", ""); player = request.RequestUri.Segments[9]; // Check to make sure we've received valid guids if (Guid.TryParse(tenantId, out tenantGuid) == false) { throw new ArgumentNullException("Request.Segments", "The incoming request does not contain a valid tenant identifier."); } if (Guid.TryParse(flowId, out flowGuid) == false) { throw new ArgumentNullException("Request.Segments", "The incoming request does not contain a valid flow identifier."); } // If a player has not been provided, we make it the default player if (String.IsNullOrWhiteSpace(player) == true) { player = "default"; } // Create a basic authenticated who for the notifier authenticatedWho = AuthenticationUtils.CreatePublicUser(tenantId); authenticatedWho.Email = email; // Create the notifier emailNotifier = EmailNotifier.GetInstance(tenantId, authenticatedWho, null, "WorkflowRuleMessageHandler"); //ExtractData would populate notification class' variables, which can be used to get desired data. receivedNotification = new WorkflowRuleNotification(); receivedNotification.ExtractData(emailNotifier, request.Content.ReadAsStringAsync().Result, mode); if (SettingUtils.IsDebugging(mode)) { emailNotifier.AddLogEntry("Mode: " + mode); } if (SettingUtils.IsDebugging(mode)) { emailNotifier.AddLogEntry("Email: " + email); } if (SettingUtils.IsDebugging(mode)) { emailNotifier.AddLogEntry("Reporting Mode: " + reportingMode); } // Execute the notifications against ManyWho this.Execute(emailNotifier, tenantId, flowId, player, mode, reportingMode, receivedNotification); // Send the debug log if the user is running in debug mode if (SettingUtils.IsDebugging(mode)) { ErrorUtils.SendAlert(emailNotifier, null, ErrorUtils.ALERT_TYPE_WARNING, "Debug Log Entries"); } //Send a response back to SFDC //Note: since we are not calling base class' SendAsync function, the request will return from here, and will not reach our POST function. return(Task.FromResult(receivedNotification.PrepareResponse(request))); } catch (Exception exception) { // Send the debug log if the user is running in debug mode if (SettingUtils.IsDebugging(mode)) { ErrorUtils.SendAlert(emailNotifier, null, ErrorUtils.ALERT_TYPE_WARNING, BaseHttpUtils.GetExceptionMessage(exception)); } throw BaseHttpUtils.GetWebException(HttpStatusCode.BadRequest, BaseHttpUtils.GetExceptionMessage(exception)); } }