2023-01-04 14:28:28 +00:00
|
|
|
using Elsa.MassTransit.Messages;
|
2023-03-03 21:47:23 +00:00
|
|
|
using Elsa.Workflows.Runtime.Contracts;
|
2023-07-19 22:05:43 +00:00
|
|
|
using Elsa.Workflows.Runtime.Requests;
|
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-11-15 19:47:11 +00:00
|
|
|
await _bus.Send(new DispatchWorkflowDefinition(
|
2023-01-04 14:28:28 +00:00
|
|
|
request.DefinitionId,
|
2023-02-16 10:00:06 +00:00
|
|
|
request.VersionOptions,
|
2023-01-04 14:28:28 +00:00
|
|
|
request.Input,
|
|
|
|
|
request.CorrelationId,
|
2023-04-21 10:12:28 +00:00
|
|
|
request.InstanceId,
|
|
|
|
|
request.TriggerActivityId
|
2023-02-16 10:00:06 +00:00
|
|
|
), 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-11-15 19:47:11 +00:00
|
|
|
await _bus.Send(new DispatchWorkflowInstance(
|
2023-02-16 10:00:06 +00:00
|
|
|
request.InstanceId,
|
2023-01-04 14:28:28 +00:00
|
|
|
request.BookmarkId,
|
2023-02-16 10:00:06 +00:00
|
|
|
request.ActivityId,
|
2023-04-06 12:59:30 +00:00
|
|
|
request.ActivityNodeId,
|
|
|
|
|
request.ActivityInstanceId,
|
|
|
|
|
request.ActivityHash,
|
2023-02-16 10:00:06 +00:00
|
|
|
request.Input,
|
|
|
|
|
request.CorrelationId
|
|
|
|
|
), cancellationToken);
|
2023-01-04 14:28:28 +00:00
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task<DispatchTriggerWorkflowsResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
2023-11-15 19:47:11 +00:00
|
|
|
await _bus.Send(new DispatchTriggerWorkflows(
|
2023-02-16 10:00:06 +00:00
|
|
|
request.ActivityTypeName,
|
2023-01-04 14:28:28 +00:00
|
|
|
request.BookmarkPayload,
|
|
|
|
|
request.CorrelationId,
|
2023-03-20 20:38:00 +00:00
|
|
|
request.WorkflowInstanceId,
|
2023-08-09 11:02:20 +00:00
|
|
|
request.ActivityInstanceId,
|
2023-02-16 10:00:06 +00:00
|
|
|
request.Input
|
|
|
|
|
), 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)
|
|
|
|
|
{
|
2023-11-15 19:47:11 +00:00
|
|
|
await _bus.Send(new DispatchResumeWorkflows(
|
2023-02-16 10:00:06 +00:00
|
|
|
request.ActivityTypeName,
|
2023-01-04 19:36:38 +00:00
|
|
|
request.BookmarkPayload,
|
|
|
|
|
request.CorrelationId,
|
2023-03-20 20:38:00 +00:00
|
|
|
request.WorkflowInstanceId,
|
2023-08-09 11:02:20 +00:00
|
|
|
request.ActivityInstanceId,
|
2023-02-16 10:00:06 +00:00
|
|
|
request.Input
|
|
|
|
|
), cancellationToken);
|
2023-01-04 19:36:38 +00:00
|
|
|
return new();
|
|
|
|
|
}
|
2022-04-10 12:35:53 +00:00
|
|
|
}
|