< Summary

Information
Class: Elsa.Features.Services.ShellInstalledFeatureProvider
Assembly: Elsa.Features
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Features/Services/ShellInstalledFeatureProvider.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 70
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
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%210%
List()100%210%
Find(...)0%620%
MapToElsaFeatureDescriptor(...)0%110100%
MapToFullName(...)0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Features/Services/ShellInstalledFeatureProvider.cs

#LineLine coverage
 1using CShells.Features;
 2using Elsa.Features.Contracts;
 3using Elsa.Features.Models;
 4
 5namespace Elsa.Features.Services;
 6
 7/// <summary>
 8/// Shell-based implementation of <see cref="IInstalledFeatureProvider"/> that reads from CShells feature descriptors.
 9/// </summary>
 10/// <remarks>
 11/// This implementation automatically discovers features from the shell's feature descriptors,
 12/// mapping them to Elsa's <see cref="FeatureDescriptor"/> model. Features are read from the
 13/// shell's DI container where they were registered during shell initialization.
 14/// </remarks>
 15public class ShellInstalledFeatureProvider : IInstalledFeatureProvider
 16{
 17    private readonly IEnumerable<ShellFeatureDescriptor> _shellFeatures;
 18
 19    /// <summary>
 20    /// Initializes a new instance of the <see cref="ShellInstalledFeatureProvider"/> class.
 21    /// </summary>
 022    public ShellInstalledFeatureProvider(IEnumerable<ShellFeatureDescriptor> shellFeatures)
 23    {
 024        _shellFeatures = shellFeatures;
 025    }
 26
 27    /// <inheritdoc />
 28    public IEnumerable<FeatureDescriptor> List()
 29    {
 030        return _shellFeatures
 031            .Where(sf => sf.StartupType != null)
 032            .Select(MapToElsaFeatureDescriptor);
 33    }
 34
 35    /// <inheritdoc />
 36    public FeatureDescriptor? Find(string fullName)
 37    {
 038        var shellFeature = _shellFeatures
 039            .Where(sf => sf.StartupType != null)
 040            .FirstOrDefault(sf => MapToFullName(sf) == fullName);
 41
 042        return shellFeature != null ? MapToElsaFeatureDescriptor(shellFeature) : null;
 43    }
 44
 45    private static FeatureDescriptor MapToElsaFeatureDescriptor(ShellFeatureDescriptor shell)
 46    {
 47        // Extract namespace and name from shell feature
 048        var type = shell.StartupType!;
 049        var ns = type.Namespace ?? "Unknown";
 050        var name = shell.Id;
 51
 52        // Try to get display name and description from metadata
 53        // These can be set via ShellFeatureAttribute properties
 054        var displayName = shell.Metadata.TryGetValue("DisplayName", out var dn)
 055            ? dn.ToString() ?? name
 056            : name;
 57
 058        var description = shell.Metadata.TryGetValue("Description", out var desc)
 059            ? desc.ToString() ?? string.Empty
 060            : string.Empty;
 61
 062        return new FeatureDescriptor(name, ns, displayName, description);
 63    }
 64
 65    private static string MapToFullName(ShellFeatureDescriptor shell)
 66    {
 067        var ns = shell.StartupType?.Namespace ?? "Unknown";
 068        return $"{ns}.{shell.Id}";
 69    }
 70}