-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (42 loc) · 1.72 KB
/
Program.cs
File metadata and controls
58 lines (42 loc) · 1.72 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
using Cocona;
using Hiky;
using Hiky.Services.DeviceConfiguration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Net;
var builder = CoconaApp.CreateBuilder(args);
// Register the DeviceConfigurationService
builder.Services.AddTransient<IDeviceConfigurationService, DeviceConfigurationService>();
// Configure HttpClient with settings from configuration - restructured to avoid multiple initializations
builder.Services.AddHttpClient(Constants.DefaultHttpClient)
.ConfigureHttpClient((sp, client) =>
{
var configService = sp.GetRequiredService<IDeviceConfigurationService>();
var config = configService.GetAsync().Result;
var url = string.Format("http://{0}:{1}/", config.IpAddress, config.Port);
client.BaseAddress = new Uri(url);
Console.WriteLine("HttpClient created with base address: " + client.BaseAddress);
})
.ConfigurePrimaryHttpMessageHandler(sp =>
{
var configService = sp.GetRequiredService<IDeviceConfigurationService>();
var config = configService.GetAsync().Result;
return new HttpClientHandler
{
PreAuthenticate = true,
Credentials = new NetworkCredential(config.Username, config.Password)
};
});
builder.Logging.AddConsole();
builder.Services.AddServices();
var app = builder.Build();
app.AddDeviceConfigurationCommand();
app.AddCheckDeviceSupportsListeningCommand();
app.AddGetListeningHostsCommand();
app.AddGetListeningHostCommand();
app.AddGetAccessControlCapabilitiesCommand();
app.AddGetAccessControlConfigurationCommand();
app.AddSetListeningHostsCommand();
app.AddListenCommand();
app.AddEnableRemoteCheckCommand();
app.Run();