| | | 1 | | using Elsa.Http.Extensions; |
| | | 2 | | using Elsa.Workflows; |
| | | 3 | | using Microsoft.AspNetCore.Http; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Http; |
| | | 6 | | |
| | | 7 | | public abstract class HttpEndpointBase : HttpEndpointBase<object>; |
| | | 8 | | |
| | | 9 | | public abstract class HttpEndpointBase<TResult> : Trigger<TResult> |
| | | 10 | | { |
| | | 11 | | protected abstract HttpEndpointOptions GetOptions(); |
| | | 12 | | |
| | | 13 | | protected virtual ValueTask OnHttpRequestReceivedAsync(ActivityExecutionContext activityExecutionContext, HttpContex |
| | | 14 | | { |
| | 0 | 15 | | OnHttpRequestReceived(activityExecutionContext, httpContext); |
| | 0 | 16 | | return default; |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | protected virtual void OnHttpRequestReceived(ActivityExecutionContext activityExecutionContext, HttpContext httpCont |
| | | 20 | | { |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) |
| | | 24 | | { |
| | 0 | 25 | | var options = GetOptions(); |
| | 0 | 26 | | await context.WaitForHttpRequestAsync(options, HttpRequestReceivedAsync); |
| | 0 | 27 | | } |
| | | 28 | | |
| | | 29 | | protected override IEnumerable<object> GetTriggerPayloads(TriggerIndexingContext context) |
| | | 30 | | { |
| | 0 | 31 | | var options = GetOptions(); |
| | 0 | 32 | | context.TriggerName = HttpStimulusNames.HttpEndpoint; |
| | 0 | 33 | | return context.GetHttpEndpointStimuli(options); |
| | | 34 | | } |
| | | 35 | | |
| | | 36 | | private async ValueTask HttpRequestReceivedAsync(ActivityExecutionContext context) |
| | | 37 | | { |
| | 0 | 38 | | var httpContext = context.GetRequiredService<IHttpContextAccessor>().HttpContext!; |
| | 0 | 39 | | await OnHttpRequestReceivedAsync(context, httpContext); |
| | 0 | 40 | | await context.CompleteActivityAsync(); |
| | 0 | 41 | | } |
| | | 42 | | } |