From 2e07c0c446f03b2ef73779325a32a4c0b2dc30f3 Mon Sep 17 00:00:00 2001 From: hsc Date: Wed, 10 Jun 2026 15:04:11 +0800 Subject: [PATCH] =?UTF-8?q?automapper=E6=A1=86=E6=9E=B6=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ADP/ADP.csproj | 4 ++ ADP/App.xaml.cs | 27 +++++-- ADP/Profiles/AutoMapperProfile.cs | 64 +++++++++++++++++ ADP/ViewModels/ShellViewModel.cs | 10 +-- .../ViewModels/AutomatedTestingViewModel.cs | 4 +- Model/Models/CanMessageShow.cs | 24 +++++++ Model/Models/DeviceInfo.cs | 18 +++++ Model/Models/InstructionNode.cs | 16 +++++ Model/Models/Method.cs | 16 +++++ Model/Models/Parameter.cs | 45 ++++++++++++ Model/Models/Program.cs | 19 +++++ Model/Models/Step.cs | 45 ++++++++++++ Model/Models/SubProgramItem.cs | 12 ++++ .../Dialogs/SerialPortConfigViewModel.cs | 16 ++--- .../ViewModels/Dialogs/TCPConfigViewModel.cs | 16 ++--- SettingModule/ViewModels/SettingViewModel.cs | 8 +-- .../ViewModels/CommandTreeViewModel.cs | 60 ++++++++-------- .../Dialogs/ParameterSettingViewModel.cs | 12 ++-- .../ViewModels/ParametersManagerViewModel.cs | 14 ++-- .../ViewModels/SingleStepEditViewModel.cs | 8 +-- .../ViewModels/StepsManagerViewModel.cs | 20 +++--- TestingModule/Views/CommandTree.xaml | 2 +- TestingModule/Views/ParametersManager.xaml | 2 +- .../Converters/FilteredParametersConverter.cs | 2 +- .../ParameterCategoryToStringConverter.cs | 2 +- .../ParameterCategoryToVisibilityConverter.cs | 2 +- UIShare/GlobalVariable/ScopedContext.cs | 6 +- UIShare/GlobalVariable/StepRunning.cs | 18 ++--- UIShare/GlobalVariable/SystemConfig.cs | 16 ++--- ...essageShowModel.cs => CanMessageShowVM.cs} | 2 +- ...ustomPanelItem.cs => CustomPanelItemVM.cs} | 6 +- .../{DeviceInfoModel.cs => DeviceInfoVM.cs} | 10 +-- UIShare/UIViewModel/InstructionNode.cs | 18 ----- UIShare/UIViewModel/InstructionNodeVM.cs | 36 ++++++++++ .../{MethodModel.cs => MethodVM.cs} | 12 ++-- .../{ParameterModel.cs => ParameterVM.cs} | 18 ++--- UIShare/UIViewModel/ProgramModel.cs | 51 -------------- UIShare/UIViewModel/ProgramVM.cs | 51 ++++++++++++++ ...nectionConfig.cs => SerialPortConfigVM.cs} | 70 +++---------------- .../UIViewModel/{StepModel.cs => StepVM.cs} | 18 ++--- UIShare/UIViewModel/SubProgramItem.cs | 15 ---- UIShare/UIViewModel/SubProgramItemVM.cs | 28 ++++++++ UIShare/UIViewModel/TcpConfigVM.cs | 62 ++++++++++++++++ 43 files changed, 612 insertions(+), 293 deletions(-) create mode 100644 ADP/Profiles/AutoMapperProfile.cs create mode 100644 Model/Models/CanMessageShow.cs create mode 100644 Model/Models/DeviceInfo.cs create mode 100644 Model/Models/InstructionNode.cs create mode 100644 Model/Models/Method.cs create mode 100644 Model/Models/Parameter.cs create mode 100644 Model/Models/Program.cs create mode 100644 Model/Models/Step.cs create mode 100644 Model/Models/SubProgramItem.cs rename UIShare/UIViewModel/{CanMessageShowModel.cs => CanMessageShowVM.cs} (96%) rename UIShare/UIViewModel/{CustomPanelItem.cs => CustomPanelItemVM.cs} (86%) rename UIShare/UIViewModel/{DeviceInfoModel.cs => DeviceInfoVM.cs} (86%) delete mode 100644 UIShare/UIViewModel/InstructionNode.cs create mode 100644 UIShare/UIViewModel/InstructionNodeVM.cs rename UIShare/UIViewModel/{MethodModel.cs => MethodVM.cs} (62%) rename UIShare/UIViewModel/{ParameterModel.cs => ParameterVM.cs} (94%) delete mode 100644 UIShare/UIViewModel/ProgramModel.cs create mode 100644 UIShare/UIViewModel/ProgramVM.cs rename UIShare/UIViewModel/{ConnectionConfig.cs => SerialPortConfigVM.cs} (54%) rename UIShare/UIViewModel/{StepModel.cs => StepVM.cs} (90%) delete mode 100644 UIShare/UIViewModel/SubProgramItem.cs create mode 100644 UIShare/UIViewModel/SubProgramItemVM.cs create mode 100644 UIShare/UIViewModel/TcpConfigVM.cs diff --git a/ADP/ADP.csproj b/ADP/ADP.csproj index 876b4b7..6c43360 100644 --- a/ADP/ADP.csproj +++ b/ADP/ADP.csproj @@ -8,6 +8,10 @@ true + + + + diff --git a/ADP/App.xaml.cs b/ADP/App.xaml.cs index 06f0652..0e19940 100644 --- a/ADP/App.xaml.cs +++ b/ADP/App.xaml.cs @@ -20,6 +20,9 @@ using UIShare; using System; using DeviceCommand.Device; using DeviceCommand.Base; +using AutoMapper; +using Microsoft.Extensions.Logging.Abstractions; +using ADP.Profiles; namespace ADP { @@ -68,6 +71,22 @@ namespace ADP RegionManager.SetRegionManager(Application.Current.MainWindow, re); login.Show(); } + protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry) + { + base.RegisterRequiredTypes(containerRegistry); + //注册全局变量 + containerRegistry.RegisterScoped(); + containerRegistry.RegisterScoped(); + containerRegistry.RegisterScoped(); + containerRegistry.RegisterScoped(); + containerRegistry.RegisterSingleton(); + //注册AutoMapper + var config = new MapperConfiguration( + cfg => cfg.AddProfile(), + NullLoggerFactory.Instance + ); + containerRegistry.RegisterSingleton(() => config.CreateMapper()); + } protected override void RegisterTypes(IContainerRegistry containerRegistry) { //注册弹窗 @@ -75,12 +94,8 @@ namespace ADP // 注册通知管理器 INotificationManager NotificationManager = new NotificationManager(); containerRegistry.RegisterInstance(NotificationManager); - //注册全局变量 - containerRegistry.RegisterScoped(); - containerRegistry.RegisterScoped(); - containerRegistry.RegisterScoped(); - containerRegistry.RegisterScoped(); - containerRegistry.RegisterSingleton(); + // 注册仓储 + containerRegistry.RegisterScoped(typeof(SqlSugarRepository<>)); } //指定模块加载方式(需要手动将模块生成的dll放入Modules文件夹中) protected override IModuleCatalog CreateModuleCatalog() diff --git a/ADP/Profiles/AutoMapperProfile.cs b/ADP/Profiles/AutoMapperProfile.cs new file mode 100644 index 0000000..c197626 --- /dev/null +++ b/ADP/Profiles/AutoMapperProfile.cs @@ -0,0 +1,64 @@ +using AutoMapper; +using Model.Models; +using System; +using UIShare.UIViewModel; + +namespace ADP.Profiles +{ + /// + /// UIShare.UIViewModel ↔ Model.Models 双向映射配置。 + /// + public class AutoMapperProfile : Profile + { + public AutoMapperProfile() + { + // ===== Parameter ===== + // ParameterModel.Type(System.Type) ↔ Parameter.TypeName(string) + // ParameterModel.Category(enum) ↔ Parameter.Category(string) + CreateMap() + .ForMember(dest => dest.TypeName, + opt => opt.MapFrom(src => src.Type != null ? src.Type.AssemblyQualifiedName : null)) + .ForMember(dest => dest.Category, + opt => opt.MapFrom(src => src.Category.ToString())); + + CreateMap() + .ForMember(dest => dest.Type, + opt => opt.MapFrom(src => string.IsNullOrEmpty(src.TypeName) + ? typeof(string) + : (Type.GetType(src.TypeName) ?? typeof(string)))) + .ForMember(dest => dest.Category, + opt => opt.MapFrom(src => ParseCategory(src.Category))); + + // ===== Step ===== + CreateMap().ReverseMap(); + + // ===== Program ===== + CreateMap().ReverseMap(); + + // ===== Method ===== + CreateMap().ReverseMap(); + + // ===== DeviceInfo ===== + CreateMap().ReverseMap(); + + // ===== CanMessageShow ===== + CreateMap().ReverseMap(); + + + // ===== InstructionNode ===== + CreateMap().ReverseMap(); + + // ===== SubProgramItem ===== + CreateMap().ReverseMap(); + } + + private static ParameterVM.ParameterCategory ParseCategory(string? category) + { + if (string.IsNullOrEmpty(category)) + return ParameterVM.ParameterCategory.Temp; + return Enum.TryParse(category, true, out var result) + ? result + : ParameterVM.ParameterCategory.Temp; + } + } +} diff --git a/ADP/ViewModels/ShellViewModel.cs b/ADP/ViewModels/ShellViewModel.cs index c028ba2..7792b69 100644 --- a/ADP/ViewModels/ShellViewModel.cs +++ b/ADP/ViewModels/ShellViewModel.cs @@ -530,8 +530,8 @@ namespace ADP.ViewModels // 读取 JSON 文件 string json = File.ReadAllText(filePath); - // 反序列化为 ProgramModel - var program = Newtonsoft.Json.JsonConvert.DeserializeObject(json); + // 反序列化为 ProgramVM + var program = Newtonsoft.Json.JsonConvert.DeserializeObject(json); if (program == null) { @@ -621,12 +621,12 @@ namespace ADP.ViewModels LoggerHelper.SuccessWithNotify($"工位 [{runningScope}] 程序保存成功!"); } - // 💡 辅助方法:建议将你的通用序列化落盘代码调整为接收 ProgramModel 参数,提高复用性 - private void SaveProgramToFile(string filePath, ProgramModel programModel) + // 💡 辅助方法:建议将你的通用序列化落盘代码调整为接收 ProgramVM 参数,提高复用性 + private void SaveProgramToFile(string filePath, ProgramVM ProgramVM) { try { - string json = Newtonsoft.Json.JsonConvert.SerializeObject(programModel, Newtonsoft.Json.Formatting.Indented); + string json = Newtonsoft.Json.JsonConvert.SerializeObject(ProgramVM, Newtonsoft.Json.Formatting.Indented); File.WriteAllText(filePath, json); } catch (Exception ex) diff --git a/MainModule/ViewModels/AutomatedTestingViewModel.cs b/MainModule/ViewModels/AutomatedTestingViewModel.cs index ae7343c..3392937 100644 --- a/MainModule/ViewModels/AutomatedTestingViewModel.cs +++ b/MainModule/ViewModels/AutomatedTestingViewModel.cs @@ -133,8 +133,8 @@ namespace MainModule.ViewModels // 读取 JSON 文件 string json = File.ReadAllText(filePath); - // 反序列化为 ProgramModel - var program = Newtonsoft.Json.JsonConvert.DeserializeObject(json); + // 反序列化为 ProgramVM + var program = Newtonsoft.Json.JsonConvert.DeserializeObject(json); if (program == null) { diff --git a/Model/Models/CanMessageShow.cs b/Model/Models/CanMessageShow.cs new file mode 100644 index 0000000..8fa34dd --- /dev/null +++ b/Model/Models/CanMessageShow.cs @@ -0,0 +1,24 @@ +namespace Model.Models +{ + /// + /// CAN 报文展示纯数据类(对应 UIShare.UIViewModel.CanMessageShowModel) + /// + public class CanMessageShow + { + public byte 通道 { get; set; } + + public int 报文ID { get; set; } + + public ulong 时间戳 { get; set; } + + public byte 长度 { get; set; } + + public bool FD { get; set; } + + public bool IsTx { get; set; } + + public byte[] Bytes { get; set; } = new byte[64]; + + public string? 报文 { get; set; } + } +} diff --git a/Model/Models/DeviceInfo.cs b/Model/Models/DeviceInfo.cs new file mode 100644 index 0000000..7e2c415 --- /dev/null +++ b/Model/Models/DeviceInfo.cs @@ -0,0 +1,18 @@ +namespace Model.Models +{ + /// + /// 设备信息纯数据类(对应 UIShare.UIViewModel.DeviceInfoModel) + /// + public class DeviceInfo + { + public string? DeviceName { get; set; } + + public string? DeviceType { get; set; } + + public string? Remark { get; set; } + + public bool IsEnabled { get; set; } + + public bool IsConnected { get; set; } + } +} diff --git a/Model/Models/InstructionNode.cs b/Model/Models/InstructionNode.cs new file mode 100644 index 0000000..bd46445 --- /dev/null +++ b/Model/Models/InstructionNode.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace Model.Models +{ + /// + /// 指令节点纯数据类(对应 UIShare.UIViewModel.InstructionNode) + /// + public class InstructionNode + { + public string? Name { get; set; } + + public IList Children { get; set; } = new List(); + + public object? Tag { get; set; } + } +} diff --git a/Model/Models/Method.cs b/Model/Models/Method.cs new file mode 100644 index 0000000..350cbc3 --- /dev/null +++ b/Model/Models/Method.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace Model.Models +{ + /// + /// 方法纯数据类(对应 UIShare.UIViewModel.MethodModel) + /// + public class Method + { + public string? Name { get; set; } + + public string? FullName { get; set; } + + public IList Parameters { get; set; } = new List(); + } +} diff --git a/Model/Models/Parameter.cs b/Model/Models/Parameter.cs new file mode 100644 index 0000000..d8b0aa5 --- /dev/null +++ b/Model/Models/Parameter.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +namespace Model.Models +{ + /// + /// 参数纯数据类(对应 UIShare.UIViewModel.ParameterModel) + /// + public class Parameter + { + public Guid ID { get; set; } = Guid.NewGuid(); + + public bool IsVisible { get; set; } = true; + + public string? Name { get; set; } + + /// + /// 类型全名(对应 ParameterModel.Type 的 FullName) + /// + public string? TypeName { get; set; } + + /// + /// 参数类别(Input / Output / Temp) + /// + public string? Category { get; set; } + + public bool IsGlobal { get; set; } + + public object? Value { get; set; } + + public object? LowerLimit { get; set; } + + public object? UpperLimit { get; set; } + + public bool Result { get; set; } = true; + + public bool IsUseVar { get; set; } + + public bool IsSave { get; set; } + + public string? VariableName { get; set; } + + public Guid? VariableID { get; set; } + } +} diff --git a/Model/Models/Program.cs b/Model/Models/Program.cs new file mode 100644 index 0000000..5aef8a4 --- /dev/null +++ b/Model/Models/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; + +namespace Model.Models +{ + /// + /// 程序纯数据类(对应 UIShare.UIViewModel.ProgramModel) + /// + public class Program + { + public Guid ID { get; set; } = Guid.NewGuid(); + + public IList StepCollection { get; set; } = new List(); + + public IList ErrorStepCollection { get; set; } = new List(); + + public IList Parameters { get; set; } = new List(); + } +} diff --git a/Model/Models/Step.cs b/Model/Models/Step.cs new file mode 100644 index 0000000..812ef6a --- /dev/null +++ b/Model/Models/Step.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +namespace Model.Models +{ + /// + /// 步骤纯数据类(对应 UIShare.UIViewModel.StepModel) + /// + public class Step + { + public Guid ID { get; set; } = Guid.NewGuid(); + + public bool IsUsed { get; set; } = true; + + public int Index { get; set; } + + public string? Name { get; set; } + + public string? StepType { get; set; } + + public Method? Method { get; set; } + + public Program? SubProgram { get; set; } + + public int? LoopCount { get; set; } + + public int? CurrentLoopCount { get; set; } + + public Guid? LoopStartStepId { get; set; } + + public int Result { get; set; } = -1; + + public int? RunTime { get; set; } + + public string? OKExpression { get; set; } + + public string GotoSettingString { get; set; } = ""; + + public Guid? OKGotoStepID { get; set; } + + public Guid? NGGotoStepID { get; set; } + + public string? Description { get; set; } + } +} diff --git a/Model/Models/SubProgramItem.cs b/Model/Models/SubProgramItem.cs new file mode 100644 index 0000000..038b47d --- /dev/null +++ b/Model/Models/SubProgramItem.cs @@ -0,0 +1,12 @@ +namespace Model.Models +{ + /// + /// 子程序项纯数据类(对应 UIShare.UIViewModel.SubProgramItem) + /// + public class SubProgramItem + { + public string Name { get; set; } = ""; + + public string FilePath { get; set; } = ""; + } +} diff --git a/SettingModule/ViewModels/Dialogs/SerialPortConfigViewModel.cs b/SettingModule/ViewModels/Dialogs/SerialPortConfigViewModel.cs index 3b1473e..14da83b 100644 --- a/SettingModule/ViewModels/Dialogs/SerialPortConfigViewModel.cs +++ b/SettingModule/ViewModels/Dialogs/SerialPortConfigViewModel.cs @@ -10,7 +10,7 @@ namespace SettingModule.ViewModels.Dialogs { /// /// 串口连接配置对话框 VM。 - /// 通过 DialogParameters 接收宿主 DeviceInfoModel;保存时把副本写回宿主。 + /// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。 /// public class SerialPortConfigViewModel : DialogViewModelBase { @@ -23,8 +23,8 @@ namespace SettingModule.ViewModels.Dialogs set => SetProperty(ref _title, value); } - private SerialPortConnectionConfig _config = new(); - public SerialPortConnectionConfig Config + private SerialPortConfigVM _config = new(); + public SerialPortConfigVM Config { get => _config; set => SetProperty(ref _config, value); @@ -70,7 +70,7 @@ namespace SettingModule.ViewModels.Dialogs public ICommand RefreshPortsCommand { get; } #endregion - private DeviceInfoModel? _hostDevice; + private DeviceInfoVM? _hostDevice; public SerialPortConfigViewModel(IContainerProvider containerProvider) : base(containerProvider) { @@ -126,7 +126,7 @@ namespace SettingModule.ViewModels.Dialogs if (_hostDevice != null) { - _hostDevice.SerialPortConfig ??= new SerialPortConnectionConfig(); + _hostDevice.SerialPortConfig ??= new SerialPortConfigVM(); Config.CopyTo(_hostDevice.SerialPortConfig); _hostDevice.ConnectionType = "Serial"; } @@ -143,13 +143,13 @@ namespace SettingModule.ViewModels.Dialogs if (parameters.ContainsKey("Device")) { - _hostDevice = parameters.GetValue("Device"); + _hostDevice = parameters.GetValue("Device"); Title = $"串口连接配置 - {_hostDevice?.DeviceName}"; - Config = new SerialPortConnectionConfig(_hostDevice?.SerialPortConfig); + Config = new SerialPortConfigVM(_hostDevice?.SerialPortConfig); } else if (parameters.ContainsKey("Config")) { - Config = new SerialPortConnectionConfig(parameters.GetValue("Config")); + Config = new SerialPortConfigVM(parameters.GetValue("Config")); } RefreshPorts(); diff --git a/SettingModule/ViewModels/Dialogs/TCPConfigViewModel.cs b/SettingModule/ViewModels/Dialogs/TCPConfigViewModel.cs index a45b8fc..4ecd64c 100644 --- a/SettingModule/ViewModels/Dialogs/TCPConfigViewModel.cs +++ b/SettingModule/ViewModels/Dialogs/TCPConfigViewModel.cs @@ -9,7 +9,7 @@ namespace SettingModule.ViewModels.Dialogs { /// /// TCP 连接配置对话框 VM。 - /// 通过 DialogParameters 接收宿主 DeviceInfoModel;保存时把副本写回宿主。 + /// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。 /// public class TCPConfigViewModel : DialogViewModelBase { @@ -23,8 +23,8 @@ namespace SettingModule.ViewModels.Dialogs } /// 编辑用的副本,取消时不会污染宿主对象。 - private TcpConnectionConfig _config = new(); - public TcpConnectionConfig Config + private TcpConfigVM _config = new(); + public TcpConfigVM Config { get => _config; set => SetProperty(ref _config, value); @@ -57,7 +57,7 @@ namespace SettingModule.ViewModels.Dialogs #endregion // 用于保存时把副本回写到原对象 - private DeviceInfoModel? _hostDevice; + private DeviceInfoVM? _hostDevice; public TCPConfigViewModel(IContainerProvider containerProvider) : base(containerProvider) { @@ -103,7 +103,7 @@ namespace SettingModule.ViewModels.Dialogs // 把副本写回宿主 if (_hostDevice != null) { - _hostDevice.TcpConfig ??= new TcpConnectionConfig(); + _hostDevice.TcpConfig ??= new TcpConfigVM(); Config.CopyTo(_hostDevice.TcpConfig); _hostDevice.ConnectionType = "TCP"; } @@ -120,13 +120,13 @@ namespace SettingModule.ViewModels.Dialogs if (parameters.ContainsKey("Device")) { - _hostDevice = parameters.GetValue("Device"); + _hostDevice = parameters.GetValue("Device"); Title = $"TCP 连接配置 - {_hostDevice?.DeviceName}"; - Config = new TcpConnectionConfig(_hostDevice?.TcpConfig); + Config = new TcpConfigVM(_hostDevice?.TcpConfig); } else if (parameters.ContainsKey("Config")) { - Config = new TcpConnectionConfig(parameters.GetValue("Config")); + Config = new TcpConfigVM(parameters.GetValue("Config")); } } diff --git a/SettingModule/ViewModels/SettingViewModel.cs b/SettingModule/ViewModels/SettingViewModel.cs index 55f0aa9..2b30092 100644 --- a/SettingModule/ViewModels/SettingViewModel.cs +++ b/SettingModule/ViewModels/SettingViewModel.cs @@ -28,7 +28,7 @@ namespace SettingModule.ViewModels set => SetProperty(ref _testStatus, value); } - public DeviceInfoModel? SelectedDevice + public DeviceInfoVM? SelectedDevice { get => _selectedDevice; set @@ -40,7 +40,7 @@ namespace SettingModule.ViewModels } } - public ObservableCollection DeviceList + public ObservableCollection DeviceList { get => _deviceList; set => SetProperty(ref _deviceList, value); @@ -70,8 +70,8 @@ namespace SettingModule.ViewModels private GlobalInfo _globalInfo { get; } private bool IsInitiated = false; private string _testStatus = string.Empty; - private DeviceInfoModel? _selectedDevice; - private ObservableCollection _deviceList; + private DeviceInfoVM? _selectedDevice; + private ObservableCollection _deviceList; private string _statusMessage = "请在左侧选择设备查看 / 编辑配置"; #endregion public SettingViewModel(IContainerExtension container) : base(container) diff --git a/TestingModule/ViewModels/CommandTreeViewModel.cs b/TestingModule/ViewModels/CommandTreeViewModel.cs index 3b1405f..e6ecf03 100644 --- a/TestingModule/ViewModels/CommandTreeViewModel.cs +++ b/TestingModule/ViewModels/CommandTreeViewModel.cs @@ -18,7 +18,7 @@ using System.Windows.Controls; using System.Windows.Input; using System.Xml; using Model; -using static UIShare.UIViewModel.ParameterModel; +using static UIShare.UIViewModel.ParameterVM; using UIShare.ViewModelBase; using NLog; @@ -34,14 +34,14 @@ namespace TestingModule.ViewModels get => _SearchText; set => SetProperty(ref _SearchText, value); } - private ObservableCollection _instructionTree = new(); - public ObservableCollection InstructionTree + private ObservableCollection _instructionTree = new(); + public ObservableCollection InstructionTree { get => _instructionTree; set => SetProperty(ref _instructionTree, value); } - public ProgramModel Program + public ProgramVM Program { get => _ScopedContext.Program; set @@ -67,15 +67,15 @@ namespace TestingModule.ViewModels } } - private ObservableCollection _subPrograms = new(); - public ObservableCollection SubPrograms + private ObservableCollection _subPrograms = new(); + public ObservableCollection SubPrograms { get => _subPrograms; set => SetProperty(ref _subPrograms, value); } - private Dictionary _treeNodeMap = new(); - public Dictionary TreeNodeMap + private Dictionary _treeNodeMap = new(); + public Dictionary TreeNodeMap { get => _treeNodeMap; set => SetProperty(ref _treeNodeMap, value); @@ -119,7 +119,7 @@ namespace TestingModule.ViewModels private void TreeDoubleClick(object obj) { if (!_globalInfo.IsAdmin) return; - if(obj is InstructionNode Node) + if(obj is InstructionNodeVM Node) { if(Node.Children.Count == 0) { @@ -140,7 +140,7 @@ namespace TestingModule.ViewModels break; } } - else if(Node.Tag is SubProgramItem subProgram) + else if(Node.Tag is SubProgramItemVM subProgram) { AddSubProgramToProgram(subProgram, index); } @@ -211,7 +211,7 @@ namespace TestingModule.ViewModels { try { - SubPrograms.Add(new SubProgramItem + SubPrograms.Add(new SubProgramItemVM { Name = Path.GetFileNameWithoutExtension(filePath), FilePath = filePath @@ -229,7 +229,7 @@ namespace TestingModule.ViewModels private void LoadInstructionsToTreeView() { InstructionTree.Clear(); - var controlRootNode = new InstructionNode + var controlRootNode = new InstructionNodeVM { Name = "系统指令", Tag = "ControlRoot" @@ -237,14 +237,14 @@ namespace TestingModule.ViewModels InstructionTree.Add(controlRootNode); // 循环开始 - controlRootNode.Children.Add(new InstructionNode + controlRootNode.Children.Add(new InstructionNodeVM { Name = "循环开始", Tag = "循环开始" }); // 循环结束 - controlRootNode.Children.Add(new InstructionNode + controlRootNode.Children.Add(new InstructionNodeVM { Name = "循环结束", Tag = "循环结束" @@ -253,7 +253,7 @@ namespace TestingModule.ViewModels // ---------------------- // 子程序 根节点 // ---------------------- - var subProgramRoot = new InstructionNode + var subProgramRoot = new InstructionNodeVM { Name = "子程序", Tag = "SubProgramRoot" @@ -262,7 +262,7 @@ namespace TestingModule.ViewModels foreach (var subProgram in SubPrograms) { - subProgramRoot.Children.Add(new InstructionNode + subProgramRoot.Children.Add(new InstructionNodeVM { Name = subProgram.Name, Tag = subProgram, @@ -304,7 +304,7 @@ namespace TestingModule.ViewModels if (validTypes.Count > 0) { - var assemblyNode = new InstructionNode + var assemblyNode = new InstructionNodeVM { Name = assembly.GetName().Name, Tag = assembly @@ -320,7 +320,7 @@ namespace TestingModule.ViewModels // continue; //} - var typeNode = new InstructionNode + var typeNode = new InstructionNodeVM { Name = type.Name, Tag = type, @@ -346,7 +346,7 @@ namespace TestingModule.ViewModels var parameters = method.GetParameters(); var paramText = string.Join(", ", parameters.Select(p => $"{p.ParameterType.Name} {p.Name}")); - var methodNode = new InstructionNode + var methodNode = new InstructionNodeVM { Name = $"{method.Name}({paramText})", Tag = method, @@ -422,11 +422,11 @@ namespace TestingModule.ViewModels { try { - var newStep = new StepModel + var newStep = new StepVM { Name = method.Name, StepType = "方法", - Method = new MethodModel + Method = new MethodVM { FullName = method.DeclaringType?.FullName, Name = method.Name @@ -436,7 +436,7 @@ namespace TestingModule.ViewModels // 添加输入参数 foreach (var param in method.GetParameters()) { - newStep.Method.Parameters.Add(new ParameterModel + newStep.Method.Parameters.Add(new ParameterVM { Name = param.Name!, Type = param.ParameterType, @@ -455,7 +455,7 @@ namespace TestingModule.ViewModels { // 提取实际返回类型(如 Task -> bool) Type actualType = returnType.GetGenericArguments()[0]; - newStep.Method.Parameters.Add(new ParameterModel + newStep.Method.Parameters.Add(new ParameterVM { Name = "Result", Type = actualType, // 使用实际类型 @@ -465,7 +465,7 @@ namespace TestingModule.ViewModels else if (returnType != typeof(void)) { // 同步方法正常添加 - newStep.Method.Parameters.Add(new ParameterModel + newStep.Method.Parameters.Add(new ParameterVM { Name = "Result", Type = returnType, @@ -490,17 +490,17 @@ namespace TestingModule.ViewModels } } - private void AddSubProgramToProgram(SubProgramItem subProgram, int insertIndex = -1) + private void AddSubProgramToProgram(SubProgramItemVM subProgram, int insertIndex = -1) { try { - var newStep = new StepModel + var newStep = new StepVM { Name = subProgram.Name, StepType = "子程序" }; var jsonstr = File.ReadAllText($"{subProgram.FilePath}"); - var tmp = JsonConvert.DeserializeObject(jsonstr); + var tmp = JsonConvert.DeserializeObject(jsonstr); if (tmp != null) { newStep.SubProgram = tmp; @@ -525,7 +525,7 @@ namespace TestingModule.ViewModels private void AddLoopStartStep(int insertIndex = -1) { - var newStep = new StepModel + var newStep = new StepVM { Name = "循环开始", StepType = "循环开始", @@ -549,7 +549,7 @@ namespace TestingModule.ViewModels private void AddLoopEndStep(int insertIndex = -1) { // 查找最近的未匹配循环开始 - StepModel? lastUnmatchedLoopStart = null; + StepVM? lastUnmatchedLoopStart = null; for (int i = Program.StepCollection.Count - 1; i >= 0; i--) { if (Program.StepCollection[i].StepType == "循环开始") @@ -564,7 +564,7 @@ namespace TestingModule.ViewModels } } - var newStep = new StepModel + var newStep = new StepVM { Name = "循环结束", StepType = "循环结束", diff --git a/TestingModule/ViewModels/Dialogs/ParameterSettingViewModel.cs b/TestingModule/ViewModels/Dialogs/ParameterSettingViewModel.cs index bedd6d1..8495166 100644 --- a/TestingModule/ViewModels/Dialogs/ParameterSettingViewModel.cs +++ b/TestingModule/ViewModels/Dialogs/ParameterSettingViewModel.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Input; using UIShare.GlobalVariable; -using static UIShare.UIViewModel.ParameterModel; +using static UIShare.UIViewModel.ParameterVM; using UIShare.ViewModelBase; using Prism.Ioc; using Prism.Navigation.Regions; @@ -58,14 +58,14 @@ namespace TestingModule.ViewModels.Dialogs set => SetProperty(ref _Mode, value); } - private ProgramModel _program; - public ProgramModel Program + private ProgramVM _program; + public ProgramVM Program { get => _program; set => SetProperty(ref _program, value); } - private ParameterModel _Parameter; - public ParameterModel Parameter + private ParameterVM _Parameter; + public ParameterVM Parameter { get => _Parameter; set => SetProperty(ref _Parameter, value); @@ -127,7 +127,7 @@ namespace TestingModule.ViewModels.Dialogs } else { - Parameter = new ParameterModel(_ScopedContext.SelectedParameter); + Parameter = new ParameterVM(_ScopedContext.SelectedParameter); } } #endregion diff --git a/TestingModule/ViewModels/ParametersManagerViewModel.cs b/TestingModule/ViewModels/ParametersManagerViewModel.cs index be750cf..4c3adad 100644 --- a/TestingModule/ViewModels/ParametersManagerViewModel.cs +++ b/TestingModule/ViewModels/ParametersManagerViewModel.cs @@ -22,15 +22,15 @@ namespace TestingModule.ViewModels // get { return _DeviceList; } // set { SetProperty(ref _DeviceList,value); } //} - private ObservableCollection _DeviceInfoModel; + private ObservableCollection _DeviceInfoModel; - public ObservableCollection DeviceInfoModel + public ObservableCollection DeviceInfoVM { get { return _DeviceInfoModel; } set { SetProperty(ref _DeviceInfoModel, value); } } - public ProgramModel Program + public ProgramVM Program { get => _ScopedContext.Program; set @@ -42,8 +42,8 @@ namespace TestingModule.ViewModels } } } - private ParameterModel _SelectedParameter; - public ParameterModel SelectedParameter + private ParameterVM _SelectedParameter; + public ParameterVM SelectedParameter { get => _SelectedParameter; set @@ -54,11 +54,11 @@ namespace TestingModule.ViewModels } } } - private DeviceInfoModel _SelectedDevice; + private DeviceInfoVM _SelectedDevice; - public DeviceInfoModel SelectedDevice + public DeviceInfoVM SelectedDevice { get { return _SelectedDevice; } set { SetProperty(ref _SelectedDevice, value); } diff --git a/TestingModule/ViewModels/SingleStepEditViewModel.cs b/TestingModule/ViewModels/SingleStepEditViewModel.cs index feb2fa1..7b8d835 100644 --- a/TestingModule/ViewModels/SingleStepEditViewModel.cs +++ b/TestingModule/ViewModels/SingleStepEditViewModel.cs @@ -27,13 +27,13 @@ namespace TestingModule.ViewModels get => _ID; set => SetProperty(ref _ID, value); } - private StepModel _SelectedStep; - public StepModel SelectedStep + private StepVM _SelectedStep; + public StepVM SelectedStep { get => _SelectedStep; set => SetProperty(ref _SelectedStep, value); } - public ProgramModel Program + public ProgramVM Program { get => _ScopedContext.Program; set @@ -193,7 +193,7 @@ namespace TestingModule.ViewModels { if (_ScopedContext.SelectedStep == null) return; ID = _ScopedContext.SelectedStep.ID; - SelectedStep = new StepModel(_ScopedContext.SelectedStep); + SelectedStep = new StepVM(_ScopedContext.SelectedStep); } #endregion diff --git a/TestingModule/ViewModels/StepsManagerViewModel.cs b/TestingModule/ViewModels/StepsManagerViewModel.cs index b9f4814..8c7e3dd 100644 --- a/TestingModule/ViewModels/StepsManagerViewModel.cs +++ b/TestingModule/ViewModels/StepsManagerViewModel.cs @@ -44,14 +44,14 @@ namespace TestingModule.ViewModels get { return _selectedTabHeader; } set { SetProperty(ref _selectedTabHeader, value); } } - private List _SelectedItems; - public List SelectedItems + private List _SelectedItems; + public List SelectedItems { get { return _SelectedItems; } set { SetProperty(ref _SelectedItems, value); } } - private StepModel _SelectedStep; - public StepModel SelectedStep + private StepVM _SelectedStep; + public StepVM SelectedStep { get => _SelectedStep; set @@ -62,7 +62,7 @@ namespace TestingModule.ViewModels } } } - public ProgramModel Program + public ProgramVM Program { get => _ScopedContext.Program; set @@ -77,7 +77,7 @@ namespace TestingModule.ViewModels ScopedContext _ScopedContext { get; set; } private readonly SystemConfig _systemConfig; private readonly GlobalInfo _globalInfo; - private List tmpCopyList = new List(); + private List tmpCopyList = new List(); #endregion @@ -115,7 +115,7 @@ namespace TestingModule.ViewModels var selectedList = parameter as IList; if (selectedList != null) { - SelectedItems = selectedList.Cast().ToList(); + SelectedItems = selectedList.Cast().ToList(); } } @@ -157,7 +157,7 @@ namespace TestingModule.ViewModels foreach (var item in tmpCopyList) { // 创建新副本,避免引用同一个对象,并赋予新 ID - var newStep = new StepModel(item) { ID = Guid.NewGuid() }; + var newStep = new StepVM(item) { ID = Guid.NewGuid() }; Program.StepCollection.Insert(insertIndex, newStep); insertIndex++; // 递增索引,保证粘贴的多项顺序一致 } @@ -168,7 +168,7 @@ namespace TestingModule.ViewModels foreach (var item in tmpCopyList) { - var newStep = new StepModel(item) { ID = Guid.NewGuid() }; + var newStep = new StepVM(item) { ID = Guid.NewGuid() }; Program.ErrorStepCollection.Insert(insertIndex, newStep); insertIndex++; } @@ -208,7 +208,7 @@ namespace TestingModule.ViewModels #region 辅助方法 private void StepCollection_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { - var collection = sender as ObservableCollection; + var collection = sender as ObservableCollection; // Add/Move/Remove 都会触发,这里判断具体情形 if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add || e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move|| diff --git a/TestingModule/Views/CommandTree.xaml b/TestingModule/Views/CommandTree.xaml index 73905a8..781144b 100644 --- a/TestingModule/Views/CommandTree.xaml +++ b/TestingModule/Views/CommandTree.xaml @@ -51,7 +51,7 @@ - diff --git a/TestingModule/Views/ParametersManager.xaml b/TestingModule/Views/ParametersManager.xaml index 31bad17..3f257d7 100644 --- a/TestingModule/Views/ParametersManager.xaml +++ b/TestingModule/Views/ParametersManager.xaml @@ -69,7 +69,7 @@ () + return allParameters.Cast() .Where(p => IsTypeMatch(currentParamType, p.Type)) .ToList(); } diff --git a/UIShare/Converters/ParameterCategoryToStringConverter.cs b/UIShare/Converters/ParameterCategoryToStringConverter.cs index 2700efd..aa76d67 100644 --- a/UIShare/Converters/ParameterCategoryToStringConverter.cs +++ b/UIShare/Converters/ParameterCategoryToStringConverter.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; -using static UIShare.UIViewModel.ParameterModel; +using static UIShare.UIViewModel.ParameterVM; diff --git a/UIShare/Converters/ParameterCategoryToVisibilityConverter.cs b/UIShare/Converters/ParameterCategoryToVisibilityConverter.cs index 074a015..55fdfc5 100644 --- a/UIShare/Converters/ParameterCategoryToVisibilityConverter.cs +++ b/UIShare/Converters/ParameterCategoryToVisibilityConverter.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Data; -using static UIShare.UIViewModel.ParameterModel; +using static UIShare.UIViewModel.ParameterVM; diff --git a/UIShare/GlobalVariable/ScopedContext.cs b/UIShare/GlobalVariable/ScopedContext.cs index eddea7c..84c3038 100644 --- a/UIShare/GlobalVariable/ScopedContext.cs +++ b/UIShare/GlobalVariable/ScopedContext.cs @@ -15,7 +15,7 @@ namespace UIShare.GlobalVariable public class ScopedContext { private static readonly Random _randomSeed = new Random(); - public ProgramModel Program { get; set; } = new(); + public ProgramVM Program { get; set; } = new(); public String SelectedStepList { get; set; } = "主程序"; public string CurrentFilePath { get; set; } public bool? IsStop { get; set; } @@ -26,8 +26,8 @@ namespace UIShare.GlobalVariable public bool IsTerminate { get; set; } = false; public ObservableCollection Assemblies { get; set; } = new(); public PackIconKind RunIcon { get; set; } = PackIconKind.Play; - public StepModel SelectedStep { get; set; } - public ParameterModel SelectedParameter { get; set; } + public StepVM SelectedStep { get; set; } + public ParameterVM SelectedParameter { get; set; } public List DeviceList { get; set; } = new(); // 【新增测试属性】:每个实例被 new 出来时独一无二的随机身份 diff --git a/UIShare/GlobalVariable/StepRunning.cs b/UIShare/GlobalVariable/StepRunning.cs index 2d50f39..eed91ba 100644 --- a/UIShare/GlobalVariable/StepRunning.cs +++ b/UIShare/GlobalVariable/StepRunning.cs @@ -13,7 +13,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using UIShare.GlobalVariable; -using static UIShare.UIViewModel.ParameterModel; +using static UIShare.UIViewModel.ParameterVM; namespace UIShare @@ -26,7 +26,7 @@ namespace UIShare private IContainerProvider containerProvider; private IEventAggregator _eventAggregator; - private readonly Dictionary tmpParameters = []; + private readonly Dictionary tmpParameters = []; private readonly Stopwatch stepStopwatch = new(); @@ -46,7 +46,7 @@ namespace UIShare _eventAggregator = eventAggregator; //_devices = containerProvider.Resolve(); } - public async Task ExecuteErrorSteps(ProgramModel program, int depth = 0, CancellationToken cancellationToken = default) + public async Task ExecuteErrorSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default) { int index = 0; bool stepSuccess = false; @@ -211,7 +211,7 @@ namespace UIShare return loopStack.Count == 0 && stepSuccess; } - public async Task ExecuteSteps(ProgramModel program, int depth = 0, CancellationToken cancellationToken = default) + public async Task ExecuteSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default) { int index = 0; bool stepSuccess = false; @@ -388,7 +388,7 @@ namespace UIShare return loopStack.Count == 0 && stepSuccess; } - public async Task ExecuteMethodStep(StepModel step, Dictionary parameters, int depth, CancellationToken cancellationToken = default) + public async Task ExecuteMethodStep(StepVM step, Dictionary parameters, int depth, CancellationToken cancellationToken = default) { try { @@ -417,7 +417,7 @@ namespace UIShare // 3. 准备参数 var inputParams = new List(); var paramTypes = new List(); - ParameterModel? outputParam = null; + ParameterVM? outputParam = null; foreach (var param in step.Method!.Parameters) { if (param.Category == ParameterCategory.Input) @@ -656,7 +656,7 @@ namespace UIShare } } - public void ResetAllStepStatus(ObservableCollection StepCollection) + public void ResetAllStepStatus(ObservableCollection StepCollection) { foreach (var step in StepCollection) { @@ -665,7 +665,7 @@ namespace UIShare } } - private void UpdateCurrentStepResult(StepModel step, bool paraResult = true, bool stepResult = true, int depth = 0) + private void UpdateCurrentStepResult(StepVM step, bool paraResult = true, bool stepResult = true, int depth = 0) { if (stepResult && paraResult) { @@ -721,7 +721,7 @@ namespace UIShare public int LoopCount { get; set; } public int CurrentLoop { get; set; } public int StartIndex { get; set; } - public StepModel? LoopStartStep { get; set; } + public StepVM? LoopStartStep { get; set; } } #endregion diff --git a/UIShare/GlobalVariable/SystemConfig.cs b/UIShare/GlobalVariable/SystemConfig.cs index 69fd583..09f812a 100644 --- a/UIShare/GlobalVariable/SystemConfig.cs +++ b/UIShare/GlobalVariable/SystemConfig.cs @@ -26,10 +26,10 @@ namespace UIShare.GlobalVariable public string DefaultProgramFilePath { get; set; } = ""; public string DefaultBLFFilePath { get; set; } = ""; public string DefaultDBCFilePath { get; set; } = ""; - public ObservableCollection DeviceList = new(); -// public ObservableCollection DeviceList { get; set; } = new() + public ObservableCollection DeviceList = new(); +// public ObservableCollection DeviceList { get; set; } = new() //{ -// new DeviceInfoModel +// new DeviceInfoVM // { // DeviceName = "IT7800E", // DeviceType = "IT7800E", @@ -39,7 +39,7 @@ namespace UIShare.GlobalVariable // IsConnected = false // }, - // new DeviceInfoModel + // new DeviceInfoVM // { // DeviceName = "N36200", // DeviceType = "N36200", @@ -49,7 +49,7 @@ namespace UIShare.GlobalVariable // IsConnected = false // }, - // new DeviceInfoModel + // new DeviceInfoVM // { // DeviceName = "N36600", // DeviceType = "N36600", @@ -59,7 +59,7 @@ namespace UIShare.GlobalVariable // IsConnected = false // }, - // new DeviceInfoModel + // new DeviceInfoVM // { // DeviceName = "N69200", // DeviceType = "N69200", @@ -69,7 +69,7 @@ namespace UIShare.GlobalVariable // IsConnected = false // }, - // new DeviceInfoModel + // new DeviceInfoVM // { // DeviceName = "SDS2000X_HD", // DeviceType = "SDS2000X_HD", @@ -79,7 +79,7 @@ namespace UIShare.GlobalVariable // IsConnected = false // }, - // new DeviceInfoModel + // new DeviceInfoVM // { // DeviceName = "SPAW7000", // DeviceType = "SPAW7000", diff --git a/UIShare/UIViewModel/CanMessageShowModel.cs b/UIShare/UIViewModel/CanMessageShowVM.cs similarity index 96% rename from UIShare/UIViewModel/CanMessageShowModel.cs rename to UIShare/UIViewModel/CanMessageShowVM.cs index e4228bc..5c226a1 100644 --- a/UIShare/UIViewModel/CanMessageShowModel.cs +++ b/UIShare/UIViewModel/CanMessageShowVM.cs @@ -1,6 +1,6 @@ namespace UIShare.UIViewModel { - public class CanMessageShowModel : BindableBase + public class CanMessageShowVM : BindableBase { // 字段声明 private byte _通道; diff --git a/UIShare/UIViewModel/CustomPanelItem.cs b/UIShare/UIViewModel/CustomPanelItemVM.cs similarity index 86% rename from UIShare/UIViewModel/CustomPanelItem.cs rename to UIShare/UIViewModel/CustomPanelItemVM.cs index 48362c6..35025ee 100644 --- a/UIShare/UIViewModel/CustomPanelItem.cs +++ b/UIShare/UIViewModel/CustomPanelItemVM.cs @@ -2,17 +2,17 @@ using Prism.Mvvm; namespace UIShare.UIViewModel { - public class CustomPanelItem : BindableBase + public class CustomPanelItemVM : BindableBase { private string _name; - private string _pointY; + public string Name { get => _name; set => SetProperty(ref _name, value); } - + private string _pointY; public string PointY { get => _pointY; diff --git a/UIShare/UIViewModel/DeviceInfoModel.cs b/UIShare/UIViewModel/DeviceInfoVM.cs similarity index 86% rename from UIShare/UIViewModel/DeviceInfoModel.cs rename to UIShare/UIViewModel/DeviceInfoVM.cs index e409092..5a7b16c 100644 --- a/UIShare/UIViewModel/DeviceInfoModel.cs +++ b/UIShare/UIViewModel/DeviceInfoVM.cs @@ -2,7 +2,7 @@ namespace UIShare.UIViewModel { - public class DeviceInfoModel : BindableBase + public class DeviceInfoVM : BindableBase { private string _deviceName; public string DeviceName @@ -51,16 +51,16 @@ namespace UIShare.UIViewModel } /// TCP 连接参数(首次访问时自动初始化,便于 XAML 直接绑定)。 - private TcpConnectionConfig _tcpConfig = new(); - public TcpConnectionConfig TcpConfig + private TcpConfigVM _tcpConfig = new(); + public TcpConfigVM TcpConfig { get => _tcpConfig; set => SetProperty(ref _tcpConfig, value); } /// 串口连接参数(首次访问时自动初始化,便于 XAML 直接绑定)。 - private SerialPortConnectionConfig _serialPortConfig = new(); - public SerialPortConnectionConfig SerialPortConfig + private SerialPortConfigVM _serialPortConfig = new(); + public SerialPortConfigVM SerialPortConfig { get => _serialPortConfig; set => SetProperty(ref _serialPortConfig, value); diff --git a/UIShare/UIViewModel/InstructionNode.cs b/UIShare/UIViewModel/InstructionNode.cs deleted file mode 100644 index 7ec6b63..0000000 --- a/UIShare/UIViewModel/InstructionNode.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; - -namespace UIShare.UIViewModel -{ - public class InstructionNode - { - public string Name { get; set; } - public ObservableCollection Children { get; set; } = new(); - public object Tag { get; set; } - } - -} diff --git a/UIShare/UIViewModel/InstructionNodeVM.cs b/UIShare/UIViewModel/InstructionNodeVM.cs new file mode 100644 index 0000000..8d9617f --- /dev/null +++ b/UIShare/UIViewModel/InstructionNodeVM.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using Prism.Mvvm; // 确保引入了 Prism 命名空间 + +namespace UIShare.UIViewModel +{ + public class InstructionNodeVM : BindableBase + { + private string _name = string.Empty; + + public string Name + { + get => _name; + set => SetProperty(ref _name, value); + } + + private ObservableCollection _children = new(); + public ObservableCollection Children + { + get => _children; + set => SetProperty(ref _children, value); + } + + private object? _tag; + public object? Tag + { + get => _tag; + set => SetProperty(ref _tag, value); + } + } +} \ No newline at end of file diff --git a/UIShare/UIViewModel/MethodModel.cs b/UIShare/UIViewModel/MethodVM.cs similarity index 62% rename from UIShare/UIViewModel/MethodModel.cs rename to UIShare/UIViewModel/MethodVM.cs index b0173b6..9139ba4 100644 --- a/UIShare/UIViewModel/MethodModel.cs +++ b/UIShare/UIViewModel/MethodVM.cs @@ -7,17 +7,17 @@ using System.Threading.Tasks; namespace UIShare.UIViewModel { - public class MethodModel + public class MethodVM { #region 构造函数 - public MethodModel() + public MethodVM() { } - public MethodModel(MethodModel source) + public MethodVM(MethodVM source) { if (source == null) return; @@ -25,8 +25,8 @@ namespace UIShare.UIViewModel FullName = source.FullName; // 深拷贝参数 - Parameters = new ObservableCollection( - source.Parameters.Select(p => new ParameterModel(p))); + Parameters = new ObservableCollection( + source.Parameters.Select(p => new ParameterVM(p))); } #endregion @@ -35,6 +35,6 @@ namespace UIShare.UIViewModel public string? FullName { get; set; } - public ObservableCollection Parameters { get; set; } = []; + public ObservableCollection Parameters { get; set; } = []; } } diff --git a/UIShare/UIViewModel/ParameterModel.cs b/UIShare/UIViewModel/ParameterVM.cs similarity index 94% rename from UIShare/UIViewModel/ParameterModel.cs rename to UIShare/UIViewModel/ParameterVM.cs index 99afb04..c2fd642 100644 --- a/UIShare/UIViewModel/ParameterModel.cs +++ b/UIShare/UIViewModel/ParameterVM.cs @@ -5,16 +5,16 @@ using System.Collections.Generic; namespace UIShare.UIViewModel { - public class ParameterModel : BindableBase + public class ParameterVM : BindableBase { #region 构造函数 - public ParameterModel() + public ParameterVM() { } - public ParameterModel(ParameterModel source) + public ParameterVM(ParameterVM source) { if (source == null) return; @@ -139,10 +139,10 @@ namespace UIShare.UIViewModel Temp } - public object? GetActualValue(Dictionary paraList) + public object? GetActualValue(Dictionary paraList) { HashSet visitedIds = new HashSet(); - ParameterModel current = this; + ParameterVM current = this; while (current != null) { @@ -172,7 +172,7 @@ namespace UIShare.UIViewModel } } - ParameterModel? next = paraList[(Guid)current.VariableID!]; + ParameterVM? next = paraList[(Guid)current.VariableID!]; if (next == null) { return null; @@ -184,10 +184,10 @@ namespace UIShare.UIViewModel return null; } - public ParameterModel? GetCurrentParameter(Dictionary paraList) + public ParameterVM? GetCurrentParameter(Dictionary paraList) { HashSet visitedIds = new HashSet(); - ParameterModel current = this; + ParameterVM current = this; while (current != null) { @@ -217,7 +217,7 @@ namespace UIShare.UIViewModel } } - ParameterModel? next = paraList[(Guid)current.VariableID!]; + ParameterVM? next = paraList[(Guid)current.VariableID!]; if (next == null) { return null; diff --git a/UIShare/UIViewModel/ProgramModel.cs b/UIShare/UIViewModel/ProgramModel.cs deleted file mode 100644 index 447ea2f..0000000 --- a/UIShare/UIViewModel/ProgramModel.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Prism.Mvvm; // 引入 Prism 的 BindableBase -using System; -using System.Collections.ObjectModel; -using System.Linq; - -namespace UIShare.UIViewModel -{ - public class ProgramModel : BindableBase - { - #region 构造函数 - - public ProgramModel() - { - // 可以进行初始化操作 - } - - public ProgramModel(ProgramModel source) - { - ID = source.ID; - StepCollection = new ObservableCollection(source.StepCollection.Select(p => new StepModel(p))); - ErrorStepCollection = new ObservableCollection(source.ErrorStepCollection.Select(p => new StepModel(p))); - Parameters = new ObservableCollection(source.Parameters.Select(p => new ParameterModel(p))); - } - - #endregion - - public Guid ID { get; set; } = Guid.NewGuid(); - - private ObservableCollection _stepCollection = new ObservableCollection(); - public ObservableCollection StepCollection - { - get => _stepCollection; - set => SetProperty(ref _stepCollection, value); - } - private ObservableCollection _errorStepCollection = new ObservableCollection(); - public ObservableCollection ErrorStepCollection - { - get => _errorStepCollection; - set => SetProperty(ref _errorStepCollection, value); - } - - private ObservableCollection _parameters = new ObservableCollection(); - public ObservableCollection Parameters - { - get => _parameters; - set => SetProperty(ref _parameters, value); - } - - - } -} diff --git a/UIShare/UIViewModel/ProgramVM.cs b/UIShare/UIViewModel/ProgramVM.cs new file mode 100644 index 0000000..2df9c73 --- /dev/null +++ b/UIShare/UIViewModel/ProgramVM.cs @@ -0,0 +1,51 @@ +using Prism.Mvvm; // 引入 Prism 的 BindableBase +using System; +using System.Collections.ObjectModel; +using System.Linq; + +namespace UIShare.UIViewModel +{ + public class ProgramVM : BindableBase + { + #region 构造函数 + + public ProgramVM() + { + // 可以进行初始化操作 + } + + public ProgramVM(ProgramVM source) + { + ID = source.ID; + StepCollection = new ObservableCollection(source.StepCollection.Select(p => new StepVM(p))); + ErrorStepCollection = new ObservableCollection(source.ErrorStepCollection.Select(p => new StepVM(p))); + Parameters = new ObservableCollection(source.Parameters.Select(p => new ParameterVM(p))); + } + + #endregion + + public Guid ID { get; set; } = Guid.NewGuid(); + + private ObservableCollection _stepCollection = new ObservableCollection(); + public ObservableCollection StepCollection + { + get => _stepCollection; + set => SetProperty(ref _stepCollection, value); + } + private ObservableCollection _errorStepCollection = new ObservableCollection(); + public ObservableCollection ErrorStepCollection + { + get => _errorStepCollection; + set => SetProperty(ref _errorStepCollection, value); + } + + private ObservableCollection _parameters = new ObservableCollection(); + public ObservableCollection Parameters + { + get => _parameters; + set => SetProperty(ref _parameters, value); + } + + + } +} diff --git a/UIShare/UIViewModel/ConnectionConfig.cs b/UIShare/UIViewModel/SerialPortConfigVM.cs similarity index 54% rename from UIShare/UIViewModel/ConnectionConfig.cs rename to UIShare/UIViewModel/SerialPortConfigVM.cs index bd65905..e61c7f0 100644 --- a/UIShare/UIViewModel/ConnectionConfig.cs +++ b/UIShare/UIViewModel/SerialPortConfigVM.cs @@ -1,68 +1,16 @@ -using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace UIShare.UIViewModel { - /// - /// TCP 连接配置(与 DeviceCommand.Base.Tcp 保持字段一致)。 - /// - public class TcpConnectionConfig : BindableBase - { - private string _ipAddress = "127.0.0.1"; - public string IPAddress - { - get => _ipAddress; - set => SetProperty(ref _ipAddress, value); - } - - private int _port = 502; - public int Port - { - get => _port; - set => SetProperty(ref _port, value); - } - - private int _sendTimeout = 3000; - public int SendTimeout - { - get => _sendTimeout; - set => SetProperty(ref _sendTimeout, value); - } - - private int _receiveTimeout = 3000; - public int ReceiveTimeout - { - get => _receiveTimeout; - set => SetProperty(ref _receiveTimeout, value); - } - - public TcpConnectionConfig() { } - - /// 拷贝构造,用于对话框编辑副本。 - public TcpConnectionConfig(TcpConnectionConfig? src) - { - if (src == null) return; - IPAddress = src.IPAddress; - Port = src.Port; - SendTimeout = src.SendTimeout; - ReceiveTimeout = src.ReceiveTimeout; - } - - /// 把字段拷回目标对象(保存时用)。 - public void CopyTo(TcpConnectionConfig? dst) - { - if (dst == null) return; - dst.IPAddress = IPAddress; - dst.Port = Port; - dst.SendTimeout = SendTimeout; - dst.ReceiveTimeout = ReceiveTimeout; - } - } - /// /// 串口连接配置(与 DeviceCommand.Base.Serial_Port 保持字段一致)。 /// StopBits / Parity 用字符串保存,避免 UIShare 引入 System.IO.Ports 依赖。 /// - public class SerialPortConnectionConfig : BindableBase + public class SerialPortConfigVM : BindableBase { private string _portName = "COM1"; public string PortName @@ -115,9 +63,9 @@ namespace UIShare.UIViewModel set => SetProperty(ref _writeTimeout, value); } - public SerialPortConnectionConfig() { } + public SerialPortConfigVM() { } - public SerialPortConnectionConfig(SerialPortConnectionConfig? src) + public SerialPortConfigVM(SerialPortConfigVM? src) { if (src == null) return; PortName = src.PortName; @@ -129,7 +77,7 @@ namespace UIShare.UIViewModel WriteTimeout = src.WriteTimeout; } - public void CopyTo(SerialPortConnectionConfig? dst) + public void CopyTo(SerialPortConfigVM? dst) { if (dst == null) return; dst.PortName = PortName; diff --git a/UIShare/UIViewModel/StepModel.cs b/UIShare/UIViewModel/StepVM.cs similarity index 90% rename from UIShare/UIViewModel/StepModel.cs rename to UIShare/UIViewModel/StepVM.cs index 3675ca6..c66085e 100644 --- a/UIShare/UIViewModel/StepModel.cs +++ b/UIShare/UIViewModel/StepVM.cs @@ -4,13 +4,13 @@ using System; namespace UIShare.UIViewModel { - public class StepModel : BindableBase + public class StepVM : BindableBase { #region 构造函数 - public StepModel() { } + public StepVM() { } - public StepModel(StepModel source) + public StepVM(StepVM source) { if (source == null) return; @@ -29,11 +29,11 @@ namespace UIShare.UIViewModel if (source.Method != null) { - Method = new MethodModel(source.Method); + Method = new MethodVM(source.Method); } if (source.SubProgram != null) { - SubProgram = new ProgramModel(source.SubProgram); + SubProgram = new ProgramVM(source.SubProgram); } } @@ -79,17 +79,17 @@ namespace UIShare.UIViewModel set => SetProperty(ref _stepType, value); } - private MethodModel? _method; + private MethodVM? _method; - public MethodModel? Method + public MethodVM? Method { get => _method; set => SetProperty(ref _method, value); } - private ProgramModel? _subProgram; + private ProgramVM? _subProgram; - public ProgramModel? SubProgram + public ProgramVM? SubProgram { get => _subProgram; set => SetProperty(ref _subProgram, value); diff --git a/UIShare/UIViewModel/SubProgramItem.cs b/UIShare/UIViewModel/SubProgramItem.cs deleted file mode 100644 index a02bd94..0000000 --- a/UIShare/UIViewModel/SubProgramItem.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace UIShare.UIViewModel -{ - public class SubProgramItem - { - public string Name { get; set; } = ""; - - public string FilePath { get; set; } = ""; - } -} diff --git a/UIShare/UIViewModel/SubProgramItemVM.cs b/UIShare/UIViewModel/SubProgramItemVM.cs new file mode 100644 index 0000000..d2fae89 --- /dev/null +++ b/UIShare/UIViewModel/SubProgramItemVM.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UIShare.UIViewModel +{ + public class SubProgramItemVM : BindableBase + { + + private string _name=""; + + public string Name + { + get => _name; + set => SetProperty(ref _name, value); + } + private string _filePath = ""; + + public string FilePath + { + get => _filePath; + set => SetProperty(ref _filePath, value); + } + + } +} diff --git a/UIShare/UIViewModel/TcpConfigVM.cs b/UIShare/UIViewModel/TcpConfigVM.cs new file mode 100644 index 0000000..82ff1b3 --- /dev/null +++ b/UIShare/UIViewModel/TcpConfigVM.cs @@ -0,0 +1,62 @@ +using Prism.Mvvm; + +namespace UIShare.UIViewModel +{ + /// + /// TCP 连接配置(与 DeviceCommand.Base.Tcp 保持字段一致)。 + /// + public class TcpConfigVM : BindableBase + { + private string _ipAddress = "127.0.0.1"; + public string IPAddress + { + get => _ipAddress; + set => SetProperty(ref _ipAddress, value); + } + + private int _port = 502; + public int Port + { + get => _port; + set => SetProperty(ref _port, value); + } + + private int _sendTimeout = 3000; + public int SendTimeout + { + get => _sendTimeout; + set => SetProperty(ref _sendTimeout, value); + } + + private int _receiveTimeout = 3000; + public int ReceiveTimeout + { + get => _receiveTimeout; + set => SetProperty(ref _receiveTimeout, value); + } + + public TcpConfigVM() { } + + /// 拷贝构造,用于对话框编辑副本。 + public TcpConfigVM(TcpConfigVM? src) + { + if (src == null) return; + IPAddress = src.IPAddress; + Port = src.Port; + SendTimeout = src.SendTimeout; + ReceiveTimeout = src.ReceiveTimeout; + } + + /// 把字段拷回目标对象(保存时用)。 + public void CopyTo(TcpConfigVM? dst) + { + if (dst == null) return; + dst.IPAddress = IPAddress; + dst.Port = Port; + dst.SendTimeout = SendTimeout; + dst.ReceiveTimeout = ReceiveTimeout; + } + } + + +}