Apply code style formatting and restore partial modifiers on Avalonia views
Linter/formatter pass across the full codebase. Restores required partial keyword on AXAML code-behind classes that the formatter incorrectly removed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,19 +3,10 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a single alarm event row.
|
||||
/// Represents a single alarm event row.
|
||||
/// </summary>
|
||||
public partial class AlarmEventViewModel : ObservableObject
|
||||
public class AlarmEventViewModel : ObservableObject
|
||||
{
|
||||
public string SourceName { get; }
|
||||
public string ConditionName { get; }
|
||||
public ushort Severity { get; }
|
||||
public string Message { get; }
|
||||
public bool Retain { get; }
|
||||
public bool ActiveState { get; }
|
||||
public bool AckedState { get; }
|
||||
public DateTime Time { get; }
|
||||
|
||||
public AlarmEventViewModel(
|
||||
string sourceName,
|
||||
string conditionName,
|
||||
@@ -35,4 +26,13 @@ public partial class AlarmEventViewModel : ObservableObject
|
||||
AckedState = ackedState;
|
||||
Time = time;
|
||||
}
|
||||
}
|
||||
|
||||
public string SourceName { get; }
|
||||
public string ConditionName { get; }
|
||||
public ushort Severity { get; }
|
||||
public string Message { get; }
|
||||
public bool Retain { get; }
|
||||
public bool ActiveState { get; }
|
||||
public bool AckedState { get; }
|
||||
public DateTime Time { get; }
|
||||
}
|
||||
@@ -9,27 +9,14 @@ using ZB.MOM.WW.LmxOpcUa.Client.UI.Services;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel for the alarms panel.
|
||||
/// ViewModel for the alarms panel.
|
||||
/// </summary>
|
||||
public partial class AlarmsViewModel : ObservableObject
|
||||
{
|
||||
private readonly IOpcUaClientService _service;
|
||||
private readonly IUiDispatcher _dispatcher;
|
||||
private readonly IOpcUaClientService _service;
|
||||
|
||||
/// <summary>Received alarm events.</summary>
|
||||
public ObservableCollection<AlarmEventViewModel> AlarmEvents { get; } = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _monitoredNodeIdText;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _interval = 1000;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(SubscribeCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(UnsubscribeCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(RefreshCommand))]
|
||||
private bool _isSubscribed;
|
||||
[ObservableProperty] private int _interval = 1000;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(SubscribeCommand))]
|
||||
@@ -37,6 +24,14 @@ public partial class AlarmsViewModel : ObservableObject
|
||||
[NotifyCanExecuteChangedFor(nameof(RefreshCommand))]
|
||||
private bool _isConnected;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(SubscribeCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(UnsubscribeCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(RefreshCommand))]
|
||||
private bool _isSubscribed;
|
||||
|
||||
[ObservableProperty] private string? _monitoredNodeIdText;
|
||||
|
||||
public AlarmsViewModel(IOpcUaClientService service, IUiDispatcher dispatcher)
|
||||
{
|
||||
_service = service;
|
||||
@@ -44,6 +39,9 @@ public partial class AlarmsViewModel : ObservableObject
|
||||
_service.AlarmEvent += OnAlarmEvent;
|
||||
}
|
||||
|
||||
/// <summary>Received alarm events.</summary>
|
||||
public ObservableCollection<AlarmEventViewModel> AlarmEvents { get; } = [];
|
||||
|
||||
private void OnAlarmEvent(object? sender, AlarmEventArgs e)
|
||||
{
|
||||
_dispatcher.Post(() =>
|
||||
@@ -60,14 +58,17 @@ public partial class AlarmsViewModel : ObservableObject
|
||||
});
|
||||
}
|
||||
|
||||
private bool CanSubscribe() => IsConnected && !IsSubscribed;
|
||||
private bool CanSubscribe()
|
||||
{
|
||||
return IsConnected && !IsSubscribed;
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanSubscribe))]
|
||||
private async Task SubscribeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
NodeId? sourceNodeId = string.IsNullOrWhiteSpace(MonitoredNodeIdText)
|
||||
var sourceNodeId = string.IsNullOrWhiteSpace(MonitoredNodeIdText)
|
||||
? null
|
||||
: NodeId.Parse(MonitoredNodeIdText);
|
||||
|
||||
@@ -80,7 +81,10 @@ public partial class AlarmsViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanUnsubscribe() => IsConnected && IsSubscribed;
|
||||
private bool CanUnsubscribe()
|
||||
{
|
||||
return IsConnected && IsSubscribed;
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanUnsubscribe))]
|
||||
private async Task UnsubscribeAsync()
|
||||
@@ -110,7 +114,7 @@ public partial class AlarmsViewModel : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears alarm events and resets state.
|
||||
/// Clears alarm events and resets state.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
@@ -119,10 +123,10 @@ public partial class AlarmsViewModel : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unhooks event handlers from the service.
|
||||
/// Unhooks event handlers from the service.
|
||||
/// </summary>
|
||||
public void Teardown()
|
||||
{
|
||||
_service.AlarmEvent -= OnAlarmEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,12 @@ using ZB.MOM.WW.LmxOpcUa.Client.UI.Services;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel for the OPC UA browse tree panel.
|
||||
/// ViewModel for the OPC UA browse tree panel.
|
||||
/// </summary>
|
||||
public partial class BrowseTreeViewModel : ObservableObject
|
||||
public class BrowseTreeViewModel : ObservableObject
|
||||
{
|
||||
private readonly IOpcUaClientService _service;
|
||||
private readonly IUiDispatcher _dispatcher;
|
||||
|
||||
/// <summary>Top-level nodes in the browse tree.</summary>
|
||||
public ObservableCollection<TreeNodeViewModel> RootNodes { get; } = new();
|
||||
private readonly IOpcUaClientService _service;
|
||||
|
||||
public BrowseTreeViewModel(IOpcUaClientService service, IUiDispatcher dispatcher)
|
||||
{
|
||||
@@ -22,18 +19,20 @@ public partial class BrowseTreeViewModel : ObservableObject
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
/// <summary>Top-level nodes in the browse tree.</summary>
|
||||
public ObservableCollection<TreeNodeViewModel> RootNodes { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Loads root nodes by browsing with a null parent.
|
||||
/// Loads root nodes by browsing with a null parent.
|
||||
/// </summary>
|
||||
public async Task LoadRootsAsync()
|
||||
{
|
||||
var results = await _service.BrowseAsync(null);
|
||||
var results = await _service.BrowseAsync();
|
||||
|
||||
_dispatcher.Post(() =>
|
||||
{
|
||||
RootNodes.Clear();
|
||||
foreach (var result in results)
|
||||
{
|
||||
RootNodes.Add(new TreeNodeViewModel(
|
||||
result.NodeId,
|
||||
result.DisplayName,
|
||||
@@ -41,15 +40,14 @@ public partial class BrowseTreeViewModel : ObservableObject
|
||||
result.HasChildren,
|
||||
_service,
|
||||
_dispatcher));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all root nodes from the tree.
|
||||
/// Clears all root nodes from the tree.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
RootNodes.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,10 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a single historical value row.
|
||||
/// Represents a single historical value row.
|
||||
/// </summary>
|
||||
public partial class HistoryValueViewModel : ObservableObject
|
||||
public class HistoryValueViewModel : ObservableObject
|
||||
{
|
||||
public string Value { get; }
|
||||
public string Status { get; }
|
||||
public string SourceTimestamp { get; }
|
||||
public string ServerTimestamp { get; }
|
||||
|
||||
public HistoryValueViewModel(string value, string status, string sourceTimestamp, string serverTimestamp)
|
||||
{
|
||||
Value = value;
|
||||
@@ -19,4 +14,9 @@ public partial class HistoryValueViewModel : ObservableObject
|
||||
SourceTimestamp = sourceTimestamp;
|
||||
ServerTimestamp = serverTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
public string Value { get; }
|
||||
public string Status { get; }
|
||||
public string SourceTimestamp { get; }
|
||||
public string ServerTimestamp { get; }
|
||||
}
|
||||
@@ -9,55 +9,30 @@ using ZB.MOM.WW.LmxOpcUa.Client.UI.Services;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel for the history panel.
|
||||
/// ViewModel for the history panel.
|
||||
/// </summary>
|
||||
public partial class HistoryViewModel : ObservableObject
|
||||
{
|
||||
private readonly IOpcUaClientService _service;
|
||||
private readonly IUiDispatcher _dispatcher;
|
||||
private readonly IOpcUaClientService _service;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(ReadHistoryCommand))]
|
||||
private string? _selectedNodeId;
|
||||
[ObservableProperty] private DateTimeOffset _endTime = DateTimeOffset.UtcNow;
|
||||
|
||||
[ObservableProperty]
|
||||
private DateTimeOffset _startTime = DateTimeOffset.UtcNow.AddHours(-1);
|
||||
[ObservableProperty] private double _intervalMs = 3600000;
|
||||
|
||||
[ObservableProperty]
|
||||
private DateTimeOffset _endTime = DateTimeOffset.UtcNow;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _maxValues = 1000;
|
||||
|
||||
[ObservableProperty]
|
||||
private AggregateType? _selectedAggregateType;
|
||||
|
||||
/// <summary>Available aggregate types (null means "Raw").</summary>
|
||||
public IReadOnlyList<AggregateType?> AggregateTypes { get; } = new AggregateType?[]
|
||||
{
|
||||
null,
|
||||
AggregateType.Average,
|
||||
AggregateType.Minimum,
|
||||
AggregateType.Maximum,
|
||||
AggregateType.Count,
|
||||
AggregateType.Start,
|
||||
AggregateType.End
|
||||
};
|
||||
|
||||
[ObservableProperty]
|
||||
private double _intervalMs = 3600000;
|
||||
|
||||
public bool IsAggregateRead => SelectedAggregateType != null;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLoading;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(ReadHistoryCommand))]
|
||||
[ObservableProperty] [NotifyCanExecuteChangedFor(nameof(ReadHistoryCommand))]
|
||||
private bool _isConnected;
|
||||
|
||||
/// <summary>History read results.</summary>
|
||||
public ObservableCollection<HistoryValueViewModel> Results { get; } = new();
|
||||
[ObservableProperty] private bool _isLoading;
|
||||
|
||||
[ObservableProperty] private int _maxValues = 1000;
|
||||
|
||||
[ObservableProperty] private AggregateType? _selectedAggregateType;
|
||||
|
||||
[ObservableProperty] [NotifyCanExecuteChangedFor(nameof(ReadHistoryCommand))]
|
||||
private string? _selectedNodeId;
|
||||
|
||||
[ObservableProperty] private DateTimeOffset _startTime = DateTimeOffset.UtcNow.AddHours(-1);
|
||||
|
||||
public HistoryViewModel(IOpcUaClientService service, IUiDispatcher dispatcher)
|
||||
{
|
||||
@@ -65,12 +40,32 @@ public partial class HistoryViewModel : ObservableObject
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
/// <summary>Available aggregate types (null means "Raw").</summary>
|
||||
public IReadOnlyList<AggregateType?> AggregateTypes { get; } =
|
||||
[
|
||||
null,
|
||||
AggregateType.Average,
|
||||
AggregateType.Minimum,
|
||||
AggregateType.Maximum,
|
||||
AggregateType.Count,
|
||||
AggregateType.Start,
|
||||
AggregateType.End
|
||||
];
|
||||
|
||||
public bool IsAggregateRead => SelectedAggregateType != null;
|
||||
|
||||
/// <summary>History read results.</summary>
|
||||
public ObservableCollection<HistoryValueViewModel> Results { get; } = [];
|
||||
|
||||
partial void OnSelectedAggregateTypeChanged(AggregateType? value)
|
||||
{
|
||||
OnPropertyChanged(nameof(IsAggregateRead));
|
||||
}
|
||||
|
||||
private bool CanReadHistory() => IsConnected && !string.IsNullOrEmpty(SelectedNodeId);
|
||||
private bool CanReadHistory()
|
||||
{
|
||||
return IsConnected && !string.IsNullOrEmpty(SelectedNodeId);
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanReadHistory))]
|
||||
private async Task ReadHistoryAsync()
|
||||
@@ -86,33 +81,27 @@ public partial class HistoryViewModel : ObservableObject
|
||||
IReadOnlyList<DataValue> values;
|
||||
|
||||
if (SelectedAggregateType != null)
|
||||
{
|
||||
values = await _service.HistoryReadAggregateAsync(
|
||||
nodeId,
|
||||
StartTime.UtcDateTime,
|
||||
EndTime.UtcDateTime,
|
||||
SelectedAggregateType.Value,
|
||||
IntervalMs);
|
||||
}
|
||||
else
|
||||
{
|
||||
values = await _service.HistoryReadRawAsync(
|
||||
nodeId,
|
||||
StartTime.UtcDateTime,
|
||||
EndTime.UtcDateTime,
|
||||
MaxValues);
|
||||
}
|
||||
|
||||
_dispatcher.Post(() =>
|
||||
{
|
||||
foreach (var dv in values)
|
||||
{
|
||||
Results.Add(new HistoryValueViewModel(
|
||||
dv.Value?.ToString() ?? "(null)",
|
||||
dv.StatusCode.ToString(),
|
||||
dv.SourceTimestamp.ToString("O"),
|
||||
dv.ServerTimestamp.ToString("O")));
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -130,11 +119,11 @@ public partial class HistoryViewModel : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears results and resets state.
|
||||
/// Clears results and resets state.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
Results.Clear();
|
||||
SelectedNodeId = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,78 +8,49 @@ using ZB.MOM.WW.LmxOpcUa.Client.UI.Services;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Main window ViewModel coordinating all panels.
|
||||
/// Main window ViewModel coordinating all panels.
|
||||
/// </summary>
|
||||
public partial class MainWindowViewModel : ObservableObject
|
||||
{
|
||||
private readonly IOpcUaClientService _service;
|
||||
private readonly IUiDispatcher _dispatcher;
|
||||
private readonly IOpcUaClientService _service;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _endpointUrl = "opc.tcp://localhost:4840";
|
||||
[ObservableProperty] private bool _autoAcceptCertificates = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _username;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _password;
|
||||
|
||||
[ObservableProperty]
|
||||
private SecurityMode _selectedSecurityMode = SecurityMode.None;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _failoverUrls;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _sessionTimeoutSeconds = 60;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _autoAcceptCertificates = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _certificateStorePath = Path.Combine(
|
||||
[ObservableProperty] private string _certificateStorePath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"LmxOpcUaClient", "pki");
|
||||
|
||||
/// <summary>All available security modes.</summary>
|
||||
public IReadOnlyList<SecurityMode> SecurityModes { get; } = Enum.GetValues<SecurityMode>();
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(ConnectCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(DisconnectCommand))]
|
||||
private ConnectionState _connectionState = ConnectionState.Disconnected;
|
||||
|
||||
public bool IsConnected => ConnectionState == ConnectionState.Connected;
|
||||
[ObservableProperty] private string _endpointUrl = "opc.tcp://localhost:4840";
|
||||
|
||||
[ObservableProperty]
|
||||
private TreeNodeViewModel? _selectedTreeNode;
|
||||
[ObservableProperty] private string? _failoverUrls;
|
||||
|
||||
[ObservableProperty]
|
||||
private RedundancyInfo? _redundancyInfo;
|
||||
[ObservableProperty] private bool _isHistoryEnabledForSelection;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _statusMessage = "Disconnected";
|
||||
[ObservableProperty] private string? _password;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _sessionLabel = string.Empty;
|
||||
[ObservableProperty] private RedundancyInfo? _redundancyInfo;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _subscriptionCount;
|
||||
[ObservableProperty] private SecurityMode _selectedSecurityMode = SecurityMode.None;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _selectedTabIndex;
|
||||
[ObservableProperty] private int _selectedTabIndex;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isHistoryEnabledForSelection;
|
||||
[ObservableProperty] private TreeNodeViewModel? _selectedTreeNode;
|
||||
|
||||
/// <summary>The currently selected tree nodes (supports multi-select).</summary>
|
||||
public ObservableCollection<TreeNodeViewModel> SelectedTreeNodes { get; } = new();
|
||||
[ObservableProperty] private string _sessionLabel = string.Empty;
|
||||
|
||||
public BrowseTreeViewModel BrowseTree { get; }
|
||||
public ReadWriteViewModel ReadWrite { get; }
|
||||
public SubscriptionsViewModel Subscriptions { get; }
|
||||
public AlarmsViewModel Alarms { get; }
|
||||
public HistoryViewModel History { get; }
|
||||
[ObservableProperty] private int _sessionTimeoutSeconds = 60;
|
||||
|
||||
[ObservableProperty] private string _statusMessage = "Disconnected";
|
||||
|
||||
[ObservableProperty] private int _subscriptionCount;
|
||||
|
||||
[ObservableProperty] private string? _username;
|
||||
|
||||
public MainWindowViewModel(IOpcUaClientServiceFactory factory, IUiDispatcher dispatcher)
|
||||
{
|
||||
@@ -95,12 +66,23 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
_service.ConnectionStateChanged += OnConnectionStateChanged;
|
||||
}
|
||||
|
||||
/// <summary>All available security modes.</summary>
|
||||
public IReadOnlyList<SecurityMode> SecurityModes { get; } = Enum.GetValues<SecurityMode>();
|
||||
|
||||
public bool IsConnected => ConnectionState == ConnectionState.Connected;
|
||||
|
||||
/// <summary>The currently selected tree nodes (supports multi-select).</summary>
|
||||
public ObservableCollection<TreeNodeViewModel> SelectedTreeNodes { get; } = [];
|
||||
|
||||
public BrowseTreeViewModel BrowseTree { get; }
|
||||
public ReadWriteViewModel ReadWrite { get; }
|
||||
public SubscriptionsViewModel Subscriptions { get; }
|
||||
public AlarmsViewModel Alarms { get; }
|
||||
public HistoryViewModel History { get; }
|
||||
|
||||
private void OnConnectionStateChanged(object? sender, ConnectionStateChangedEventArgs e)
|
||||
{
|
||||
_dispatcher.Post(() =>
|
||||
{
|
||||
ConnectionState = e.NewState;
|
||||
});
|
||||
_dispatcher.Post(() => { ConnectionState = e.NewState; });
|
||||
}
|
||||
|
||||
partial void OnConnectionStateChanged(ConnectionState value)
|
||||
@@ -144,7 +126,10 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
History.SelectedNodeId = value?.NodeId;
|
||||
}
|
||||
|
||||
private bool CanConnect() => ConnectionState == ConnectionState.Disconnected;
|
||||
private bool CanConnect()
|
||||
{
|
||||
return ConnectionState == ConnectionState.Disconnected;
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanConnect))]
|
||||
private async Task ConnectAsync()
|
||||
@@ -199,8 +184,11 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanDisconnect() => ConnectionState == ConnectionState.Connected
|
||||
|| ConnectionState == ConnectionState.Reconnecting;
|
||||
private bool CanDisconnect()
|
||||
{
|
||||
return ConnectionState == ConnectionState.Connected
|
||||
|| ConnectionState == ConnectionState.Reconnecting;
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanDisconnect))]
|
||||
private async Task DisconnectAsync()
|
||||
@@ -217,15 +205,12 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dispatcher.Post(() =>
|
||||
{
|
||||
ConnectionState = ConnectionState.Disconnected;
|
||||
});
|
||||
_dispatcher.Post(() => { ConnectionState = ConnectionState.Disconnected; });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes all selected tree nodes and switches to the Subscriptions tab.
|
||||
/// Subscribes all selected tree nodes and switches to the Subscriptions tab.
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private async Task SubscribeSelectedNodesAsync()
|
||||
@@ -233,17 +218,14 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
if (SelectedTreeNodes.Count == 0 || !IsConnected) return;
|
||||
|
||||
var nodes = SelectedTreeNodes.ToList();
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
await Subscriptions.AddSubscriptionForNodeAsync(node.NodeId);
|
||||
}
|
||||
foreach (var node in nodes) await Subscriptions.AddSubscriptionForNodeAsync(node.NodeId);
|
||||
|
||||
SubscriptionCount = Subscriptions.SubscriptionCount;
|
||||
SelectedTabIndex = 1; // Subscriptions tab
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the history tab's selected node and switches to the History tab.
|
||||
/// Sets the history tab's selected node and switches to the History tab.
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
private void ViewHistoryForSelectedNode()
|
||||
@@ -256,14 +238,14 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates whether "View History" should be enabled based on the selected node's type.
|
||||
/// Only Variable nodes can have history.
|
||||
/// Updates whether "View History" should be enabled based on the selected node's type.
|
||||
/// Only Variable nodes can have history.
|
||||
/// </summary>
|
||||
public void UpdateHistoryEnabledForSelection()
|
||||
{
|
||||
IsHistoryEnabledForSelection = IsConnected
|
||||
&& SelectedTreeNodes.Count > 0
|
||||
&& SelectedTreeNodes[0].NodeClass == "Variable";
|
||||
&& SelectedTreeNodes.Count > 0
|
||||
&& SelectedTreeNodes[0].NodeClass == "Variable";
|
||||
}
|
||||
|
||||
private static string[]? ParseFailoverUrls(string? csv)
|
||||
@@ -272,7 +254,7 @@ public partial class MainWindowViewModel : ObservableObject
|
||||
return null;
|
||||
|
||||
return csv.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Where(u => !string.IsNullOrEmpty(u))
|
||||
.ToArray();
|
||||
.Where(u => !string.IsNullOrEmpty(u))
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,42 +7,34 @@ using ZB.MOM.WW.LmxOpcUa.Client.UI.Services;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel for the read/write panel.
|
||||
/// ViewModel for the read/write panel.
|
||||
/// </summary>
|
||||
public partial class ReadWriteViewModel : ObservableObject
|
||||
{
|
||||
private readonly IOpcUaClientService _service;
|
||||
private readonly IUiDispatcher _dispatcher;
|
||||
private readonly IOpcUaClientService _service;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(ReadCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(WriteCommand))]
|
||||
private string? _selectedNodeId;
|
||||
[ObservableProperty] private string? _currentStatus;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _currentValue;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _currentStatus;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _sourceTimestamp;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _serverTimestamp;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _writeValue;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _writeStatus;
|
||||
[ObservableProperty] private string? _currentValue;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(ReadCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(WriteCommand))]
|
||||
private bool _isConnected;
|
||||
|
||||
public bool IsNodeSelected => !string.IsNullOrEmpty(SelectedNodeId);
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(ReadCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(WriteCommand))]
|
||||
private string? _selectedNodeId;
|
||||
|
||||
[ObservableProperty] private string? _serverTimestamp;
|
||||
|
||||
[ObservableProperty] private string? _sourceTimestamp;
|
||||
|
||||
[ObservableProperty] private string? _writeStatus;
|
||||
|
||||
[ObservableProperty] private string? _writeValue;
|
||||
|
||||
public ReadWriteViewModel(IOpcUaClientService service, IUiDispatcher dispatcher)
|
||||
{
|
||||
@@ -50,16 +42,18 @@ public partial class ReadWriteViewModel : ObservableObject
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public bool IsNodeSelected => !string.IsNullOrEmpty(SelectedNodeId);
|
||||
|
||||
partial void OnSelectedNodeIdChanged(string? value)
|
||||
{
|
||||
OnPropertyChanged(nameof(IsNodeSelected));
|
||||
if (!string.IsNullOrEmpty(value) && IsConnected)
|
||||
{
|
||||
_ = ExecuteReadAsync();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(value) && IsConnected) _ = ExecuteReadAsync();
|
||||
}
|
||||
|
||||
private bool CanReadOrWrite() => IsConnected && !string.IsNullOrEmpty(SelectedNodeId);
|
||||
private bool CanReadOrWrite()
|
||||
{
|
||||
return IsConnected && !string.IsNullOrEmpty(SelectedNodeId);
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanReadOrWrite))]
|
||||
private async Task ReadAsync()
|
||||
@@ -106,22 +100,16 @@ public partial class ReadWriteViewModel : ObservableObject
|
||||
var nodeId = NodeId.Parse(SelectedNodeId);
|
||||
var statusCode = await _service.WriteValueAsync(nodeId, WriteValue);
|
||||
|
||||
_dispatcher.Post(() =>
|
||||
{
|
||||
WriteStatus = statusCode.ToString();
|
||||
});
|
||||
_dispatcher.Post(() => { WriteStatus = statusCode.ToString(); });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dispatcher.Post(() =>
|
||||
{
|
||||
WriteStatus = $"Error: {ex.Message}";
|
||||
});
|
||||
_dispatcher.Post(() => { WriteStatus = $"Error: {ex.Message}"; });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all displayed values.
|
||||
/// Clears all displayed values.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
@@ -133,4 +121,4 @@ public partial class ReadWriteViewModel : ObservableObject
|
||||
WriteValue = null;
|
||||
WriteStatus = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,28 +3,25 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a single active subscription row.
|
||||
/// Represents a single active subscription row.
|
||||
/// </summary>
|
||||
public partial class SubscriptionItemViewModel : ObservableObject
|
||||
{
|
||||
/// <summary>The monitored NodeId.</summary>
|
||||
public string NodeId { get; }
|
||||
[ObservableProperty] private string? _status;
|
||||
|
||||
/// <summary>The subscription interval in milliseconds.</summary>
|
||||
public int IntervalMs { get; }
|
||||
[ObservableProperty] private string? _timestamp;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _value;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _status;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _timestamp;
|
||||
[ObservableProperty] private string? _value;
|
||||
|
||||
public SubscriptionItemViewModel(string nodeId, int intervalMs)
|
||||
{
|
||||
NodeId = nodeId;
|
||||
IntervalMs = intervalMs;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The monitored NodeId.</summary>
|
||||
public string NodeId { get; }
|
||||
|
||||
/// <summary>The subscription interval in milliseconds.</summary>
|
||||
public int IntervalMs { get; }
|
||||
}
|
||||
@@ -9,35 +9,28 @@ using ZB.MOM.WW.LmxOpcUa.Client.UI.Services;
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel for the subscriptions panel.
|
||||
/// ViewModel for the subscriptions panel.
|
||||
/// </summary>
|
||||
public partial class SubscriptionsViewModel : ObservableObject
|
||||
{
|
||||
private readonly IOpcUaClientService _service;
|
||||
private readonly IUiDispatcher _dispatcher;
|
||||
|
||||
/// <summary>Currently active subscriptions.</summary>
|
||||
public ObservableCollection<SubscriptionItemViewModel> ActiveSubscriptions { get; } = new();
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(AddSubscriptionCommand))]
|
||||
private string? _newNodeIdText;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _newInterval = 1000;
|
||||
private readonly IOpcUaClientService _service;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(AddSubscriptionCommand))]
|
||||
[NotifyCanExecuteChangedFor(nameof(RemoveSubscriptionCommand))]
|
||||
private bool _isConnected;
|
||||
|
||||
[ObservableProperty]
|
||||
private int _subscriptionCount;
|
||||
[ObservableProperty] private int _newInterval = 1000;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyCanExecuteChangedFor(nameof(RemoveSubscriptionCommand))]
|
||||
[ObservableProperty] [NotifyCanExecuteChangedFor(nameof(AddSubscriptionCommand))]
|
||||
private string? _newNodeIdText;
|
||||
|
||||
[ObservableProperty] [NotifyCanExecuteChangedFor(nameof(RemoveSubscriptionCommand))]
|
||||
private SubscriptionItemViewModel? _selectedSubscription;
|
||||
|
||||
[ObservableProperty] private int _subscriptionCount;
|
||||
|
||||
public SubscriptionsViewModel(IOpcUaClientService service, IUiDispatcher dispatcher)
|
||||
{
|
||||
_service = service;
|
||||
@@ -45,23 +38,27 @@ public partial class SubscriptionsViewModel : ObservableObject
|
||||
_service.DataChanged += OnDataChanged;
|
||||
}
|
||||
|
||||
/// <summary>Currently active subscriptions.</summary>
|
||||
public ObservableCollection<SubscriptionItemViewModel> ActiveSubscriptions { get; } = [];
|
||||
|
||||
private void OnDataChanged(object? sender, DataChangedEventArgs e)
|
||||
{
|
||||
_dispatcher.Post(() =>
|
||||
{
|
||||
foreach (var item in ActiveSubscriptions)
|
||||
{
|
||||
if (item.NodeId == e.NodeId)
|
||||
{
|
||||
item.Value = e.Value.Value?.ToString() ?? "(null)";
|
||||
item.Status = e.Value.StatusCode.ToString();
|
||||
item.Timestamp = e.Value.SourceTimestamp.ToString("O");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private bool CanAddSubscription() => IsConnected && !string.IsNullOrWhiteSpace(NewNodeIdText);
|
||||
private bool CanAddSubscription()
|
||||
{
|
||||
return IsConnected && !string.IsNullOrWhiteSpace(NewNodeIdText);
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanAddSubscription))]
|
||||
private async Task AddSubscriptionAsync()
|
||||
@@ -88,7 +85,10 @@ public partial class SubscriptionsViewModel : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanRemoveSubscription() => IsConnected && SelectedSubscription != null;
|
||||
private bool CanRemoveSubscription()
|
||||
{
|
||||
return IsConnected && SelectedSubscription != null;
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanRemoveSubscription))]
|
||||
private async Task RemoveSubscriptionAsync()
|
||||
@@ -115,7 +115,7 @@ public partial class SubscriptionsViewModel : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribes to a node by ID (used by context menu). Skips if already subscribed.
|
||||
/// Subscribes to a node by ID (used by context menu). Skips if already subscribed.
|
||||
/// </summary>
|
||||
public async Task AddSubscriptionForNodeAsync(string nodeIdStr, int intervalMs = 1000)
|
||||
{
|
||||
@@ -142,7 +142,7 @@ public partial class SubscriptionsViewModel : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all subscriptions and resets state.
|
||||
/// Clears all subscriptions and resets state.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
@@ -151,10 +151,10 @@ public partial class SubscriptionsViewModel : ObservableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unhooks event handlers from the service.
|
||||
/// Unhooks event handlers from the service.
|
||||
/// </summary>
|
||||
public void Teardown()
|
||||
{
|
||||
_service.DataChanged -= OnDataChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,27 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Opc.Ua;
|
||||
using ZB.MOM.WW.LmxOpcUa.Client.Shared;
|
||||
using ZB.MOM.WW.LmxOpcUa.Client.UI.Services;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Client.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a single node in the OPC UA browse tree with lazy-load support.
|
||||
/// Represents a single node in the OPC UA browse tree with lazy-load support.
|
||||
/// </summary>
|
||||
public partial class TreeNodeViewModel : ObservableObject
|
||||
{
|
||||
private static readonly TreeNodeViewModel PlaceholderSentinel = new();
|
||||
private readonly IUiDispatcher? _dispatcher;
|
||||
|
||||
private readonly IOpcUaClientService? _service;
|
||||
private readonly IUiDispatcher? _dispatcher;
|
||||
private bool _hasLoadedChildren;
|
||||
|
||||
/// <summary>The string NodeId of this node.</summary>
|
||||
public string NodeId { get; }
|
||||
[ObservableProperty] private bool _isExpanded;
|
||||
|
||||
/// <summary>The display name shown in the tree.</summary>
|
||||
public string DisplayName { get; }
|
||||
|
||||
/// <summary>The OPC UA node class (Object, Variable, etc.).</summary>
|
||||
public string NodeClass { get; }
|
||||
|
||||
/// <summary>Whether this node has child references.</summary>
|
||||
public bool HasChildren { get; }
|
||||
|
||||
/// <summary>Child nodes (may contain a placeholder sentinel before first expand).</summary>
|
||||
public ObservableCollection<TreeNodeViewModel> Children { get; } = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isExpanded;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLoading;
|
||||
[ObservableProperty] private bool _isLoading;
|
||||
|
||||
/// <summary>
|
||||
/// Private constructor for the placeholder sentinel only.
|
||||
/// Private constructor for the placeholder sentinel only.
|
||||
/// </summary>
|
||||
private TreeNodeViewModel()
|
||||
{
|
||||
@@ -64,18 +46,32 @@ public partial class TreeNodeViewModel : ObservableObject
|
||||
_service = service;
|
||||
_dispatcher = dispatcher;
|
||||
|
||||
if (hasChildren)
|
||||
{
|
||||
Children.Add(PlaceholderSentinel);
|
||||
}
|
||||
if (hasChildren) Children.Add(PlaceholderSentinel);
|
||||
}
|
||||
|
||||
/// <summary>The string NodeId of this node.</summary>
|
||||
public string NodeId { get; }
|
||||
|
||||
/// <summary>The display name shown in the tree.</summary>
|
||||
public string DisplayName { get; }
|
||||
|
||||
/// <summary>The OPC UA node class (Object, Variable, etc.).</summary>
|
||||
public string NodeClass { get; }
|
||||
|
||||
/// <summary>Whether this node has child references.</summary>
|
||||
public bool HasChildren { get; }
|
||||
|
||||
/// <summary>Child nodes (may contain a placeholder sentinel before first expand).</summary>
|
||||
public ObservableCollection<TreeNodeViewModel> Children { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether this node instance is the placeholder sentinel.
|
||||
/// </summary>
|
||||
internal bool IsPlaceholder => ReferenceEquals(this, PlaceholderSentinel);
|
||||
|
||||
partial void OnIsExpandedChanged(bool value)
|
||||
{
|
||||
if (value && !_hasLoadedChildren && HasChildren)
|
||||
{
|
||||
_ = LoadChildrenAsync();
|
||||
}
|
||||
if (value && !_hasLoadedChildren && HasChildren) _ = LoadChildrenAsync();
|
||||
}
|
||||
|
||||
private async Task LoadChildrenAsync()
|
||||
@@ -94,7 +90,6 @@ public partial class TreeNodeViewModel : ObservableObject
|
||||
{
|
||||
Children.Clear();
|
||||
foreach (var result in results)
|
||||
{
|
||||
Children.Add(new TreeNodeViewModel(
|
||||
result.NodeId,
|
||||
result.DisplayName,
|
||||
@@ -102,7 +97,6 @@ public partial class TreeNodeViewModel : ObservableObject
|
||||
result.HasChildren,
|
||||
_service,
|
||||
_dispatcher));
|
||||
}
|
||||
});
|
||||
}
|
||||
catch
|
||||
@@ -114,9 +108,4 @@ public partial class TreeNodeViewModel : ObservableObject
|
||||
_dispatcher.Post(() => IsLoading = false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether this node instance is the placeholder sentinel.
|
||||
/// </summary>
|
||||
internal bool IsPlaceholder => ReferenceEquals(this, PlaceholderSentinel);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user