| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity; |
| | | 3 | | using Elsa.Workflows.Management.Contracts; |
| | | 4 | | using Elsa.Workflows.Runtime.Notifications; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Runtime.Handlers; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Refreshes the <see cref="IActivityRegistry"/> for the <see cref="WorkflowDefinitionActivityProvider"/> provider when |
| | | 11 | | /// </summary> |
| | | 12 | | [PublicAPI] |
| | 467 | 13 | | public class RefreshActivityRegistry(IWorkflowDefinitionActivityRegistryUpdater workflowDefinitionActivityRegistryUpdate |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public async Task HandleAsync(WorkflowDefinitionsReloaded notification, CancellationToken cancellationToken) |
| | | 17 | | { |
| | 876 | 18 | | foreach (var reloadedWorkflowDefinition in notification.ReloadedWorkflowDefinitions) |
| | 432 | 19 | | await UpdateDefinition(reloadedWorkflowDefinition.DefinitionVersionId, reloadedWorkflowDefinition.UsableAsAc |
| | 6 | 20 | | } |
| | | 21 | | |
| | | 22 | | private Task UpdateDefinition(string definitionVersionId, bool? usableAsActivity) |
| | | 23 | | { |
| | | 24 | | // A workflow should remain in the activity registry unless no longer being marked as an activity. |
| | 432 | 25 | | if (usableAsActivity.GetValueOrDefault()) |
| | 60 | 26 | | return workflowDefinitionActivityRegistryUpdater.AddToRegistry(definitionVersionId); |
| | | 27 | | |
| | 372 | 28 | | workflowDefinitionActivityRegistryUpdater.RemoveDefinitionVersionFromRegistry(definitionVersionId); |
| | 372 | 29 | | return Task.CompletedTask; |
| | | 30 | | } |
| | | 31 | | } |