feat: GSS2.Test - UI+DI, Vulkan render test

This commit is contained in:
2026-01-22 08:04:04 +03:00
parent 2ce8d3e966
commit 5af1c508f5
23 changed files with 1093 additions and 131 deletions
+4 -62
View File
@@ -1,83 +1,25 @@
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()
{
var mainWindowViewModel = Program.ApplicationHost.Services.GetRequiredService<MainWindowViewModel>();
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 (_, _) =>
desktop.MainWindow = new MainWindow()
{
await lightsService.DisconnectAsync();
await _host.StopAsync();
_host.Dispose();
DataContext = mainWindowViewModel
};
}
base.OnFrameworkInitializationCompleted();
}
}