feat: AvaloniaUi GSS2.Test

This commit is contained in:
2026-01-16 14:17:19 +03:00
parent af828a407d
commit 2ce8d3e966
11 changed files with 210 additions and 40 deletions
+83
View File
@@ -0,0 +1,83 @@
using System.Drawing;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using GSS2.Core;
using GSS2.Core.Analysis.AmineContent.Database;
using GSS2.Core.Hardware;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Console;
namespace GSS2.Test;
public partial class App : Application
{
private readonly IHost _host = BuildHostApp();
public override void Initialize()
{
_host.Start();
AvaloniaXamlLoader.Load(this);
}
private static IHost BuildHostApp()
{
var builder = Host.CreateApplicationBuilder();
builder.Logging.ClearProviders();
builder.Logging.AddConsole(options => options.FormatterName = nameof(ConsoleFormatter));
builder.Logging.AddConsoleFormatter<ConsoleFormatter, ConsoleFormatterOptions>();
builder.Logging.AddProvider(new FileLoggerProvider("app.log"));
builder.Services.AddSingleton<LibCameraLogSink>();
builder.Services.AddAmineContentCalibrationContext(builder.Configuration);
builder.Services.AddAmineContentResultsContext(builder.Configuration);
builder.Services.AddLightsService("Hardware:Lights");
builder.Services.AddTemperatureHumidityService("Hardware:TemperatureHumidity");
builder.Services.AddIlluminatorService("Hardware:Illuminator");
builder.Services.AddCameraService("Hardware:Camera", true);
var host = builder.Build();
host.Services.GetRequiredService<LibCameraLogSink>();
using (var scope = host.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<AmineContentCalibrationContext>();
context.Database.Migrate();
}
using (var scope = host.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<AmineContentResultsContext>();
context.Database.Migrate();
}
return host;
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var lightsService = _host.Services.GetRequiredService<LightsService>();
_ = lightsService.Run(CancellationToken.None);
_ = lightsService.SnowfallAsync(0.3, 1, Color.Aqua);
var cameraService = _host.Services.GetRequiredService<CameraService>();
var illuminatorService = _host.Services.GetRequiredService<IlluminatorService>();
desktop.MainWindow = new MainWindow(cameraService, illuminatorService, lightsService);
desktop.MainWindow.Closed += async (_, _) =>
{
await lightsService.DisconnectAsync();
await _host.StopAsync();
_host.Dispose();
};
}
base.OnFrameworkInitializationCompleted();
}
}