2023-01-04 14:28:28 +00:00
|
|
|
using Elsa.MassTransit.Messages;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Workflows.Runtime.Models;
|
|
|
|
|
using Elsa.Workflows.Runtime.Services;
|
2022-04-10 12:35:53 +00:00
|
|
|
using MassTransit;
|
|
|
|
|
|
2022-05-26 10:47:31 +00:00
|
|
|
namespace Elsa.MassTransit.Implementations;
|
2022-04-10 12:35:53 +00:00
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Implements <see cref="IWorkflowDispatcher"/> by leveraging MassTransit.
|
|
|
|
|
/// </summary>
|
2022-04-10 12:35:53 +00:00
|
|
|
public class MassTransitWorkflowDispatcher : IWorkflowDispatcher
|
|
|
|
|
{
|
|
|
|
|
private readonly IBus _bus;
|
|
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
2022-04-10 12:35:53 +00:00
|
|
|
public MassTransitWorkflowDispatcher(IBus bus)
|
|
|
|
|
{
|
|
|
|
|
_bus = bus;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <inheritdoc />
|
2022-04-10 12:35:53 +00:00
|
|
|
public async Task<DispatchWorkflowDefinitionResponse> DispatchAsync(DispatchWorkflowDefinitionRequest request, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
2023-01-04 14:28:28 +00:00
|
|
|
await _bus.Publish<DispatchWorkflowDefinition>(new
|
|
|
|
|
{
|
|
|
|
|
request.DefinitionId,
|
|
|
|
|
request.Input,
|
|
|
|
|
request.CorrelationId,
|
|
|
|
|
request.VersionOptions
|
|
|
|
|
}, cancellationToken);
|
2022-04-10 12:35:53 +00:00
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 14:28:28 +00:00
|
|
|
/// <inheritdoc />
|
2022-04-10 12:35:53 +00:00
|
|
|
public async Task<DispatchWorkflowInstanceResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
2023-01-04 14:28:28 +00:00
|
|
|
await _bus.Publish<DispatchWorkflowInstance>(new
|
|
|
|
|
{
|
|
|
|
|
request.Input,
|
|
|
|
|
request.ActivityId,
|
|
|
|
|
request.BookmarkId,
|
|
|
|
|
request.CorrelationId,
|
|
|
|
|
request.InstanceId
|
|
|
|
|
}, cancellationToken);
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task<DispatchTriggerWorkflowsResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
await _bus.Publish<DispatchTriggerWorkflows>(new
|
|
|
|
|
{
|
|
|
|
|
request.Input,
|
|
|
|
|
request.BookmarkPayload,
|
|
|
|
|
request.CorrelationId,
|
|
|
|
|
request.ActivityTypeName
|
|
|
|
|
}, cancellationToken);
|
2022-04-10 12:35:53 +00:00
|
|
|
return new();
|
|
|
|
|
}
|
2023-01-04 19:36:38 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task<DispatchResumeWorkflowsResponse> DispatchAsync(DispatchResumeWorkflowsRequest request, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
await _bus.Publish<DispatchResumeWorkflows>(new
|
|
|
|
|
{
|
|
|
|
|
request.Input,
|
|
|
|
|
request.BookmarkPayload,
|
|
|
|
|
request.CorrelationId,
|
|
|
|
|
request.ActivityTypeName
|
|
|
|
|
}, cancellationToken);
|
|
|
|
|
return new();
|
|
|
|
|
}
|
2022-04-10 12:35:53 +00:00
|
|
|
}
|