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