Files
HC_APTBS/App.xaml.cs
LucianoDev 0280a2fad1 feat: page-based navigation shell + Tests page wizard
Replace the monolithic MainWindow with a SelectedPage-driven shell
(Dashboard / Pump / Bench / Tests / Results / Settings). The Tests
page gets the Plan -> Preconditions -> Running -> Done wizard from
ui-structure.md \u00a74, backed by a 7-item precondition gate and
shared sub-views (PhaseCardView / TestSectionView / GraphicIndicatorView)
extracted from the now-deleted monolithic TestPanelView.

New VMs / views:
- Tests wizard: TestPreconditions, PhaseCard, GraphicIndicator,
  TestSection, TestPlan, TestRunning, TestDone
- Dashboard panels: DashboardConnection, DashboardReadings,
  DashboardAlarms, InterlockBanner, ResultHistory
- Pump / bench panels: PumpIdentificationPanel, PumpLiveData,
  UnlockPanel, BenchDriveControl, BenchReadings, RelayBank,
  TemperatureControl, DtcList, AuthGate
- Dialogs: generic ConfirmDialog, UserManageDialog, UserPromptDialog

Supporting changes:
- IsOilPumpOn exposed on MainViewModel for precondition evaluation
- RequiresAuth added to TestDefinition (XML round-trip)
- BipStatusDefinition + CompletedTestRun models
- ~35 new Test.* localization keys (en + es)
- Settings moved from modal dialog to full page
- Pause / Retry / Skip stubs in TestRunningView; full spec in
  docs/gap-test-running-controls.md for follow-up implementation
- docs/ui-structure.md captures the wizard design

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-18 13:11:34 +02:00

88 lines
3.9 KiB
C#

using System.Windows;
using HC_APTBS.Infrastructure.Logging;
using HC_APTBS.Infrastructure.Pcan;
using HC_APTBS.Models;
using HC_APTBS.Services;
using HC_APTBS.Services.Impl;
using HC_APTBS.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Peak.Can.Basic;
namespace HC_APTBS;
/// <summary>
/// Application entry-point and DI container host.
///
/// <para>
/// Registers all services, ViewModels, and the main window with
/// <see cref="ServiceCollection"/>, then resolves and shows <see cref="MainWindow"/>
/// on startup. The container is disposed when the application exits.
/// </para>
/// </summary>
public partial class App : Application
{
private ServiceProvider? _serviceProvider;
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
// Wire runtime-warning hooks on pure Model classes before any config is loaded.
// Keeps the Models layer DI-free while still routing warnings through IAppLogger.
var logger = _serviceProvider.GetRequiredService<IAppLogger>();
CanBusParameter.WarningLogger = logger.Warning;
SensorConfiguration.WarningLogger = logger.Warning;
// Initialise the ViewModel (loads pump IDs, starts refresh timer, connects CAN).
var mainVm = _serviceProvider.GetRequiredService<MainViewModel>();
await mainVm.InitialiseAsync();
var window = _serviceProvider.GetRequiredService<MainWindow>();
window.Show();
}
protected override void OnExit(ExitEventArgs e)
{
_serviceProvider?.Dispose();
base.OnExit(e);
}
// ── Service registration ──────────────────────────────────────────────────
private static void ConfigureServices(IServiceCollection services)
{
// ── Infrastructure ────────────────────────────────────────────────────
services.AddSingleton<IAppLogger, AppLogger>();
// PcanAdapter requires a channel handle and baudrate read from configuration.
services.AddSingleton<ICanService>(sp =>
{
var cfg = sp.GetRequiredService<IConfigurationService>();
var logger = sp.GetRequiredService<IAppLogger>();
var channel = cfg.Bench.Channel;
// Default to 500 kbps; the channel can switch at runtime via ICanService.SwitchBaudrate.
return new PcanAdapter(channel, TPCANBaudrate.PCAN_BAUD_500K, logger);
});
services.AddSingleton<IKwpService, KwpService>();
// ── Application services ──────────────────────────────────────────────
services.AddSingleton<IConfigurationService, ConfigurationService>();
services.AddSingleton<IBenchService, BenchService>();
services.AddSingleton<IUnlockService, UnlockService>();
services.AddSingleton<ICalibrationService, CalibrationService>();
services.AddSingleton<IPdfService, PdfService>();
services.AddSingleton<ILocalizationService, LocalizationService>();
// ── ViewModels ────────────────────────────────────────────────────────
services.AddSingleton<MainViewModel>();
// ── Views ─────────────────────────────────────────────────────────────
services.AddSingleton<MainWindow>();
}
}