< Summary

Information
Class: Elsa.WorkflowProviders.BlobStorage.ElsaScript.Handlers.ElsaScriptBlobWorkflowFormatHandler
Assembly: Elsa.WorkflowProviders.BlobStorage.ElsaScript
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.WorkflowProviders.BlobStorage.ElsaScript/Handlers/ElsaScriptBlobWorkflowFormatHandler.cs
Line coverage
11%
Covered lines: 2
Uncovered lines: 16
Coverable lines: 18
Total lines: 60
Line coverage: 11.1%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Name()100%210%
get_SupportedExtensions()100%11100%
CanHandle(...)0%620%
TryParseAsync()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.WorkflowProviders.BlobStorage.ElsaScript/Handlers/ElsaScriptBlobWorkflowFormatHandler.cs

#LineLine coverage
 1using Elsa.Dsl.ElsaScript.Contracts;
 2using Elsa.Dsl.ElsaScript.Materializers;
 3using Elsa.WorkflowProviders.BlobStorage.Contracts;
 4using Elsa.Workflows.Runtime;
 5using FluentStorage.Blobs;
 6using Microsoft.Extensions.Logging;
 7
 8namespace Elsa.WorkflowProviders.BlobStorage.ElsaScript.Handlers;
 9
 10/// <summary>
 11/// Handles ElsaScript-formatted workflow definitions from blob storage.
 12/// </summary>
 26613public class ElsaScriptBlobWorkflowFormatHandler(IElsaScriptCompiler compiler, ILogger<ElsaScriptBlobWorkflowFormatHandl
 14{
 15    /// <inheritdoc />
 016    public string Name => "ElsaScript";
 17
 18    /// <inheritdoc />
 819    public IEnumerable<string> SupportedExtensions => ["elsa"];
 20
 21    /// <inheritdoc />
 22    public bool CanHandle(Blob blob, string? contentType)
 23    {
 24        // Extension filtering is already handled by the provider via SupportedExtensions.
 25        // Here we can optionally check content type for additional validation.
 026        if (!string.IsNullOrEmpty(contentType) && contentType.Contains("elsa", StringComparison.OrdinalIgnoreCase))
 027            return true;
 28
 29        // If no content type is available, assume we can handle it (since extension was already validated)
 030        return true;
 31    }
 32
 33    /// <inheritdoc />
 34    public async ValueTask<MaterializedWorkflow?> TryParseAsync(Blob blob, string content, CancellationToken cancellatio
 35    {
 36        try
 37        {
 038            var workflow = await compiler.CompileAsync(content, cancellationToken);
 39
 040            return new(
 041                workflow,
 042                ProviderName: "FluentStorage",
 043                MaterializerName: ElsaScriptWorkflowMaterializer.MaterializerName,
 044                MaterializerContext: null,
 045                OriginalSource: content // Preserve the original ElsaScript source
 046            );
 47        }
 048        catch (Exception ex)
 49        {
 50            // Intentionally catching all exceptions here to gracefully handle any failure during workflow parsing.
 51            // This includes ParseException, IOException, compiler errors, or any unexpected exceptions.
 52            // Since this is a format handler for user-provided files, we want to log and skip invalid files
 53            // rather than crashing the workflow loading process.
 054            logger.LogWarning(ex, "Failed to parse ElsaScript workflow from blob '{BlobPath}'. The file will be skipped.
 55
 56            // Return null to indicate this handler can't process the content
 057            return null;
 58        }
 059    }
 60}