diff --git a/ADP/App.xaml.cs b/ADP/App.xaml.cs index f5a0595..06f0652 100644 --- a/ADP/App.xaml.cs +++ b/ADP/App.xaml.cs @@ -17,6 +17,9 @@ using UIShare.PubEvent; using static System.Runtime.InteropServices.JavaScript.JSType; using UIShare.GlobalVariable; using UIShare; +using System; +using DeviceCommand.Device; +using DeviceCommand.Base; namespace ADP { @@ -76,6 +79,7 @@ namespace ADP containerRegistry.RegisterScoped(); containerRegistry.RegisterScoped(); containerRegistry.RegisterScoped(); + containerRegistry.RegisterScoped(); containerRegistry.RegisterSingleton(); } //指定模块加载方式(需要手动将模块生成的dll放入Modules文件夹中) diff --git a/MainModule/MainModule.cs b/MainModule/MainModule.cs index 39a030c..747c814 100644 --- a/MainModule/MainModule.cs +++ b/MainModule/MainModule.cs @@ -1,3 +1,5 @@ +using DeviceCommand.Base; +using DeviceCommand.Device; using MainModule.Views; using System.Reflection; using UIShare.GlobalVariable; @@ -18,11 +20,6 @@ namespace MainModule containerRegistry.RegisterForNavigation("MainView"); containerRegistry.RegisterForNavigation("AutomatedTestingView"); containerRegistry.RegisterForNavigation("ProtocolStartView"); - // Scoped: one ScopedContext per container scope. - // AutomatedTestingViewModel creates its own scope (IContainerExtension.CreateScope) - // and resolves the 5 child VMs from it, so all siblings inside one parent share - // the same ScopedContext, while different parents get isolated instances. - } } } diff --git a/MainModule/ViewModels/AutomatedTestingViewModel.cs b/MainModule/ViewModels/AutomatedTestingViewModel.cs index cc9b20c..ae7343c 100644 --- a/MainModule/ViewModels/AutomatedTestingViewModel.cs +++ b/MainModule/ViewModels/AutomatedTestingViewModel.cs @@ -9,6 +9,7 @@ using UIShare.GlobalVariable; using UIShare.PubEvent; using UIShare.UIViewModel; using UIShare.ViewModelBase; +using static System.Formats.Asn1.AsnWriter; namespace MainModule.ViewModels { @@ -33,6 +34,7 @@ namespace MainModule.ViewModels public StepRunning _stepRunning { get; } public GlobalInfo _globalInfo { get; } public SystemConfig _systemConfig { get; set; } + public DeviceManager _deviceManager { get; set; } // 5 个子 ViewModel 全部从同一个 scope 解析,自动注入同一个 ScopedContext public CommandTreeViewModel CommandTreeVM { get; } @@ -45,15 +47,15 @@ namespace MainModule.ViewModels public ICommand RefreshCommand { get; set; } public ICommand BackToProtocolCommand { get; set; } - public AutomatedTestingViewModel(IContainerExtension container) : base(container) + public AutomatedTestingViewModel(IContainerProvider container) : base(container) { // 每个 AutomatedTestingViewModel 实例创建独立的容器作用域 _scope = container.CreateScope(); - _globalInfo=container.Resolve(); + _globalInfo =container.Resolve(); // 在该作用域内解析 ScopedContext —— 当前作用域唯一 _scopedContext = _scope.Resolve(); _stepRunning = _scope.Resolve(); - _systemConfig = _scope.Resolve(); + _systemConfig = _scope.Resolve();; // 关键:从同一个 _scope 解析 5 个子 VM,DI 会把同一个 ScopedContext 注入它们 CommandTreeVM = _scope.Resolve(); StepsManagerVM = _scope.Resolve(); @@ -62,6 +64,7 @@ namespace MainModule.ViewModels ParametersManagerVM = _scope.Resolve(); RefreshCommand = new DelegateCommand(OnRefresh); BackToProtocolCommand = new DelegateCommand(OnBackToProtocol); + } public void Dispose() @@ -144,6 +147,7 @@ namespace MainModule.ViewModels _scopedContext.Program.StepCollection = program.StepCollection; _scopedContext.Program.ErrorStepCollection = program.ErrorStepCollection; _scopedContext.CurrentFilePath = filePath; + _deviceManager = _scope.Resolve(); } } diff --git a/SettingModule/ViewModels/SettingViewModel.cs b/SettingModule/ViewModels/SettingViewModel.cs index bda3ac7..55f0aa9 100644 --- a/SettingModule/ViewModels/SettingViewModel.cs +++ b/SettingModule/ViewModels/SettingViewModel.cs @@ -61,7 +61,6 @@ namespace SettingModule.ViewModels #region 命令 public ICommand RefreshCommand { get; } public ICommand SaveCommand { get; } - public ICommand ResetCommand { get; } public ICommand OpenConnectionConfigCommand { get; } #endregion #region 私有字段 @@ -80,7 +79,6 @@ namespace SettingModule.ViewModels _globalInfo = container.Resolve(); RefreshCommand = new DelegateCommand(OnExpand); SaveCommand = new DelegateCommand(OnSave); - ResetCommand = new DelegateCommand(OnReset); OpenConnectionConfigCommand = new DelegateCommand(OnOpenConnectionConfig); } @@ -132,15 +130,7 @@ namespace SettingModule.ViewModels } /// 重置当前选中设备的配置(占位)。 - private void OnReset() - { - if (SelectedDevice == null) - { - StatusMessage = "无可重置的设备"; - return; - } - StatusMessage = $"已重置设备 [{SelectedDevice.DeviceName}] 的配置"; - } + /// /// 打开"连接配置"对话框。按 SelectedDevice.ConnectionType 决定开 TCP 还是串口对话框。 diff --git a/SettingModule/Views/SettingView.xaml b/SettingModule/Views/SettingView.xaml index ba9baf1..a0e3c18 100644 --- a/SettingModule/Views/SettingView.xaml +++ b/SettingModule/Views/SettingView.xaml @@ -205,7 +205,7 @@ -