Unlock progress UI:
- UnlockProgressDialog with dark-themed progress ring, phase indicator, elapsed
time, and cancel/close buttons (non-modal, draggable borderless window)
- UnlockProgressViewModel with event-driven progress tracking via IUnlockService
- Triggers on pump selection (manual or K-Line auto-detect), not test start
UnlockService rewrite:
- Persistent CAN senders that outlive the unlock sequence (StopSenders on pump change)
- Concurrent K-Line fast unlock: awaits session Connected, sends RAM timer shortcut
({02 88 02 03 A8 01 00}), verifies via CAN TestUnlock before skipping wait
- Fix Type 1 verification (Value == 0 means unlocked, was inverted)
K-Line fast unlock support:
- IKwpService.TryFastUnlockAsync / KwpService implementation
Additional features:
- ILocalizationService with ES/EN resource dictionaries and runtime switching
- Safety dialogs: VoltageWarning, OilPumpConfirm, RpmSafetyWarning
- SettingsDialog for app configuration
- BenchService enhancements, ConfigurationService improvements, PDF report updates
- All UI strings localized via DynamicResource
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
84 lines
3.6 KiB
C#
84 lines
3.6 KiB
C#
using System.Windows;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using HC_APTBS.Services;
|
|
|
|
namespace HC_APTBS.ViewModels.Dialogs
|
|
{
|
|
/// <summary>
|
|
/// ViewModel for the user authentication dialog shown before report generation.
|
|
/// Validates operator credentials against the stored user list.
|
|
/// </summary>
|
|
public sealed partial class UserCheckViewModel : ObservableObject
|
|
{
|
|
private readonly IConfigurationService _config;
|
|
private readonly ILocalizationService _loc;
|
|
|
|
/// <summary>Initialises the dialog, optionally pre-filling the last used username.</summary>
|
|
public UserCheckViewModel(IConfigurationService config, ILocalizationService loc, string lastUsername = "")
|
|
{
|
|
_config = config;
|
|
_loc = loc;
|
|
_username = lastUsername;
|
|
}
|
|
|
|
// ── Bindable properties ───────────────────────────────────────────────────
|
|
|
|
/// <summary>Username entered by the operator.</summary>
|
|
[ObservableProperty]
|
|
[NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
|
|
private string _username = string.Empty;
|
|
|
|
/// <summary>Password entered by the operator (set from code-behind PasswordChanged handler).</summary>
|
|
[ObservableProperty]
|
|
[NotifyCanExecuteChangedFor(nameof(AcceptCommand))]
|
|
private string _password = string.Empty;
|
|
|
|
// ── Dialog result ─────────────────────────────────────────────────────────
|
|
|
|
/// <summary>True if the user authenticated successfully.</summary>
|
|
public bool Accepted { get; private set; }
|
|
|
|
/// <summary>The validated username, available after <see cref="Accepted"/> is true.</summary>
|
|
public string AuthenticatedUser { get; private set; } = string.Empty;
|
|
|
|
// ── Commands ──────────────────────────────────────────────────────────────
|
|
|
|
/// <summary>Validates credentials and closes the dialog on success.</summary>
|
|
[RelayCommand(CanExecute = nameof(CanAccept))]
|
|
private void Accept()
|
|
{
|
|
if (_config.ValidateUser(Username, Password))
|
|
{
|
|
AuthenticatedUser = Username;
|
|
Accepted = true;
|
|
RequestClose?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show(
|
|
_loc.GetString("Error.AuthInvalid"),
|
|
_loc.GetString("Error.AuthTitle"),
|
|
MessageBoxButton.OK,
|
|
MessageBoxImage.Stop);
|
|
}
|
|
}
|
|
|
|
private bool CanAccept() => !string.IsNullOrWhiteSpace(Username)
|
|
&& !string.IsNullOrEmpty(Password);
|
|
|
|
/// <summary>Cancels authentication and closes the dialog.</summary>
|
|
[RelayCommand]
|
|
private void Cancel()
|
|
{
|
|
Accepted = false;
|
|
RequestClose?.Invoke();
|
|
}
|
|
|
|
// ── Events ────────────────────────────────────────────────────────────────
|
|
|
|
/// <summary>Raised when the dialog should close itself.</summary>
|
|
public event System.Action? RequestClose;
|
|
}
|
|
}
|