| | | 1 | | using Elsa.Expressions.Models; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | using Elsa.Http.Bookmarks; |
| | | 4 | | using Elsa.Workflows; |
| | | 5 | | using Elsa.Workflows.Models; |
| | | 6 | | using Microsoft.AspNetCore.Routing.Patterns; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Http.Extensions; |
| | | 9 | | |
| | | 10 | | public static class HttpEndpointActivityExecutionContextExtensions |
| | | 11 | | { |
| | | 12 | | public static async ValueTask WaitForHttpRequestAsync(this ActivityExecutionContext context, string path, string method, |
| | | 13 | | { |
| | 0 | 14 | | var options = new HttpEndpointOptions |
| | 0 | 15 | | { |
| | 0 | 16 | | Path = path, |
| | 0 | 17 | | Methods = [method] |
| | 0 | 18 | | }; |
| | 0 | 19 | | await WaitForHttpRequestAsync(context, options, callback); |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | public static async ValueTask WaitForHttpRequestAsync(this ActivityExecutionContext context, string path, IEnumerable<st |
| | | 23 | | { |
| | 218 | 24 | | var options = new HttpEndpointOptions |
| | 218 | 25 | | { |
| | 218 | 26 | | Path = path, |
| | 218 | 27 | | Methods = methods.ToList() |
| | 218 | 28 | | }; |
| | 218 | 29 | | await WaitForHttpRequestAsync(context, options, callback); |
| | 218 | 30 | | } |
| | | 31 | | |
| | | 32 | | public static async ValueTask WaitForHttpRequestAsync(this ActivityExecutionContext context, HttpEndpointOptions opt |
| | | 33 | | { |
| | 218 | 34 | | var path = options.Path; |
| | 218 | 35 | | if (path.Contains("//")) |
| | 0 | 36 | | throw new RoutePatternException(path, "Path cannot contain double slashes (//)"); |
| | | 37 | | |
| | 218 | 38 | | var expressionExecutionContext = context.ExpressionExecutionContext; |
| | 218 | 39 | | if (!context.IsTriggerOfWorkflow()) |
| | | 40 | | { |
| | 6 | 41 | | context.CreateBookmarks(expressionExecutionContext.GetHttpEndpointStimuli(options), includeActivityInstanceI |
| | 6 | 42 | | return; |
| | | 43 | | } |
| | | 44 | | |
| | 212 | 45 | | if (callback is not null) |
| | 212 | 46 | | await callback(context); |
| | 218 | 47 | | } |
| | | 48 | | |
| | | 49 | | public static IEnumerable<object> GetHttpEndpointStimuli(this TriggerIndexingContext context, string path, string me |
| | | 50 | | { |
| | 0 | 51 | | return context.GetHttpEndpointStimuli(path, [method]); |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | public static IEnumerable<object> GetHttpEndpointStimuli(this TriggerIndexingContext context, string path, IEnumerab |
| | | 55 | | { |
| | 0 | 56 | | var options = new HttpEndpointOptions |
| | 0 | 57 | | { |
| | 0 | 58 | | Path = path, |
| | 0 | 59 | | Methods = methods.ToList() |
| | 0 | 60 | | }; |
| | | 61 | | |
| | 0 | 62 | | return context.GetHttpEndpointStimuli(options); |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | public static IEnumerable<object> GetHttpEndpointStimuli(this TriggerIndexingContext context, HttpEndpointOptions op |
| | | 66 | | { |
| | 0 | 67 | | return context.ExpressionExecutionContext.GetHttpEndpointStimuli(options); |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | public static IEnumerable<object> GetHttpEndpointStimuli(this ExpressionExecutionContext context, HttpEndpointOption |
| | | 71 | | { |
| | | 72 | | // Generate bookmark data for path and selected methods. |
| | 6 | 73 | | var normalizedRoute = options.Path.NormalizeRoute(); |
| | 6 | 74 | | var authorize = options.Authorize; |
| | 6 | 75 | | var policy = options.Policy; |
| | 6 | 76 | | var requestTimeout = options.RequestTimeout; |
| | 6 | 77 | | var requestSizeLimit = options.RequestSizeLimit; |
| | | 78 | | |
| | 6 | 79 | | return options.Methods |
| | 6 | 80 | | .Select(x => new HttpEndpointBookmarkPayload(normalizedRoute, x.ToLowerInvariant(), authorize, policy, reque |
| | 6 | 81 | | .Cast<object>() |
| | 6 | 82 | | .ToArray(); |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | internal static void CreateCrossBoundaryBookmark(this ActivityExecutionContext context, ExecuteActivityDelegate? cal |
| | | 86 | | { |
| | 0 | 87 | | var bookmarkOptions = new CreateBookmarkArgs |
| | 0 | 88 | | { |
| | 0 | 89 | | BookmarkName = HttpStimulusNames.HttpEndpoint, |
| | 0 | 90 | | Callback = callback, |
| | 0 | 91 | | Metadata = BookmarkMetadata.HttpCrossBoundary, |
| | 0 | 92 | | }; |
| | 0 | 93 | | context.CreateBookmark(bookmarkOptions); |
| | 0 | 94 | | } |
| | | 95 | | } |