< Summary

Information
Class: Elsa.Workflows.Management.Handlers.Notifications.RefreshActivityRegistry
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Handlers/Notifications/RefreshActivityRegistry.cs
Line coverage
42%
Covered lines: 9
Uncovered lines: 12
Coverable lines: 21
Total lines: 96
Line coverage: 42.8%
Branch coverage
25%
Covered branches: 2
Total branches: 8
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
HandleAsync(...)100%11100%
HandleAsync(...)100%210%
HandleAsync(...)100%11100%
HandleAsync(...)100%11100%
HandleAsync(...)0%620%
HandleAsync(...)100%210%
HandleAsync(...)0%620%
HandleAsync()0%620%
UpdateDefinition(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Handlers/Notifications/RefreshActivityRegistry.cs

#LineLine coverage
 1using Elsa.Mediator.Contracts;
 2using Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity;
 3using Elsa.Workflows.Management.Contracts;
 4using Elsa.Workflows.Management.Entities;
 5using Elsa.Workflows.Management.Notifications;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Workflows.Management.Handlers.Notifications;
 9
 10/// <summary>
 11/// Refreshes the <see cref="IActivityRegistry"/> for the <see cref="WorkflowDefinitionActivityProvider"/> provider when
 12/// </summary>
 13[PublicAPI]
 31914public class RefreshActivityRegistry(IWorkflowDefinitionActivityRegistryUpdater workflowDefinitionActivityRegistryUpdate
 15    INotificationHandler<WorkflowDefinitionPublished>,
 16    INotificationHandler<WorkflowDefinitionRetracted>,
 17    INotificationHandler<WorkflowDefinitionVersionRetracted>,
 18    INotificationHandler<WorkflowDefinitionDeleted>,
 19    INotificationHandler<WorkflowDefinitionsDeleted>,
 20    INotificationHandler<WorkflowDefinitionVersionDeleted>,
 21    INotificationHandler<WorkflowDefinitionVersionsDeleted>,
 22    INotificationHandler<WorkflowDefinitionVersionsUpdated>
 23{
 24    /// <inheritdoc />
 25    public Task HandleAsync(WorkflowDefinitionPublished notification, CancellationToken cancellationToken)
 26    {
 527        return UpdateDefinition(notification.WorkflowDefinition.Id, notification.WorkflowDefinition.Options.UsableAsActi
 28    }
 29
 30    /// <inheritdoc />
 31    public Task HandleAsync(WorkflowDefinitionRetracted notification, CancellationToken cancellationToken)
 32    {
 033        return UpdateDefinition(notification.WorkflowDefinition.Id, notification.WorkflowDefinition.Options.UsableAsActi
 34    }
 35
 36    /// <inheritdoc />
 37    public Task HandleAsync(WorkflowDefinitionVersionRetracted notification, CancellationToken cancellationToken)
 38    {
 339        return UpdateDefinition(notification.WorkflowDefinition.Id, notification.WorkflowDefinition.Options.UsableAsActi
 40    }
 41
 42    /// <inheritdoc />
 43    public Task HandleAsync(WorkflowDefinitionDeleted notification, CancellationToken cancellationToken)
 44    {
 445        workflowDefinitionActivityRegistryUpdater.RemoveDefinitionFromRegistry(notification.DefinitionId);
 446        return Task.CompletedTask;
 47    }
 48
 49    /// <inheritdoc />
 50    public Task HandleAsync(WorkflowDefinitionsDeleted notification, CancellationToken cancellationToken)
 51    {
 052        foreach (string id in notification.DefinitionIds)
 53        {
 054            workflowDefinitionActivityRegistryUpdater.RemoveDefinitionFromRegistry(id);
 55        }
 56
 057        return Task.CompletedTask;
 58    }
 59
 60    /// <inheritdoc />
 61    public Task HandleAsync(WorkflowDefinitionVersionDeleted notification, CancellationToken cancellationToken)
 62    {
 063        workflowDefinitionActivityRegistryUpdater.RemoveDefinitionVersionFromRegistry(notification.WorkflowDefinition.Id
 064        return Task.CompletedTask;
 65    }
 66
 67    /// <inheritdoc />
 68    public Task HandleAsync(WorkflowDefinitionVersionsDeleted notification, CancellationToken cancellationToken)
 69    {
 070        foreach (string id in notification.Ids)
 71        {
 072            workflowDefinitionActivityRegistryUpdater.RemoveDefinitionVersionFromRegistry(id);
 73        }
 74
 075        return Task.CompletedTask;
 76    }
 77
 78    /// <inheritdoc />
 79    public async Task HandleAsync(WorkflowDefinitionVersionsUpdated notification, CancellationToken cancellationToken)
 80    {
 081        foreach (var definition in notification.WorkflowDefinitions)
 82        {
 083            await UpdateDefinition(definition.Id, definition.Options.UsableAsActivity);
 84        }
 085    }
 86
 87    private Task UpdateDefinition(string id, bool? usableAsActivity)
 88    {
 89        // Once a workflow has been published, it should remain in the activity registry unless no longer being marked a
 890        if (usableAsActivity.GetValueOrDefault())
 391            return workflowDefinitionActivityRegistryUpdater.AddToRegistry(id);
 92
 593        workflowDefinitionActivityRegistryUpdater.RemoveDefinitionVersionFromRegistry(id);
 594        return Task.CompletedTask;
 95    }
 96}