添加OPCUA的后台服务

This commit is contained in:
2025-07-08 17:33:20 +08:00
parent 103c7bf32e
commit 07253aed65
9 changed files with 394 additions and 2 deletions

View File

@@ -16,13 +16,15 @@ public partial class SettingViewModel : ViewModelBase
private ConnectionSettings _connectionSettings;
private readonly S7BackgroundService _s7BackgroundService;
private readonly MqttBackgroundService _mqttBackgroundService;
private readonly OpcUaBackgroundService _opcUaBackgroundService;
public SettingViewModel(S7BackgroundService s7BackgroundService, MqttBackgroundService mqttBackgroundService)
public SettingViewModel(S7BackgroundService s7BackgroundService, MqttBackgroundService mqttBackgroundService, OpcUaBackgroundService opcUaBackgroundService)
{
_connectionSettings = ConnectionSettings.Load();
AvailableDbTypes = Enum.GetNames(typeof(SqlSugar.DbType)).ToList();
_s7BackgroundService = s7BackgroundService;
_mqttBackgroundService = mqttBackgroundService;
_opcUaBackgroundService = opcUaBackgroundService;
}
public List<string> AvailableDbTypes { get; set; }
@@ -155,6 +157,28 @@ public partial class SettingViewModel : ViewModelBase
}
}
public bool EnableOpcUaService
{
get => _connectionSettings.EnableOpcUaService;
set
{
if (_connectionSettings.EnableOpcUaService != value)
{
_connectionSettings.EnableOpcUaService = value;
OnPropertyChanged();
_connectionSettings.Save();
if (value)
{
_opcUaBackgroundService.StartService();
}
else
{
_opcUaBackgroundService.StopService();
}
}
}
}
[RelayCommand]
private async Task TestConnection()
{