public static Task <IHttpResponse> CreateAsync( [EastFive.Api.Meta.Flows.WorkflowNewId] [WorkflowVariable(Workflows.MonitoringFlow.Variables.CreatedNotification, IdPropertyName)] [UpdateId] IRef <TeamsNotification> teamsNotificationRef, [PropertyOptional(Name = RouteFiltersPropertyName)] [WorkflowArrayObjectParameter(Value0 = "/api/*")] string routeFilters, [PropertyOptional(Name = CollectionPropertyName)] [WorkflowParameter(Value = "Collection1", Disabled = true)] string collection, [Resource] TeamsNotification storyBoard, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, UnauthorizedResponse onUnauthorized) { return(storyBoard.HttpPostAsync( onCreated, onAlreadyExists)); }
public async Task <IHttpResponse> HandleRouteAsync(Type controllerType, IInvokeResource resourceInvoker, IApplication httpApp, IHttpRequest request, RouteHandlingDelegate continueExecution) { var response = await continueExecution(controllerType, httpApp, request); if (deactivated) { return(response); } string teamsNotifyParam = GetTeamsNotifyParameter(); if (!ShouldNotify(out string collectionFolder)) { return(response); } try { string messageId = await TeamsNotifyAsync(controllerType, resourceInvoker, httpApp, request, response, teamsNotifyParam, collectionFolder); } catch (HttpRequestException) { } catch (Exception) { } return(response); string GetTeamsNotifyParameter() { return(request.Headers .Where(kvp => kvp.Key.Equals("X-Teams-Notify", StringComparison.OrdinalIgnoreCase)) .First( (teamsNotifyParams, next) => { return teamsNotifyParams.Value.First( (teamsNotifyParam, next) => teamsNotifyParam, () => default(string)); }, () => { return default(string); })); } bool HasReportableError() { if (((int)response.StatusCode) < 400) { return(false); } if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { return(false); } if (response.StatusCode == System.Net.HttpStatusCode.Conflict) { return(false); } return(true); } bool RequestTeamsNotify() => teamsNotifyParam != default; bool ShouldNotify(out string collectionFolder) { collectionFolder = default; if (RequestTeamsNotify()) { return(true); } if (HasReportableError()) { return(true); } if (TeamsNotification.IsMatch(request, response, out collectionFolder)) { return(true); } return(false); } }