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
2.9 KiB
C#
84 lines
2.9 KiB
C#
using System;
|
|
using System.Windows;
|
|
|
|
namespace HC_APTBS.Services.Impl
|
|
{
|
|
/// <summary>
|
|
/// Manages runtime language switching by swapping a merged
|
|
/// <see cref="ResourceDictionary"/> in <see cref="Application.Current"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// On construction the service reads <see cref="Models.AppSettings.Language"/>
|
|
/// and loads the corresponding dictionary. Subsequent calls to
|
|
/// <see cref="SetLanguage"/> replace it in-place and persist the preference.
|
|
/// </remarks>
|
|
public sealed class LocalizationService : ILocalizationService
|
|
{
|
|
private const string EspUri = "pack://application:,,,/Resources/Strings.es.xaml";
|
|
private const string EngUri = "pack://application:,,,/Resources/Strings.en.xaml";
|
|
|
|
private readonly IConfigurationService _config;
|
|
private ResourceDictionary? _currentDictionary;
|
|
|
|
/// <inheritdoc />
|
|
public string CurrentLanguage { get; private set; } = "ESP";
|
|
|
|
/// <inheritdoc />
|
|
public event Action? LanguageChanged;
|
|
|
|
/// <summary>
|
|
/// Initialises the localization service and loads the language
|
|
/// stored in <see cref="Models.AppSettings.Language"/>.
|
|
/// </summary>
|
|
public LocalizationService(IConfigurationService config)
|
|
{
|
|
_config = config;
|
|
// Load persisted language without saving (already persisted).
|
|
LoadDictionary(_config.Settings.Language);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public void SetLanguage(string languageCode)
|
|
{
|
|
var code = NormaliseCode(languageCode);
|
|
if (code == CurrentLanguage)
|
|
return;
|
|
|
|
LoadDictionary(code);
|
|
|
|
// Persist the choice.
|
|
_config.Settings.Language = code;
|
|
_config.SaveSettings();
|
|
|
|
LanguageChanged?.Invoke();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public string GetString(string key)
|
|
{
|
|
return Application.Current.Resources[key]?.ToString() ?? key;
|
|
}
|
|
|
|
// ── Helpers ──────────────────────────────────────────────────────────────
|
|
|
|
private void LoadDictionary(string languageCode)
|
|
{
|
|
var code = NormaliseCode(languageCode);
|
|
var uri = code == "ENG" ? EngUri : EspUri;
|
|
|
|
var dict = new ResourceDictionary { Source = new Uri(uri, UriKind.Absolute) };
|
|
|
|
var merged = Application.Current.Resources.MergedDictionaries;
|
|
if (_currentDictionary != null)
|
|
merged.Remove(_currentDictionary);
|
|
|
|
merged.Add(dict);
|
|
_currentDictionary = dict;
|
|
CurrentLanguage = code;
|
|
}
|
|
|
|
private static string NormaliseCode(string code) =>
|
|
string.Equals(code, "ENG", StringComparison.OrdinalIgnoreCase) ? "ENG" : "ESP";
|
|
}
|
|
}
|