-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
70 lines (60 loc) · 2.66 KB
/
Program.cs
File metadata and controls
70 lines (60 loc) · 2.66 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using LabTracker;
using LabTracker.Mqtt;
using LabTracker.Ssh;
using LabTracker.Unifi;
var builder = Host.CreateApplicationBuilder(args);
// Add additional configuration files
builder.Configuration.AddJsonFile("appsettings.Options.json", optional: true, reloadOnChange: true);
builder.Configuration.AddJsonFile($"appsettings.Options.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true);
// Configuration sources (in order of precedence):
// 1. Command line arguments
// 2. Environment variables
// 3. appsettings.{Environment}.json
// 4. appsettings.json
//
// Environment variable format: SectionName__PropertyName
// For arrays use: SectionName__ArrayProperty__Index
// For nested sections use: SectionName__SubSection__PropertyName
// Examples:
// Options__Unifi__AccessPoints__0=192.168.1.100
// Options__Unifi__AccessPoints__1=192.168.1.101
// Options__Unifi__PrivateKeyPath=/path/to/key
// Options__DelayMs=30000
// Options__Mqtt__BrokerHost=mqtt.example.com
// Options__Mqtt__BrokerPort=1883
// Options__UnifiApi__Key=your-api-key
// Configure options with environment variable override support
builder.Services.Configure<Options>(
builder.Configuration.GetSection(Options.SectionName));
// Register the publisher service
// To use console publisher for testing, change MqttPublisher to ConsolePublisher
builder.Services.AddSingleton<IPublisher, MqttPublisher>();
// Register the UniFi API client
builder.Services.AddSingleton<IUniFiApiClient, UniFiApiClient>();
// Register the published state reader service based on InitialState configuration
var options = builder.Configuration.GetSection(Options.SectionName).Get<Options>() ?? new Options();
switch (options.InitialState)
{
case InitialState.UnifiAPI:
builder.Services.AddSingleton<IPublished, UnifiPublishedReader>();
break;
case InitialState.MQTT:
builder.Services.AddSingleton<IPublished, MqttPublishedReader>();
break;
case InitialState.All:
builder.Services.AddSingleton<IPublished, CombinedPublishedReader>();
break;
case InitialState.None:
// Don't initialize client states - use null implementation
builder.Services.AddSingleton<IPublished, NullPublishedReader>();
break;
default:
// Use MQTT as default for backward compatibility
builder.Services.AddSingleton<IPublished, MqttPublishedReader>();
break;
}
// Register the client information provider
builder.Services.AddSingleton<IClientInfoProvider, SshClientProvider>();
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
host.Run();