-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTradingEngineServer.cs
67 lines (50 loc) · 2.75 KB
/
TradingEngineServer.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
// This is our configuration file namespace
using TradingEngineServer.Core.Configuration;
namespace TradingEngineServer.Core{
// Maknig my Trading Engine a background service, and also an ITradingEngineServer
// Now I have access to many things
// Sealed means that no derived class can override functions in this class
sealed class TradingEngineServer : BackgroundService, ITradingEngineServer {
// Member variables
// Storing the logger
private readonly ILogger<TradingEngineServer> _logger;
// Storing the configuration
private readonly TradingEngineServerConfiguration _tradingEngineServerConfig;
// Constructor
public TradingEngineServer(ILogger<TradingEngineServer> logger,
IOptions<TradingEngineServerConfiguration> config){
// ?? is the null coalescing operator
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
// This is injecting the configuration server
// Value retursn the value of the IOptions
_tradingEngineServerConfig = config.Value ?? throw new ArgumentNullException(nameof(config));
}
// Forwarding the function for execute async to run it
// This way, we now have a public way to call ExecuteAsync!
// We don't need this, because microsoft library for hosting, so Microsfot.Extensions.Hosting will call executeAsync for us, so we implemented this all ourself.
public Task Run(CancellationToken token) => ExecuteAsync(token);
// This is our executed Async
// Backrournd Service has this function. We need to make this avialable publicly.
// We will do this through an interaface because this is private in the BackgroundSerivce Parent Class
// We can do this through a Task
// See above
protected override Task ExecuteAsync(CancellationToken stoppingToken){
// This toekn is what is passing through to CancellationToken
// CancellationTokenSource cancel = new //CancellationTokenSource();
// cancel.Cancel();
// cancel.Dispose();
// cancel.Token;
_logger.LogInformation($"Starting {nameof(TradingEngineServer)}");
while (!stoppingToken.IsCancellationRequested){
// _logger.LogInformation("running");
}
_logger.LogInformation("hfsdfsd\n");
_logger.LogInformation($"{stoppingToken.IsCancellationRequested}");
_logger.LogInformation($"Stopping {nameof(TradingEngineServer)} boiiii");
return Task.CompletedTask;
}
}
}