-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimingService.cs
More file actions
44 lines (35 loc) · 1.33 KB
/
TimingService.cs
File metadata and controls
44 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using PostSharp.Patterns.Model;
using PostSharp.Patterns.Threading;
using Serilog;
using ILogger = Serilog.ILogger;
namespace Automation
{
[Actor]
public class TimingService : IHostedService
{
[Reference] private GenericPlatform _platform;
[Reference] private readonly ILogger _log = Log.ForContext<TimingService>();
[Child] private INativeClass _nativeTimers { get; set; }
public TimingService(IOptions<AppConfig> options)
{
_platform = options.Value.Platform;
}
[Reentrant]
public async Task StartAsync(CancellationToken cancellationToken)
{
_log.Information("[Timing Service]: Calling out to the platform for native timers.");
_nativeTimers = (INativeClass)_platform.GetNativeClass("Automation", "NativeTimers");
await _nativeTimers.Initialize(this);
}
[Reentrant]
public async Task StopAsync(CancellationToken cancellationToken)
{
_log.Warning("[Timing Service]: Terminating this service.");
await _nativeTimers.Terminate("The timing service is being shut down by the host.");
}
}
}