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:
@@ -215,6 +215,16 @@ public partial class AlarmsViewModel : ObservableObject
|
|||||||
ActiveAlarmCount = 0;
|
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>
|
/// <summary>
|
||||||
/// Unhooks event handlers from the service.
|
/// Unhooks event handlers from the service.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -166,6 +166,8 @@ public partial class MainWindowViewModel : ObservableObject
|
|||||||
{
|
{
|
||||||
case ConnectionState.Connected:
|
case ConnectionState.Connected:
|
||||||
StatusMessage = $"Connected to {EndpointUrl}";
|
StatusMessage = $"Connected to {EndpointUrl}";
|
||||||
|
Subscriptions?.Reattach();
|
||||||
|
Alarms?.Reattach();
|
||||||
break;
|
break;
|
||||||
case ConnectionState.Reconnecting:
|
case ConnectionState.Reconnecting:
|
||||||
StatusMessage = "Reconnecting...";
|
StatusMessage = "Reconnecting...";
|
||||||
@@ -177,6 +179,8 @@ public partial class MainWindowViewModel : ObservableObject
|
|||||||
StatusMessage = "Disconnected";
|
StatusMessage = "Disconnected";
|
||||||
SessionLabel = string.Empty;
|
SessionLabel = string.Empty;
|
||||||
RedundancyInfo = null;
|
RedundancyInfo = null;
|
||||||
|
Subscriptions?.Teardown();
|
||||||
|
Alarms?.Teardown();
|
||||||
BrowseTree?.Clear();
|
BrowseTree?.Clear();
|
||||||
ReadWrite?.Clear();
|
ReadWrite?.Clear();
|
||||||
Subscriptions?.Clear();
|
Subscriptions?.Clear();
|
||||||
|
|||||||
@@ -265,6 +265,16 @@ public partial class SubscriptionsViewModel : ObservableObject
|
|||||||
SubscriptionCount = 0;
|
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>
|
/// <summary>
|
||||||
/// Unhooks event handlers from the service.
|
/// Unhooks event handlers from the service.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user