| | | 1 | | using Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity; |
| | | 2 | | using Elsa.Workflows.Management.Contracts; |
| | | 3 | | using Elsa.Workflows.Models; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Management.Services; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Service responsible for updating the activity registry based on activity providers. |
| | | 9 | | /// </summary> |
| | 319 | 10 | | public class WorkflowDefinitionActivityRegistryUpdater(WorkflowDefinitionActivityProvider provider, IActivityRegistry re |
| | | 11 | | { |
| | 319 | 12 | | private readonly Type _providerType = typeof(WorkflowDefinitionActivityProvider); |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public async Task AddToRegistry(string workflowDefinitionVersionId, CancellationToken cancellationToken) |
| | | 16 | | { |
| | 63 | 17 | | var descriptors = await provider.GetDescriptorsAsync(cancellationToken); |
| | 63 | 18 | | var descriptorToAdd = descriptors |
| | 63 | 19 | | .FirstOrDefault(d => |
| | 451 | 20 | | d.CustomProperties.TryGetValue("WorkflowDefinitionVersionId", out var val) && |
| | 451 | 21 | | val.ToString() == workflowDefinitionVersionId); |
| | | 22 | | |
| | 63 | 23 | | if (descriptorToAdd is not null) |
| | 63 | 24 | | registry.Add(_providerType, descriptorToAdd); |
| | 63 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <inheritdoc /> |
| | | 28 | | public void RemoveDefinitionFromRegistry(string workflowDefinitionId) |
| | | 29 | | { |
| | 4 | 30 | | var providerDescriptors = registry.ListByProvider(_providerType); |
| | | 31 | | |
| | 4 | 32 | | var descriptorsToRemove = providerDescriptors |
| | 4 | 33 | | .Where(d => |
| | 48 | 34 | | d.CustomProperties.TryGetValue("WorkflowDefinitionId", out var val) && |
| | 48 | 35 | | val.ToString() == workflowDefinitionId).ToList(); |
| | | 36 | | |
| | 18 | 37 | | foreach (ActivityDescriptor activityDescriptor in descriptorsToRemove) |
| | | 38 | | { |
| | 5 | 39 | | registry.Remove(_providerType, activityDescriptor); |
| | | 40 | | } |
| | 4 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <inheritdoc /> |
| | | 44 | | public void RemoveDefinitionVersionFromRegistry(string workflowDefinitionVersionId) |
| | | 45 | | { |
| | 377 | 46 | | var providerDescriptors = registry.ListByProvider(_providerType); |
| | | 47 | | |
| | 377 | 48 | | var descriptorToRemove = providerDescriptors |
| | 377 | 49 | | .FirstOrDefault(d => |
| | 4267 | 50 | | d.CustomProperties.TryGetValue("WorkflowDefinitionVersionId", out var val) && |
| | 4267 | 51 | | val.ToString() == workflowDefinitionVersionId); |
| | | 52 | | |
| | 377 | 53 | | if (descriptorToRemove is not null) |
| | 1 | 54 | | registry.Remove(_providerType, descriptorToRemove); |
| | 377 | 55 | | } |
| | | 56 | | } |