2022-12-31 15:16:43 +00:00
|
|
|
|
using Elsa.Extensions;
|
2023-03-03 21:47:23 +00:00
|
|
|
|
using Elsa.Http.Contracts;
|
|
|
|
|
|
using Elsa.Mediator.Contracts;
|
2022-05-26 10:47:31 +00:00
|
|
|
|
using Elsa.Workflows.Runtime.Notifications;
|
2022-04-27 20:32:40 +00:00
|
|
|
|
|
2022-11-19 21:30:43 +00:00
|
|
|
|
namespace Elsa.Http.Handlers;
|
|
|
|
|
|
|
2023-04-13 18:35:55 +00:00
|
|
|
|
/// <summary>
|
2023-04-17 13:23:05 +00:00
|
|
|
|
/// A handler that updates the route table when workflow triggers and bookmarks are indexed.
|
2023-04-13 18:35:55 +00:00
|
|
|
|
/// </summary>
|
2022-11-19 21:30:43 +00:00
|
|
|
|
public class UpdateRouteTable :
|
|
|
|
|
|
INotificationHandler<WorkflowTriggersIndexed>,
|
|
|
|
|
|
INotificationHandler<WorkflowBookmarksIndexed>
|
2022-04-27 20:32:40 +00:00
|
|
|
|
{
|
2022-11-19 21:30:43 +00:00
|
|
|
|
private readonly IRouteTable _routeTable;
|
2023-04-13 18:35:55 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="UpdateRouteTable"/> class.
|
|
|
|
|
|
/// </summary>
|
2022-11-19 21:30:43 +00:00
|
|
|
|
public UpdateRouteTable(IRouteTable routeTable) => _routeTable = routeTable;
|
2022-04-27 20:32:40 +00:00
|
|
|
|
|
2023-04-13 18:35:55 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-11-19 21:30:43 +00:00
|
|
|
|
public Task HandleAsync(WorkflowTriggersIndexed notification, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
_routeTable.RemoveRoutes(notification.IndexedWorkflowTriggers.RemovedTriggers);
|
|
|
|
|
|
_routeTable.AddRoutes(notification.IndexedWorkflowTriggers.AddedTriggers);
|
|
|
|
|
|
_routeTable.AddRoutes(notification.IndexedWorkflowTriggers.UnchangedTriggers);
|
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
|
}
|
2022-04-27 20:32:40 +00:00
|
|
|
|
|
2023-04-13 18:35:55 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-11-19 21:30:43 +00:00
|
|
|
|
public Task HandleAsync(WorkflowBookmarksIndexed notification, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
|
|
|
|
|
_routeTable.RemoveRoutes(notification.IndexedWorkflowBookmarks.RemovedBookmarks);
|
|
|
|
|
|
_routeTable.AddRoutes(notification.IndexedWorkflowBookmarks.AddedBookmarks);
|
|
|
|
|
|
return Task.CompletedTask;
|
2022-04-27 20:32:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|