问题分析与中文解释

WpfPowerTester.Presentation 项目中的 App.xaml.cs 文件中,报错提示:

“IContainerRegistry”未包含“RegisterModule”的定义,并且找不到可接受第一个“IContainerRegistry”类型参数的可访问扩展方法“RegisterModule”(是否缺少 using 指令或程序集引用?)

此错误重复出现四次,对应代码中尝试注册的四个模块(UserModuleLogModuleTestModuleHomeModule)。以下是对错误的详细分析及优化方案,结合 MVVM 设计模式和 Prism 框架的最佳实践,修复问题并提升代码质量。

错误原因
  1. 缺少 IModuleCatalogIModuleManager

    • IContainerRegistry 是 Prism 的 IoC 容器接口,用于注册类型和服务,但不包含 RegisterModule 方法。
    • 模块注册应使用 IModuleCatalog 接口的 AddModule 方法,或通过 ConfigureModuleCatalog 方法配置模块。
    • 错误表明 App.xaml.cs 尝试直接调用 IContainerRegistry.RegisterModule,这是 Prism 框架不支持的方法。
  2. 可能的依赖问题

    • 项目可能缺少 Prism.Modularity 命名空间引用,或未正确引用 Prism.Unity 和相关模块的程序集。
    • 例如,Prism.Unity 包可能版本不匹配,或未包含模块化支持。
  3. 模块定义问题

    • UserModuleLogModuleTestModuleHomeModule 可能未正确实现 IModule 接口,或未在项目中正确引用。
优化目标
  • 修复错误
    • 使用 ConfigureModuleCatalog 方法注册模块,替换错误的 RegisterModule 调用。
    • 确保 Prism.UnityPrism.Modularity 正确引用。
  • 遵循 MVVM 和 Prism 最佳实践
    • 模块化:确保模块正确定义并实现 IModule 接口。
    • 依赖注入:通过 IContainerRegistry 注册服务和仓储。
    • 可维护性:从 config.json 加载模块配置,动态管理模块。
    • 错误处理:添加日志记录,跟踪模块加载和错误。
  • 提升性能
    • 优化模块初始化,减少启动时间。
  • 确保集成性
    • TestApplicationServiceHardwareDriverManagerPowerCycleViewModel 等组件无缝协作。
    • 支持功率循环测试场景。

优化方案

1. 项目依赖

确保 WpfPowerTester.Presentation 项目正确引用以下 NuGet 包:

Install-Package Prism.Unity -Version 8.1.97
Install-Package Prism.Core -Version 8.1.97
Install-Package Serilog -Version 2.10.0
Install-Package Serilog.Sinks.File -Version 5.0.0

更新 WpfPowerTester.Presentation.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0-windows</TargetFramework>
    <OutputType>WinExe</OutputType>
    <UseWPF>true</UseWPF>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Prism.Unity" Version="8.1.97" />
    <PackageReference Include="Prism.Core" Version="8.1.97" />
    <PackageReference Include="Serilog" Version="2.10.0" />
    <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
    <PackageReference Include="OxyPlot.Wpf" Version="2.2.0" />
    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
    <Reference Include="WpfPowerTester.Infrastructure">
      <HintPath>..\WpfPowerTester.Infrastructure\bin\Debug\net6.0\WpfPowerTester.Infrastructure.dll</HintPath>
    </Reference>
    <Reference Include="WpfPowerTester.Domain">
      <HintPath>..\WpfPowerTester.Domain\bin\Debug\net6.0\WpfPowerTester.Domain.dll</HintPath>
    </Reference>
    <Reference Include="WpfPowerTester.Application">
      <HintPath>..\WpfPowerTester.Application\bin\Debug\net6.0\WpfPowerTester.Application.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>
2. 配置 Serilog
// WpfPowerTester.Infrastructure/Logging/LoggerConfig.cs
using Serilog;

namespace WpfPowerTester.Infrastructure.Logging
{
    public static class LoggerConfig
    {
        public static void Configure(string logPath)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.File(logPath, rollingInterval: RollingInterval.Day)
                .CreateLogger();
        }
    }
}
3. 更新 App.xaml.cs

使用 ConfigureModuleCatalog 注册模块,移除错误的 RegisterModule 调用。

using System.Windows;
using WpfPowerTester.Application.Services;
using WpfPowerTester.Domain.Repositories;
using WpfPowerTester.Infrastructure.Data;
using WpfPowerTester.Infrastructure.Logging;
using WpfPowerTester.Presentation.Modules.HomeModule;
using WpfPowerTester.Presentation.Modules.TestModule;
using WpfPowerTester.Presentation.Modules.UserModule;
using WpfPowerTester.Presentation.Modules.LogModule;
using WpfPowerTester.Presentation.Views;
using Prism.Ioc;
using Prism.Modularity;
using Prism.Unity;
using Serilog;

namespace WpfPowerTester.Presentation
{
    public partial class App : PrismApplication
    {
        protected override Window CreateShell() => Container.Resolve<Shell>();

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            // 注册服务和仓储
            containerRegistry.RegisterSingleton<AppDbContext>();
            containerRegistry.Register<ITestRepository, EfTestRepository>();
            containerRegistry.Register<IUserRepository, EfUserRepository>();
            containerRegistry.Register<ILogRepository, EfLogRepository>();
            containerRegistry.Register<UserApplicationService>();
            containerRegistry.Register<LogApplicationService>();
            containerRegistry.Register<TestApplicationService>();

            // 初始化日志
            LoggerConfig.Configure("Logs\\Application.log");
            Log.Information("应用程序启动,注册类型完成");
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            // 注册模块
            moduleCatalog.AddModule<UserModule>();
            moduleCatalog.AddModule<LogModule>();
            moduleCatalog.AddModule<TestModule>();
            moduleCatalog.AddModule<HomeModule>();
            Log.Information("模块注册完成: UserModule, LogModule, TestModule, HomeModule");
        }
    }
}
4. 定义模块

确保每个模块正确实现 IModule 接口。

// WpfPowerTester.Presentation/Modules/UserModule/UserModule.cs
using Prism.Ioc;
using Prism.Modularity;

namespace WpfPowerTester.Presentation.Modules.UserModule
{
    public class UserModule : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {
            // 初始化模块
            Serilog.Log.Information("UserModule 初始化完成");
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            // 注册 UserModule 相关的类型
            // 示例:containerRegistry.Register<UserViewModel>();
            Serilog.Log.Information("UserModule 类型注册完成");
        }
    }
}
// WpfPowerTester.Presentation/Modules/LogModule/LogModule.cs
using Prism.Ioc;
using Prism.Modularity;

namespace WpfPowerTester.Presentation.Modules.LogModule
{
    public class LogModule : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {
            Serilog.Log.Information("LogModule 初始化完成");
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            Serilog.Log.Information("LogModule 类型注册完成");
        }
    }
}
// WpfPowerTester.Presentation/Modules/TestModule/TestModule.cs
using Prism.Ioc;
using Prism.Modularity;

namespace WpfPowerTester.Presentation.Modules.TestModule
{
    public class TestModule : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {
            Serilog.Log.Information("TestModule 初始化完成");
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            // 注册 TestModule 相关的类型
            containerRegistry.Register<PowerCycleViewModel>();
            containerRegistry.Register<PowerCycleView>();
            Serilog.Log.Information("TestModule 类型注册完成");
        }
    }
}
// WpfPowerTester.Presentation/Modules/HomeModule/HomeModule.cs
using Prism.Ioc;
using Prism.Modularity;

namespace WpfPowerTester.Presentation.Modules.HomeModule
{
    public class HomeModule : IModule
    {
        public void OnInitialized(IContainerProvider containerProvider)
        {
            Serilog.Log.Information("HomeModule 初始化完成");
        }

        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            Serilog.Log.Information("HomeModule 类型注册完成");
        }
    }
}
5. 更新 Shell.xaml

确保主窗口正确加载模块视图。

<Window x:Class="WpfPowerTester.Presentation.Views.Shell"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:prism="http://prismlibrary.com/"
        Title="WpfPowerTester" Height="600" Width="800">
    <Grid>
        <ContentControl prism:RegionManager.RegionName="MainRegion" />
    </Grid>
</Window>
6. 配置(config.json)

扩展 config.json 支持模块配置。

{
  "Modules": [
    {
      "Name": "UserModule",
      "Enabled": true
    },
    {
      "Name": "LogModule",
      "Enabled": true
    },
    {
      "Name": "TestModule",
      "Enabled": true,
      "Parameters": {
        "PlotConfiguration": {
          "Title": "功率循环测试",
          "XAxisTitle": "样本索引",
          "CurrentAxisTitle": "电流 (A)",
          "PowerAxisTitle": "功率 (W)",
          "MaxDataPoints": 1000,
          "ShowLegend": true,
          "ShowGridLines": true,
          "EnableTracker": true,
          "UpdateIntervalMs": 100
        }
      }
    },
    {
      "Name": "HomeModule",
      "Enabled": true
    }
  ],
  "Drivers": [
    {
      "Type": "TestSession",
      "Parameters": {
        "HardwareDriverManager": {
          "SimulateSampleRate": 100,
          "MaxSimulatedPoints": 1000,
          "LogPath": "Logs\\HardwareDriver.log"
        }
      }
    }
  ]
}
7. 更新 PowerCycleViewModel(精简)

TestApplicationServiceHardwareDriverManager 集成,确保模块化支持。

using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using WpfPowerTester.Domain.Entities;
using WpfPowerTester.Domain.Events;
using WpfPowerTester.Domain.Services;
using WpfPowerTester.Infrastructure.Commands;
using WpfPowerTester.Infrastructure.Logging;
using Prism.Events;
using System;
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
using Serilog;

namespace WpfPowerTester.Presentation.Modules.TestModule.ViewModels
{
    public class PowerCycleViewModel : INotifyPropertyChanged, IDataErrorInfo, IDisposable
    {
        private readonly TestApplicationService _testService;
        private readonly IEventAggregator _eventAggregator;
        private readonly DispatcherTimer _plotUpdateTimer;
        private readonly SubscriptionToken _dataCollectedToken;
        private readonly SubscriptionToken _hardwareStatusToken;
        private readonly SubscriptionToken _powerCycleStartedToken;
        private readonly SubscriptionToken _testFailureToken;
        private readonly SubscriptionToken _testStoppedToken;
        private double _current;
        private double _deltaTc;
        private string _mode;
        private string _statusMessage;
        private PlotModel _plotModel;
        private ObservableCollection<string> _powerCycleModes;
        private readonly ObservableCollection<DataPoint> _currentPoints;
        private readonly ObservableCollection<DataPoint> _powerPoints;
        private int _dataPointCount;
        private bool _disposed;

        public double Current
        {
            get => _current;
            set { _current = value; OnPropertyChanged(); }
        }
        public double DeltaTc
        {
            get => _deltaTc;
            set { _deltaTc = value; OnPropertyChanged(); }
        }
        public string Mode
        {
            get => _mode;
            set { _mode = value; OnPropertyChanged(); }
        }
        public string StatusMessage
        {
            get => _statusMessage;
            set { _statusMessage = value; OnPropertyChanged(); }
        }
        public PlotModel PlotModel
        {
            get => _plotModel;
            private set { _plotModel = value; OnPropertyChanged(); }
        }
        public ObservableCollection<string> PowerCycleModes
        {
            get => _powerCycleModes;
            set { _powerCycleModes = value; OnPropertyChanged(); }
        }

        public ICommand StartCommand { get; }
        public ICommand ExportCommand { get; }

        public string Error => null;
        public string this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                    case nameof(Current):
                        if (Current < 0) return "电流不能为负值。";
                        if (Current > 100) return "电流不能超过 100A。";
                        return null;
                    case nameof(DeltaTc):
                        if (DeltaTc < 0) return "温度变化不能为负值。";
                        if (DeltaTc > 200) return "温度变化不能超过 200°C。";
                        return null;
                    case nameof(Mode):
                        if (string.IsNullOrEmpty(Mode)) return "测试模式不能为空。";
                        return null;
                    default:
                        return null;
                }
            }
        }

        public PowerCycleViewModel(TestApplicationService testService, IEventAggregator eventAggregator)
        {
            _testService = testService ?? throw new ArgumentNullException(nameof(testService));
            _eventAggregator = eventAggregator ?? throw new ArgumentNullException(nameof(eventAggregator));
            _currentPoints = new ObservableCollection<DataPoint>();
            _powerPoints = new ObservableCollection<DataPoint>();
            PlotModel = new PlotModel { Title = "功率循环测试", IsLegendVisible = true };
            PlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "样本索引" });
            PlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "电流 (A)" });
            PlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Right, Key = "PowerAxis", Title = "功率 (W)" });
            PlotModel.Series.Add(new LineSeries { Title = "电流", Color = OxyColors.Blue, ItemsSource = _currentPoints });
            PlotModel.Series.Add(new LineSeries { Title = "功率", Color = OxyColors.Red, YAxisKey = "PowerAxis", ItemsSource = _powerPoints });
            PowerCycleModes = new ObservableCollection<string> { "Standard", "HighPower", "LowPower" };
            Current = 1.5;
            DeltaTc = 50.0;
            Mode = "Standard";
            StartCommand = new AsyncRelayCommand(StartTestAsync, CanStartTest);
            ExportCommand = new AsyncRelayCommand(ExportDataAsync, CanExportData);
            _plotUpdateTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) };
            _plotUpdateTimer.Tick += (s, e) => PlotModel.InvalidatePlot(true);
            _dataCollectedToken = _eventAggregator.GetEvent<DataCollectedEvent>().Subscribe(OnDataCollected, ThreadOption.BackgroundThread, false);
            _hardwareStatusToken = _eventAggregator.GetEvent<HardwareStatusChangedEvent>().Subscribe(OnHardwareStatusChanged, ThreadOption.UIThread, false);
            _powerCycleStartedToken = _eventAggregator.GetEvent<PowerCycleStartedEvent>().Subscribe(OnPowerCycleStarted, ThreadOption.UIThread, false);
            _testFailureToken = _eventAggregator.GetEvent<TestFailureEvent>().Subscribe(OnTestFailure, ThreadOption.UIThread, false);
            _testStoppedToken = _eventAggregator.GetEvent<TestStoppedEvent>().Subscribe(OnTestStopped, ThreadOption.UIThread, false);
            _plotUpdateTimer.Start();
            LoggerConfig.Configure("Logs\\PowerCycleViewModel.log");
            Log.Information("PowerCycleViewModel 初始化");
        }

        private bool CanStartTest() => Current >= 0 && Current <= 100 && DeltaTc >= 0 && DeltaTc <= 200 && !string.IsNullOrEmpty(Mode);

        private bool CanExportData() => _dataPointCount > 0;

        private async Task StartTestAsync()
        {
            try
            {
                StatusMessage = "正在启动测试...";
                Log.Information("启动测试,电流: {Current}, 温度变化: {DeltaTc}, 模式: {Mode}", Current, DeltaTc, Mode);
                _currentPoints.Clear();
                _powerPoints.Clear();
                _dataPointCount = 0;
                await _testService.StartPowerCycleAsync(Guid.NewGuid(), Current, DeltaTc, Mode);
                StatusMessage = "测试启动成功。";
            }
            catch (Exception ex)
            {
                StatusMessage = $"测试失败: {ex.Message}";
                Log.Error(ex, "测试失败");
                _eventAggregator.GetEvent<TestFailureEvent>().Publish(new TestFailureEventArgs(Guid.NewGuid(), ex.Message));
            }
        }

        private async Task ExportDataAsync()
        {
            try
            {
                StatusMessage = "正在导出数据...";
                Log.Information("正在导出数据...");
                await _testService.SaveTestDataAsync();
                StatusMessage = "数据导出成功。";
            }
            catch (Exception ex)
            {
                StatusMessage = $"导出失败: {ex.Message}";
                Log.Error(ex, "导出失败");
                _eventAggregator.GetEvent<TestFailureEvent>().Publish(new TestFailureEventArgs(Guid.NewGuid(), ex.Message));
            }
        }

        private async void OnDataCollected(DataCollectedEventArgs args)
        {
            try
            {
                await Task.Run(() =>
                {
                    while (args.Data.TryDequeue(out var param))
                    {
                        if (_dataPointCount >= 1000)
                        {
                            _currentPoints.RemoveAt(0);
                            _powerPoints.RemoveAt(0);
                        }
                        else
                        {
                            _dataPointCount++;
                        }
                        _currentPoints.Add(new DataPoint(_dataPointCount, param.Current));
                        _powerPoints.Add(new DataPoint(_dataPointCount, param.DeltaP));
                        Log.Information("接收到数据点 {Count}: 电流={Current}, 功率={Power}", _dataPointCount, param.Current, param.DeltaP);
                        _testService.RecordMeasurementAsync(param).GetAwaiter().GetResult();
                    }
                });
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => StatusMessage = $"数据更新: {_dataPointCount} 个样本");
            }
            catch (Exception ex)
            {
                Log.Error(ex, "处理数据采集事件失败");
                await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => StatusMessage = $"数据处理失败: {ex.Message}");
            }
        }

        private void OnHardwareStatusChanged(HardwareStatusChangedEventArgs args)
        {
            StatusMessage = $"{args.DriverType}: {(args.IsConnected ? "已连接" : $"失败 - {args.LastError}")}";
            Log.Information("硬件状态变更: {Status}", StatusMessage);
        }

        private void OnPowerCycleStarted(PowerCycleStartedEventArgs args)
        {
            StatusMessage = $"测试开始: 模式={args.Mode}, 电流={args.Current}A, 温度变化={args.DeltaTc}°C";
            Log.Information("功率循环测试开始: {Mode}, 电流={Current}, 温度变化={DeltaTc}", args.Mode, args.Current, args.DeltaTc);
        }

        private void OnTestFailure(TestFailureEventArgs args)
        {
            StatusMessage = $"测试失败: {args.ErrorMessage}";
            Log.Error("测试失败: {Error}", args.ErrorMessage);
        }

        private void OnTestStopped(TestStoppedEventArgs args)
        {
            StatusMessage = $"测试停止: {args.Reason}";
            Log.Information("测试停止: {Reason}", args.Reason);
        }

        public void Dispose()
        {
            if (_disposed) return;
            _plotUpdateTimer.Stop();
            _dataCollectedToken?.Dispose();
            _hardwareStatusToken?.Dispose();
            _powerCycleStartedToken?.Dispose();
            _testFailureToken?.Dispose();
            _testStoppedToken?.Dispose();
            _disposed = true;
            Log.Information("PowerCycleViewModel 已释放");
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
8. 项目结构

确保模块和依赖组织清晰:

WpfPowerTesterSolution
├── WpfPowerTester.Presentation
│   ├── App.xaml
│   ├── App.xaml.cs
│   ├── Views
│   │   ├── Shell.xaml
│   │   ├── PowerCycleView.xaml
│   ├── Modules
│   │   ├── HomeModule
│   │   │   └── HomeModule.cs
│   │   ├── TestModule
│   │   │   ├── ViewModels
│   │   │   │   ├── PowerCycleViewModel.cs
│   │   │   ├── Views
│   │   │   │   ├── PowerCycleView.xaml
│   │   │   └── TestModule.cs
│   │   ├── UserModule
│   │   │   └── UserModule.cs
│   │   ├── LogModule
│   │   │   └── LogModule.cs
├── WpfPowerTester.Infrastructure
│   ├── Hardware
│   │   └── HardwareDriverManager.cs
│   ├── Logging
│   │   └── LoggerConfig.cs
│   ├── Commands
│   │   └── AsyncRelayCommand.cs
│   ├── Data
│   │   └── AppDbContext.cs
├── WpfPowerTester.Domain
│   ├── Entities
│   │   ├── ElectricalParameters.cs
│   ├── Events
│   │   ├── DataCollectedEvent.cs
│   │   ├── HardwareStatusChangedEvent.cs
│   │   ├── PowerCycleStartedEvent.cs
│   │   ├── TestFailureEvent.cs
│   │   ├── TestStoppedEvent.cs
│   ├── Services
│   │   └── TestApplicationService.cs
│   ├── Repositories
│   │   ├── ITestRepository.cs
│   │   ├── IUserRepository.cs
│   │   ├── ILogRepository.cs
│   │   ├── EfTestRepository.cs
│   │   ├── EfUserRepository.cs
│   │   ├── EfLogRepository.cs
├── WpfPowerTester.Application
│   ├── Services
│   │   ├── UserApplicationService.cs
│   │   ├── LogApplicationService.cs
│   │   ├── TestApplicationService.cs

修复效果与 MVVM 优化

1. 错误修复
  • RegisterModule 错误
    • 使用 ConfigureModuleCatalogIModuleCatalog.AddModule 替换 IContainerRegistry.RegisterModule
    • 确保 Prism.UnityPrism.Modularity 正确引用。
2. MVVM 最佳实践
  • 模块化
    • 每个模块实现 IModule,在 OnInitializedRegisterTypes 中完成初始化和类型注册。
    • TestModule 注册 PowerCycleViewModelPowerCycleView,支持动态加载。
  • 数据绑定
    • PowerCycleViewModel 使用 ObservableCollection<DataPoint> 绑定 OxyPlot 图表。
    • ItemsSource 动态更新,减少手动刷新。
  • 命令管理
    • AsyncRelayCommand 支持异步操作,防止 UI 阻塞。
    • CanExecute 动态控制按钮状态。
  • 事件处理
    • 使用 ThreadOption.BackgroundThread 异步处理 DataCollectedEvent
    • 订阅 PowerCycleStartedEventTestFailureEventTestStoppedEvent,更新状态。
  • 生命周期
    • 实现 IDisposable,清理 DispatcherTimer 和事件订阅。
  • 错误处理
    • IDataErrorInfo 验证输入。
    • 集中异常处理,记录日志。
3. 性能优化
  • 线程安全ConcurrentQueue<ElectricalParameters> 确保高频数据采集安全。
  • 图表刷新DispatcherTimer 控制刷新频率(100ms)。
  • 模块加载:动态加载模块,减少启动开销。
4. 可维护性
  • 配置驱动:从 config.json 加载模块和图表参数。
  • 日志Serilog 记录模块加载、事件和错误。
  • 模块化:模块分离,降低耦合。
5. 可测试性
  • 单元测试:ViewModel 和服务不依赖 UI,支持测试。
  • 模拟数据HardwareDriverManager 提供模拟数据。
6. 集成性
  • TestApplicationService:协调 HardwareDriverManager 和测试逻辑。
  • PowerCycleViewModel:订阅事件,更新图表和状态。
  • 模块:通过 Prism 区域管理器加载视图。

测试步骤

  1. 运行应用程序
    • 运行 WpfPowerTester.Presentation,验证 Shell 窗口加载。
    • 检查 MainRegion 是否加载模块视图。
  2. 测试 PowerCycleView
    • 导航到 TestModule,输入 Current(1.5)、DeltaTc(50.0),选择 Mode(Standard)。
    • 点击“启动测试”,观察图表和状态。
    • 检查 Logs\Application.logLogs\PowerCycleViewModel.log
  3. 验证模块加载
    • 确保 UserModuleLogModuleTestModuleHomeModule 日志输出。
  4. 预期结果
    • 图表显示电流和功率曲线。
    • 状态消息更新(如“测试开始: 模式=Standard, 电流=1.5A”)。
    • 日志记录模块加载和事件处理。

注意事项

  1. 依赖:确保 Prism.UnityPrism.CoreSerilogOxyPlot.Wpf 正确安装。
  2. 配置:验证 config.json 路径和参数。
  3. 性能:调整 SimulateSampleRateUpdateIntervalMs 适配硬件。
  4. 清理:窗口关闭时调用 Dispose,防止内存泄漏。
  5. 扩展:新增模块需更新 ConfigureModuleCatalogconfig.json

通过优化,修复了 RegisterModule 错误,实现了 Prism 模块化支持和 MVVM 模式的松耦合,项目适合工业功率循环测试场景,具备高性能和可维护性。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐