2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Workflows.Runtime.Services;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
namespace Elsa.Workflows.Runtime.Implementations;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
|
|
|
|
public class StimulusInterpreter : IStimulusInterpreter
|
|
|
|
|
{
|
|
|
|
|
private readonly IEnumerable<IStimulusHandler> _workflowExecutionInstructionProviders;
|
|
|
|
|
|
|
|
|
|
public StimulusInterpreter(IEnumerable<IStimulusHandler> workflowExecutionInstructionProviders)
|
|
|
|
|
{
|
|
|
|
|
_workflowExecutionInstructionProviders = workflowExecutionInstructionProviders;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<IWorkflowInstruction>> GetExecutionInstructionsAsync(IStimulus stimulus, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
var providers = _workflowExecutionInstructionProviders.Where(x => x.GetSupportsStimulus(stimulus)).ToList();
|
|
|
|
|
var tasks = providers.Select(x => x.GetInstructionsAsync(stimulus, cancellationToken).AsTask());
|
|
|
|
|
return (await Task.WhenAll(tasks)).SelectMany(x => x);
|
|
|
|
|
}
|
|
|
|
|
}
|