The 'input' parameter in 'PublishAsync', 'DispatchAsync' and related methods across multiple classes has been replaced with 'payload'. The renaming of 'input' to 'payload' provides a more intuitive understanding of the parameter as the actual content or data of the event being published or dispatched. It also includes changes in 'PublishInternalAsync' where the workflow input dictionary is now being populated with the payload.
72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
using Elsa.Mediator;
|
|
using Elsa.Mediator.Contracts;
|
|
using Elsa.Workflows.Runtime.Activities;
|
|
using Elsa.Workflows.Runtime.Bookmarks;
|
|
using Elsa.Workflows.Runtime.Contracts;
|
|
using Elsa.Workflows.Runtime.Models;
|
|
using Elsa.Workflows.Runtime.Options;
|
|
using Elsa.Workflows.Runtime.Results;
|
|
|
|
namespace Elsa.Workflows.Runtime.Services;
|
|
|
|
/// <inheritdoc />
|
|
public class EventPublisher : IEventPublisher
|
|
{
|
|
private readonly IWorkflowInbox _workflowInbox;
|
|
|
|
/// <summary>
|
|
/// Constructor.
|
|
/// </summary>
|
|
public EventPublisher(IWorkflowInbox workflowInbox)
|
|
{
|
|
_workflowInbox = workflowInbox;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<ICollection<WorkflowExecutionResult>> PublishAsync(
|
|
string eventName,
|
|
string? correlationId = default,
|
|
string? workflowInstanceId = default,
|
|
string? activityInstanceId = default,
|
|
object? payload = default,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
return await PublishInternalAsync(eventName, false, correlationId, workflowInstanceId, activityInstanceId, payload, cancellationToken);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task DispatchAsync(
|
|
string eventName,
|
|
string? correlationId = default,
|
|
string? workflowInstanceId = default,
|
|
string? activityInstanceId = default,
|
|
object? payload = default,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
await PublishInternalAsync(eventName, true, correlationId, workflowInstanceId, activityInstanceId, payload, cancellationToken);
|
|
}
|
|
|
|
private async Task<ICollection<WorkflowExecutionResult>> PublishInternalAsync(
|
|
string eventName,
|
|
bool dispatchAsynchronously,
|
|
string? correlationId = default,
|
|
string? workflowInstanceId = default,
|
|
string? activityInstanceId = default,
|
|
object? payload = default,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var eventBookmark = new EventBookmarkPayload(eventName);
|
|
var workflowInput = new Dictionary<string, object>
|
|
{
|
|
[Event.EventPayloadWorkflowInputKey] = payload ?? new Dictionary<string, object>()
|
|
};
|
|
var message = NewWorkflowInboxMessage.For<Event>(eventBookmark, workflowInstanceId, correlationId, activityInstanceId, workflowInput);
|
|
var options = new WorkflowInboxMessageDeliveryOptions
|
|
{
|
|
DispatchAsynchronously = dispatchAsynchronously
|
|
};
|
|
|
|
var result = await _workflowInbox.SubmitAsync(message, options, cancellationToken);
|
|
return result.WorkflowExecutionResults;
|
|
}
|
|
} |