using Elsa.Extensions; using Elsa.Workflows.Core.Helpers; using Elsa.Workflows.Core.Models; using Elsa.Workflows.Runtime.Activities; using Elsa.Workflows.Runtime.Models; using Elsa.Workflows.Runtime.Services; namespace Elsa.Workflows.Runtime.Implementations; /// public class EventPublisher : IEventPublisher { private readonly IWorkflowRuntime _workflowRuntime; private readonly IWorkflowDispatcher _workflowDispatcher; /// /// Constructor. /// public EventPublisher(IWorkflowRuntime workflowRuntime, IWorkflowDispatcher workflowDispatcher) { _workflowRuntime = workflowRuntime; _workflowDispatcher = workflowDispatcher; } /// public async Task PublishAsync(string eventName, string? correlationId = default, IDictionary? input = default, CancellationToken cancellationToken = default) { var eventBookmark = new EventBookmarkPayload(eventName); var options = new TriggerWorkflowsRuntimeOptions(correlationId, input); await _workflowRuntime.TriggerWorkflowsAsync(eventBookmark, options, cancellationToken); } /// public async Task DispatchAsync(string eventName, string? correlationId = default, IDictionary? input = default, CancellationToken cancellationToken = default) { var eventBookmark = new EventBookmarkPayload(eventName); var activityTypeName = ActivityTypeNameHelper.GenerateTypeName(); var request = new DispatchTriggerWorkflowsRequest(activityTypeName, eventBookmark, correlationId, input); await _workflowDispatcher.DispatchAsync(request, cancellationToken); } }