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:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user