• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DemoBytom / DemoEngine / 22109264872

17 Feb 2026 05:44PM UTC coverage: 29.986% (+0.2%) from 29.787%
22109264872

push

coveralls.net

web-flow
Merge pull request #502 from DemoBytom/feature/small_fixes

Fixes #501 
Turns on several diagnostics as warnings (and thus errors):
- [CA1852](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1852)
- [CA1001](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1001)
- [CA2213](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2213)
- [CA2216](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2216)
- [CA2215](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2215)
- [CA1816](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1816)

639 of 2131 relevant lines covered (29.99%)

0.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Demo.Engine.Core/Services/EngineService.cs
1
// Copyright © Michał Dembski and contributors.
2
// Distributed under MIT license. See LICENSE file in the root for more information.
3

4
using System.Reflection;
5
using Demo.Engine.Core.Features.StaThread;
6
using Demo.Engine.Core.Interfaces;
7
using Demo.Engine.Core.Interfaces.Platform;
8
using Demo.Engine.Core.Interfaces.Rendering;
9
using Microsoft.Extensions.DependencyInjection;
10
using Microsoft.Extensions.Hosting;
11
using Microsoft.Extensions.Logging;
12

13
namespace Demo.Engine.Core.Services;
14

15
internal sealed class EngineService(
×
16
    ILogger<EngineService> logger,
×
17
    IHostApplicationLifetime hostApplicationLifetime,
×
18
    IServiceScopeFactory scopeFactory)
×
19
    : IHostedService,
20
      IDisposable
21
{
22
    private readonly ILogger<EngineService> _logger = logger;
×
23
    private readonly IHostApplicationLifetime _hostApplicationLifetime = hostApplicationLifetime;
×
24
    private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
×
25
    private readonly string _serviceName = "Engine";
×
26
    private Task? _executingTask;
27
    private bool _stopRequested;
28
    private bool _disposedValue;
29

30
    private readonly string _version = Assembly
×
31
        .GetEntryAssembly()
×
32
        ?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
×
33
        ?.InformationalVersion ?? "0.0.0";
×
34

35
    public Task StartAsync(CancellationToken cancellationToken)
36
    {
37
        _logger.LogInformation("{serviceName} starting! v{version}", _serviceName, _version);
×
38
        _executingTask = DoWorkAsync();
×
39

40
        return _executingTask.IsCompleted
×
41
            ? _executingTask
×
42
            : Task.CompletedTask;
×
43
    }
44

45
    public async Task StopAsync(CancellationToken cancellationToken)
46
    {
47
        _logger.LogInformation("{serviceName} stopping!", _serviceName);
×
48

49
        _stopRequested = true;
×
50
        if (_executingTask is null)
×
51
        {
52
            return;
×
53
        }
54

55
        _ = await Task.WhenAny(
×
56
            _executingTask,
×
57
            Task.Delay(Timeout.Infinite, cancellationToken));
×
58
    }
×
59

60
    private async Task DoWorkAsync()
61
    {
62
        using var scope = _scopeFactory.CreateScope();
×
63
        var serviceProvider = scope.ServiceProvider;
×
64
        var mainLoopLifetime = serviceProvider.GetService<IMainLoopLifetime>();
×
65

66
        try
67
        {
68
            var osMessageHandler = serviceProvider.GetRequiredService<IOSMessageHandler>();
×
69
            var renderingEngine = serviceProvider.GetRequiredService<IRenderingEngine>();
×
70

71
            var mainLoopService = serviceProvider.GetRequiredService<IMainLoopService>();
×
72
            var executeAsync = mainLoopService.ExecutingTask;
×
73

74
            var staThreadService = serviceProvider.GetRequiredService<IStaThreadService>();
×
75
            var runStaThread = staThreadService.ExecutingTask;
×
76

77
            await Task.WhenAll(
×
78
                [
×
79
                    executeAsync,
×
80
                    runStaThread
×
81
                ]);
×
82
        }
×
83
        catch (OperationCanceledException)
×
84
        {
85
            mainLoopLifetime?.Cancel();
×
86
        }
×
87
        catch (Exception ex)
×
88
        {
89
            _logger.LogCritical(ex, "{serviceName} failed with error! {errorMessage}", _serviceName, ex.Message);
×
90
        }
×
91
        finally
92
        {
93
            if (!_stopRequested)
×
94
            {
95
                _hostApplicationLifetime.StopApplication();
×
96
            }
97
        }
98
    }
×
99

100
    private void Dispose(bool disposing)
101
    {
102
        if (!_disposedValue)
×
103
        {
104
            if (disposing)
×
105
            {
106
                _hostApplicationLifetime.StopApplication();
×
107
            }
108

109
            _disposedValue = true;
×
110
        }
111
    }
×
112

113
    public void Dispose()
114
    {
115
        // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
116
        Dispose(disposing: true);
×
117
        GC.SuppressFinalize(this);
×
118
    }
×
119
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc