fix(client-ui): resolve Medium code-review finding (Client.UI-005)

Call Subscriptions?.Teardown() and Alarms?.Teardown() in the Disconnected
branch of OnConnectionStateChanged so server-side session drops also
quiesce the DataChanged and AlarmEvent handlers. Add Reattach() methods
that idempotently re-hook the handlers; call them from the Connected
branch so reconnects after a server-side drop restore live updates.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-22 07:27:03 -04:00
parent af454c6af6
commit a9cede8ed4
3 changed files with 24 additions and 0 deletions

View File

@@ -215,6 +215,16 @@ public partial class AlarmsViewModel : ObservableObject
ActiveAlarmCount = 0;
}
/// <summary>
/// Re-hooks event handlers to the service after a server-side reconnect.
/// Safe to call when already attached (duplicate += is a no-op in .NET multicast delegates).
/// </summary>
public void Reattach()
{
_service.AlarmEvent -= OnAlarmEvent;
_service.AlarmEvent += OnAlarmEvent;
}
/// <summary>
/// Unhooks event handlers from the service.
/// </summary>

View File

@@ -166,6 +166,8 @@ public partial class MainWindowViewModel : ObservableObject
{
case ConnectionState.Connected:
StatusMessage = $"Connected to {EndpointUrl}";
Subscriptions?.Reattach();
Alarms?.Reattach();
break;
case ConnectionState.Reconnecting:
StatusMessage = "Reconnecting...";
@@ -177,6 +179,8 @@ public partial class MainWindowViewModel : ObservableObject
StatusMessage = "Disconnected";
SessionLabel = string.Empty;
RedundancyInfo = null;
Subscriptions?.Teardown();
Alarms?.Teardown();
BrowseTree?.Clear();
ReadWrite?.Clear();
Subscriptions?.Clear();

View File

@@ -265,6 +265,16 @@ public partial class SubscriptionsViewModel : ObservableObject
SubscriptionCount = 0;
}
/// <summary>
/// Re-hooks event handlers to the service after a server-side reconnect.
/// Safe to call when already attached (duplicate += is a no-op in .NET multicast delegates).
/// </summary>
public void Reattach()
{
_service.DataChanged -= OnDataChanged;
_service.DataChanged += OnDataChanged;
}
/// <summary>
/// Unhooks event handlers from the service.
/// </summary>