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

DemoBytom / DemoEngine / 23720751690

29 Mar 2026 10:33PM UTC coverage: 30.541% (-0.8%) from 31.336%
23720751690

push

coveralls.net

DemoBytom
WIP fixes

1276 of 4178 relevant lines covered (30.54%)

0.37 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.Requests;
8
using Mediator;
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
    IMediator mediator)
×
20
    : IHostedService,
21
      IDisposable
22
{
23
    private readonly ILogger<EngineService> _logger = logger;
×
24
    private readonly IHostApplicationLifetime _hostApplicationLifetime = hostApplicationLifetime;
×
25
    private readonly IServiceScopeFactory _scopeFactory = scopeFactory;
×
26
    private readonly IMediator _mediator = mediator;
×
27
    private readonly string _serviceName = "Engine";
×
28
    private Task? _executingTask;
29
    private bool _stopRequested;
30
    private bool _disposedValue;
31

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

37
    public Task StartAsync(CancellationToken cancellationToken)
38
    {
39
        _logger.LogServiceIsStarting(_serviceName, _version);
×
40
        _executingTask = DoWorkAsync();
×
41

42
        return _executingTask.IsCompleted
×
43
            ? _executingTask
×
44
            : Task.CompletedTask;
×
45
    }
46

47
    public async Task StopAsync(CancellationToken cancellationToken)
48
    {
49
        _logger.LogServiceStopping(_serviceName);
×
50

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

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

62
    private async Task DoWorkAsync()
63
    {
64
        await using var scope = _scopeFactory.CreateAsyncScope();
×
65
        var serviceProvider = scope.ServiceProvider;
×
66
        var mainLoopLifetime = serviceProvider.GetService<IMainLoopLifetime>();
×
67

68
        try
69
        {
70
            //var osMessageHandler = serviceProvider.GetRequiredService<IOSMessageHandler>();
71
            //var renderingEngine = serviceProvider.GetRequiredService<IRenderingEngine>();
72

73
            _ = await _mediator.Send(new CompileShaders(), _hostApplicationLifetime.ApplicationStopping);
×
74
            _ = await _mediator.Send(new LoadShadersRequest(), _hostApplicationLifetime.ApplicationStopping);
×
75

76
            var mainLoopService = serviceProvider.GetRequiredService<IMainLoopService>();
×
77
            var executeAsync = mainLoopService.ExecutingTask;
×
78

79
            var staThreadService = serviceProvider.GetRequiredService<IStaThreadService>();
×
80
            var runStaThread = staThreadService.ExecutingTask;
×
81

82
            await Task.WhenAll(
×
83
                [
×
84
                    executeAsync,
×
85
                    runStaThread
×
86
                ]);
×
87
        }
×
88
        catch (OperationCanceledException)
×
89
        {
90
            mainLoopLifetime?.Cancel();
×
91
        }
×
92
        catch (Exception ex)
×
93
        {
94
            _logger.LogServiceFailedWithError(ex, _serviceName);
×
95
        }
×
96
        finally
97
        {
98
            if (!_stopRequested)
×
99
            {
100
                await scope.DisposeAsync();
×
101
                _hostApplicationLifetime.StopApplication();
×
102
            }
103
        }
104
    }
×
105

106
    private void Dispose(bool disposing)
107
    {
108
        if (!_disposedValue)
×
109
        {
110
            if (disposing)
×
111
            {
112
                _hostApplicationLifetime.StopApplication();
×
113
            }
114

115
            _disposedValue = true;
×
116
        }
117
    }
×
118

119
    public void Dispose()
120
    {
121
        // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
122
        Dispose(disposing: true);
×
123
        GC.SuppressFinalize(this);
×
124
    }
×
125
}
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