-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
62 lines (52 loc) · 2.25 KB
/
Program.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
using System.IO.Ports;
using backend24.Extensions;
using backend24.Services;
using backend24.Services.DataProcessors.DataExtractors;
using backend24.Services.DataProviders;
using backend24.Services.EventFinalizers;
namespace backend24
{
public class Program
{
public static void Main(string[] args) {
// Create a builder, using the arguments passed from the command line.
var builder = WebApplication.CreateBuilder(args);
// Reset logging to the console
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
// Get the name of the serial port where data is arriving
Console.WriteLine("Enter the name of the serial port where the APC220 module is connected.\nAvailable ports are:");
Console.Write(string.Concat(SerialPort.GetPortNames().Select(x => "\t" + x + "\n")) + "> ");
string serialPortName = Console.ReadLine()!;
// Add services to the container.
// Register internal services, using keyed services
builder.Services
.AddKeyedSingleton<IDataProvider<Dictionary<SerialProvider.DataLabel, string>>, SerialProvider>(ServiceKeys.SerialProvider,
(serviceProvider, _) => ActivatorUtilities.CreateInstance<SerialProvider>(serviceProvider, serialPortName, 19200, Parity.None))
.AddKeyedSingleton<IDataProvider<float>, PressureExtractor>(ServiceKeys.PressureExtractor)
.AddKeyedSingleton<IDataProvider<float>, TemperatureExtractor>(ServiceKeys.TemperatureExtractor)
.AddKeyedSingleton<IDataProvider<float>, AltitudeExtractor>(ServiceKeys.AltitudeExtractor)
.AddFinalizer<PressureFinalizer>()
.AddFinalizer<TemperatureFinalizer>()
.AddFinalizer<AltitudeFinalizer>()
;
// This will register all classes annotated with ApiController
builder.Services.AddControllers();
// Set up Swagger/OpenAPI (learn more at https://aka.ms/aspnetcore/swashbuckle)
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// Build an app from the configuration.
var app = builder.Build();
// Configure the HTTP request pipeline.
if(app.Environment.IsDevelopment()) {
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization(); // TODO: Research this - is it necessary?
app.MapControllers();
// Start the app.
app.Run();
}
}
}