| | | 1 | | using Elsa.Expressions.Models; |
| | | 2 | | using Elsa.Extensions; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Workflows.Runtime.Activities; |
| | | 5 | | |
| | | 6 | | public abstract class EventBase : Trigger<object>; |
| | | 7 | | |
| | | 8 | | public abstract class EventBase<TResult> : Trigger<TResult> |
| | | 9 | | { |
| | | 10 | | protected abstract string GetEventName(ExpressionExecutionContext context); |
| | | 11 | | |
| | | 12 | | protected virtual ValueTask OnEventReceivedAsync(ActivityExecutionContext context, TResult? input) |
| | | 13 | | { |
| | 0 | 14 | | OnEventReceived(context, input); |
| | 0 | 15 | | return default; |
| | | 16 | | } |
| | | 17 | | |
| | | 18 | | protected virtual void OnEventReceived(ActivityExecutionContext context, TResult? input) |
| | | 19 | | { |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | protected override object GetTriggerPayload(TriggerIndexingContext context) |
| | | 23 | | { |
| | 0 | 24 | | var eventName = GetEventName(context.ExpressionExecutionContext); |
| | 0 | 25 | | return context.GetEventStimulus(eventName); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | protected override ValueTask ExecuteAsync(ActivityExecutionContext context) |
| | | 29 | | { |
| | 0 | 30 | | var eventName = GetEventName(context.ExpressionExecutionContext); |
| | 0 | 31 | | context.WaitForEvent(eventName, EventReceivedAsync); |
| | 0 | 32 | | return default; |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | protected async ValueTask EventReceivedAsync(ActivityExecutionContext context) |
| | | 36 | | { |
| | 0 | 37 | | var input = (TResult?)context.GetEventInput(); |
| | 0 | 38 | | Result.Set(context, input); |
| | 0 | 39 | | await OnEventReceivedAsync(context, input); |
| | 0 | 40 | | await context.CompleteActivityAsync(); |
| | 0 | 41 | | } |
| | | 42 | | } |