< Summary

Information
Class: Elsa.Diagnostics.ConsoleLogs.Services.ConsoleLogCaptureShellInitializer
Assembly: Elsa.Diagnostics.ConsoleLogs
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.ConsoleLogs/Services/ConsoleLogCaptureShellLease.cs
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 68
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
InitializeAsync(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.ConsoleLogs/Services/ConsoleLogCaptureShellLease.cs

#LineLine coverage
 1using ConsoleLogStreaming.Core;
 2using CShells.Lifecycle;
 3using Microsoft.Extensions.DependencyInjection;
 4
 5namespace Elsa.Diagnostics.ConsoleLogs.Services;
 6
 7public class ConsoleLogCaptureShellLease(IServiceProvider serviceProvider)
 8{
 9    private readonly SemaphoreSlim _lock = new(1, 1);
 10    private bool _started;
 11
 12    public async Task StartAsync(CancellationToken cancellationToken = default)
 13    {
 14        await _lock.WaitAsync(cancellationToken);
 15        try
 16        {
 17            if (_started)
 18                return;
 19
 20            ConsoleLogStreamingHost.AddReference();
 21            var releaseReference = true;
 22
 23            try
 24            {
 25                var capture = serviceProvider.GetRequiredService<IConsoleLogCapture>();
 26                await capture.StartAsync(cancellationToken);
 27                _started = true;
 28                releaseReference = false;
 29            }
 30            finally
 31            {
 32                if (releaseReference)
 33                    await ConsoleLogStreamingHost.ReleaseReferenceAsync(CancellationToken.None);
 34            }
 35        }
 36        finally
 37        {
 38            _lock.Release();
 39        }
 40    }
 41
 42    public async Task StopAsync(CancellationToken cancellationToken = default)
 43    {
 44        await _lock.WaitAsync(cancellationToken);
 45        try
 46        {
 47            if (!_started)
 48                return;
 49
 50            _started = false;
 51            await ConsoleLogStreamingHost.ReleaseReferenceAsync(cancellationToken);
 52        }
 53        finally
 54        {
 55            _lock.Release();
 56        }
 57    }
 58}
 59
 360public class ConsoleLogCaptureShellInitializer(ConsoleLogCaptureShellLease lease) : IShellInitializer
 61{
 262    public Task InitializeAsync(CancellationToken cancellationToken = default) => lease.StartAsync(cancellationToken);
 63}
 64
 65public class ConsoleLogCaptureShellDrainHandler(ConsoleLogCaptureShellLease lease) : IDrainHandler
 66{
 67    public Task DrainAsync(IDrainExtensionHandle extensionHandle, CancellationToken cancellationToken) => lease.StopAsyn
 68}