< Summary

Information
Class: Elsa.Workflows.Management.Services.WorkflowDefinitionService
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionService.cs
Line coverage
68%
Covered lines: 32
Uncovered lines: 15
Coverable lines: 47
Total lines: 112
Line coverage: 68%
Branch coverage
41%
Covered branches: 5
Total branches: 12
Branch coverage: 41.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Services/WorkflowDefinitionService.cs

#LineLine coverage
 1using Elsa.Common.Models;
 2using Elsa.Workflows.Management.Entities;
 3using Elsa.Workflows.Management.Filters;
 4using Elsa.Workflows.Models;
 5
 6namespace Elsa.Workflows.Management.Services;
 7
 8/// <inheritdoc />
 3249public class WorkflowDefinitionService(
 32410    IWorkflowDefinitionStore workflowDefinitionStore,
 32411    IWorkflowGraphBuilder workflowGraphBuilder,
 32412    Func<IEnumerable<IWorkflowMaterializer>> materializers)
 13    : IWorkflowDefinitionService
 14{
 15    /// <inheritdoc />
 16    public async Task<WorkflowGraph> MaterializeWorkflowAsync(WorkflowDefinition definition, CancellationToken cancellat
 17    {
 139118        var workflowMaterializers = materializers();
 509819        var materializer = workflowMaterializers.FirstOrDefault(x => x.Name == definition.MaterializerName);
 20
 139121        if (materializer == null)
 022            throw new("Provider not found");
 23
 139124        var workflow = await materializer.MaterializeAsync(definition, cancellationToken);
 139125        return await workflowGraphBuilder.BuildAsync(workflow, cancellationToken);
 139126    }
 27
 28    /// <inheritdoc />
 29    public Task<WorkflowDefinition?> FindWorkflowDefinitionAsync(string definitionId, VersionOptions versionOptions, Can
 30    {
 2031        var handle = WorkflowDefinitionHandle.ByDefinitionId(definitionId, versionOptions);
 2032        return FindWorkflowDefinitionAsync(handle, cancellationToken);
 33    }
 34
 35    /// <inheritdoc />
 36    public Task<WorkflowDefinition?> FindWorkflowDefinitionAsync(string definitionVersionId, CancellationToken cancellat
 37    {
 7738        var handle = WorkflowDefinitionHandle.ByDefinitionVersionId(definitionVersionId);
 7739        return FindWorkflowDefinitionAsync(handle, cancellationToken);
 40    }
 41
 42    /// <inheritdoc />
 43    public async Task<WorkflowDefinition?> FindWorkflowDefinitionAsync(WorkflowDefinitionHandle handle, CancellationToke
 44    {
 9745        var filter = handle.ToFilter();
 9746        return await workflowDefinitionStore.FindAsync(filter, cancellationToken);
 9747    }
 48
 49    /// <inheritdoc />
 50    public async Task<WorkflowDefinition?> FindWorkflowDefinitionAsync(WorkflowDefinitionFilter filter, CancellationToke
 51    {
 42352        return await workflowDefinitionStore.FindAsync(filter, cancellationToken);
 42353    }
 54
 55    /// <inheritdoc />
 56    public async Task<WorkflowGraph?> FindWorkflowGraphAsync(string definitionId, VersionOptions versionOptions, Cancell
 57    {
 1858        var definition = await FindWorkflowDefinitionAsync(definitionId, versionOptions, cancellationToken);
 59
 1860        if (definition == null)
 161            return null;
 62
 1763        return await MaterializeWorkflowAsync(definition, cancellationToken);
 1864    }
 65
 66    /// <inheritdoc />
 67    public async Task<WorkflowGraph?> FindWorkflowGraphAsync(string definitionVersionId, CancellationToken cancellationT
 68    {
 7769        var definition = await FindWorkflowDefinitionAsync(definitionVersionId, cancellationToken);
 70
 7771        if (definition == null)
 072            return null;
 73
 7774        return await MaterializeWorkflowAsync(definition, cancellationToken);
 7775    }
 76
 77    /// <inheritdoc />
 78    public async Task<WorkflowGraph?> FindWorkflowGraphAsync(WorkflowDefinitionHandle definitionHandle, CancellationToke
 79    {
 080        var definition = await FindWorkflowDefinitionAsync(definitionHandle, cancellationToken);
 81
 082        if (definition == null)
 083            return null;
 84
 085        return await MaterializeWorkflowAsync(definition, cancellationToken);
 086    }
 87
 88    /// <inheritdoc />
 89    public async Task<WorkflowGraph?> FindWorkflowGraphAsync(WorkflowDefinitionFilter filter, CancellationToken cancella
 90    {
 28391        var definition = await FindWorkflowDefinitionAsync(filter, cancellationToken);
 92
 28393        if (definition == null)
 094            return null;
 95
 28396        return await MaterializeWorkflowAsync(definition, cancellationToken);
 28397    }
 98
 99    /// <inheritdoc />
 100    public async Task<IEnumerable<WorkflowGraph>> FindWorkflowGraphsAsync(WorkflowDefinitionFilter filter, CancellationT
 101    {
 0102        var workflowDefinitions = await workflowDefinitionStore.FindManyAsync(filter, cancellationToken);
 0103        var workflowGraphs = new List<WorkflowGraph>();
 0104        foreach (var workflowDefinition in workflowDefinitions)
 105        {
 0106            var workflowGraph = await MaterializeWorkflowAsync(workflowDefinition, cancellationToken);
 0107            workflowGraphs.Add(workflowGraph);
 108        }
 109
 0110        return workflowGraphs;
 0111    }
 112}