automapper框架优化
This commit is contained in:
@@ -8,6 +8,10 @@
|
|||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutoMapper" Version="16.1.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\CAN驱动\CAN驱动.csproj" />
|
<ProjectReference Include="..\CAN驱动\CAN驱动.csproj" />
|
||||||
<ProjectReference Include="..\Command\Command.csproj" />
|
<ProjectReference Include="..\Command\Command.csproj" />
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ using UIShare;
|
|||||||
using System;
|
using System;
|
||||||
using DeviceCommand.Device;
|
using DeviceCommand.Device;
|
||||||
using DeviceCommand.Base;
|
using DeviceCommand.Base;
|
||||||
|
using AutoMapper;
|
||||||
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
using ADP.Profiles;
|
||||||
|
|
||||||
namespace ADP
|
namespace ADP
|
||||||
{
|
{
|
||||||
@@ -68,6 +71,22 @@ namespace ADP
|
|||||||
RegionManager.SetRegionManager(Application.Current.MainWindow, re);
|
RegionManager.SetRegionManager(Application.Current.MainWindow, re);
|
||||||
login.Show();
|
login.Show();
|
||||||
}
|
}
|
||||||
|
protected override void RegisterRequiredTypes(IContainerRegistry containerRegistry)
|
||||||
|
{
|
||||||
|
base.RegisterRequiredTypes(containerRegistry);
|
||||||
|
//注册全局变量
|
||||||
|
containerRegistry.RegisterScoped<SystemConfig>();
|
||||||
|
containerRegistry.RegisterScoped<StepRunning>();
|
||||||
|
containerRegistry.RegisterScoped<ScopedContext>();
|
||||||
|
containerRegistry.RegisterScoped<DeviceManager>();
|
||||||
|
containerRegistry.RegisterSingleton<GlobalInfo>();
|
||||||
|
//注册AutoMapper
|
||||||
|
var config = new MapperConfiguration(
|
||||||
|
cfg => cfg.AddProfile<AutoMapperProfile>(),
|
||||||
|
NullLoggerFactory.Instance
|
||||||
|
);
|
||||||
|
containerRegistry.RegisterSingleton<IMapper>(() => config.CreateMapper());
|
||||||
|
}
|
||||||
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
protected override void RegisterTypes(IContainerRegistry containerRegistry)
|
||||||
{
|
{
|
||||||
//注册弹窗
|
//注册弹窗
|
||||||
@@ -75,12 +94,8 @@ namespace ADP
|
|||||||
// 注册通知管理器
|
// 注册通知管理器
|
||||||
INotificationManager NotificationManager = new NotificationManager();
|
INotificationManager NotificationManager = new NotificationManager();
|
||||||
containerRegistry.RegisterInstance<INotificationManager>(NotificationManager);
|
containerRegistry.RegisterInstance<INotificationManager>(NotificationManager);
|
||||||
//注册全局变量
|
// 注册仓储
|
||||||
containerRegistry.RegisterScoped<SystemConfig>();
|
containerRegistry.RegisterScoped(typeof(SqlSugarRepository<>));
|
||||||
containerRegistry.RegisterScoped<StepRunning>();
|
|
||||||
containerRegistry.RegisterScoped<ScopedContext>();
|
|
||||||
containerRegistry.RegisterScoped<DeviceManager>();
|
|
||||||
containerRegistry.RegisterSingleton<GlobalInfo>();
|
|
||||||
}
|
}
|
||||||
//指定模块加载方式(需要手动将模块生成的dll放入Modules文件夹中)
|
//指定模块加载方式(需要手动将模块生成的dll放入Modules文件夹中)
|
||||||
protected override IModuleCatalog CreateModuleCatalog()
|
protected override IModuleCatalog CreateModuleCatalog()
|
||||||
|
|||||||
64
ADP/Profiles/AutoMapperProfile.cs
Normal file
64
ADP/Profiles/AutoMapperProfile.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using Model.Models;
|
||||||
|
using System;
|
||||||
|
using UIShare.UIViewModel;
|
||||||
|
|
||||||
|
namespace ADP.Profiles
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// UIShare.UIViewModel ↔ Model.Models 双向映射配置。
|
||||||
|
/// </summary>
|
||||||
|
public class AutoMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
// ===== Parameter =====
|
||||||
|
// ParameterModel.Type(System.Type) ↔ Parameter.TypeName(string)
|
||||||
|
// ParameterModel.Category(enum) ↔ Parameter.Category(string)
|
||||||
|
CreateMap<ParameterVM, Parameter>()
|
||||||
|
.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<Parameter, ParameterVM>()
|
||||||
|
.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<StepVM, Step>().ReverseMap();
|
||||||
|
|
||||||
|
// ===== Program =====
|
||||||
|
CreateMap<ProgramVM, Program>().ReverseMap();
|
||||||
|
|
||||||
|
// ===== Method =====
|
||||||
|
CreateMap<MethodVM, Method>().ReverseMap();
|
||||||
|
|
||||||
|
// ===== DeviceInfo =====
|
||||||
|
CreateMap<DeviceInfoVM, DeviceInfo>().ReverseMap();
|
||||||
|
|
||||||
|
// ===== CanMessageShow =====
|
||||||
|
CreateMap<CanMessageShowVM, CanMessageShow>().ReverseMap();
|
||||||
|
|
||||||
|
|
||||||
|
// ===== InstructionNode =====
|
||||||
|
CreateMap<InstructionNodeVM, InstructionNode>().ReverseMap();
|
||||||
|
|
||||||
|
// ===== SubProgramItem =====
|
||||||
|
CreateMap<SubProgramItemVM,SubProgramItem>().ReverseMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ParameterVM.ParameterCategory ParseCategory(string? category)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(category))
|
||||||
|
return ParameterVM.ParameterCategory.Temp;
|
||||||
|
return Enum.TryParse<ParameterVM.ParameterCategory>(category, true, out var result)
|
||||||
|
? result
|
||||||
|
: ParameterVM.ParameterCategory.Temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -530,8 +530,8 @@ namespace ADP.ViewModels
|
|||||||
// 读取 JSON 文件
|
// 读取 JSON 文件
|
||||||
string json = File.ReadAllText(filePath);
|
string json = File.ReadAllText(filePath);
|
||||||
|
|
||||||
// 反序列化为 ProgramModel
|
// 反序列化为 ProgramVM
|
||||||
var program = Newtonsoft.Json.JsonConvert.DeserializeObject<ProgramModel>(json);
|
var program = Newtonsoft.Json.JsonConvert.DeserializeObject<ProgramVM>(json);
|
||||||
|
|
||||||
if (program == null)
|
if (program == null)
|
||||||
{
|
{
|
||||||
@@ -621,12 +621,12 @@ namespace ADP.ViewModels
|
|||||||
LoggerHelper.SuccessWithNotify($"工位 [{runningScope}] 程序保存成功!");
|
LoggerHelper.SuccessWithNotify($"工位 [{runningScope}] 程序保存成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 💡 辅助方法:建议将你的通用序列化落盘代码调整为接收 ProgramModel 参数,提高复用性
|
// 💡 辅助方法:建议将你的通用序列化落盘代码调整为接收 ProgramVM 参数,提高复用性
|
||||||
private void SaveProgramToFile(string filePath, ProgramModel programModel)
|
private void SaveProgramToFile(string filePath, ProgramVM ProgramVM)
|
||||||
{
|
{
|
||||||
try
|
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);
|
File.WriteAllText(filePath, json);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -133,8 +133,8 @@ namespace MainModule.ViewModels
|
|||||||
// 读取 JSON 文件
|
// 读取 JSON 文件
|
||||||
string json = File.ReadAllText(filePath);
|
string json = File.ReadAllText(filePath);
|
||||||
|
|
||||||
// 反序列化为 ProgramModel
|
// 反序列化为 ProgramVM
|
||||||
var program = Newtonsoft.Json.JsonConvert.DeserializeObject<ProgramModel>(json);
|
var program = Newtonsoft.Json.JsonConvert.DeserializeObject<ProgramVM>(json);
|
||||||
|
|
||||||
if (program == null)
|
if (program == null)
|
||||||
{
|
{
|
||||||
|
|||||||
24
Model/Models/CanMessageShow.cs
Normal file
24
Model/Models/CanMessageShow.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
namespace Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// CAN 报文展示纯数据类(对应 UIShare.UIViewModel.CanMessageShowModel)
|
||||||
|
/// </summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Model/Models/DeviceInfo.cs
Normal file
18
Model/Models/DeviceInfo.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 设备信息纯数据类(对应 UIShare.UIViewModel.DeviceInfoModel)
|
||||||
|
/// </summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
16
Model/Models/InstructionNode.cs
Normal file
16
Model/Models/InstructionNode.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 指令节点纯数据类(对应 UIShare.UIViewModel.InstructionNode)
|
||||||
|
/// </summary>
|
||||||
|
public class InstructionNode
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public IList<InstructionNode> Children { get; set; } = new List<InstructionNode>();
|
||||||
|
|
||||||
|
public object? Tag { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
16
Model/Models/Method.cs
Normal file
16
Model/Models/Method.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 方法纯数据类(对应 UIShare.UIViewModel.MethodModel)
|
||||||
|
/// </summary>
|
||||||
|
public class Method
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? FullName { get; set; }
|
||||||
|
|
||||||
|
public IList<Parameter> Parameters { get; set; } = new List<Parameter>();
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Model/Models/Parameter.cs
Normal file
45
Model/Models/Parameter.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 参数纯数据类(对应 UIShare.UIViewModel.ParameterModel)
|
||||||
|
/// </summary>
|
||||||
|
public class Parameter
|
||||||
|
{
|
||||||
|
public Guid ID { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
|
public bool IsVisible { get; set; } = true;
|
||||||
|
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 类型全名(对应 ParameterModel.Type 的 FullName)
|
||||||
|
/// </summary>
|
||||||
|
public string? TypeName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 参数类别(Input / Output / Temp)
|
||||||
|
/// </summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
19
Model/Models/Program.cs
Normal file
19
Model/Models/Program.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 程序纯数据类(对应 UIShare.UIViewModel.ProgramModel)
|
||||||
|
/// </summary>
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public Guid ID { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
|
public IList<Step> StepCollection { get; set; } = new List<Step>();
|
||||||
|
|
||||||
|
public IList<Step> ErrorStepCollection { get; set; } = new List<Step>();
|
||||||
|
|
||||||
|
public IList<Parameter> Parameters { get; set; } = new List<Parameter>();
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Model/Models/Step.cs
Normal file
45
Model/Models/Step.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 步骤纯数据类(对应 UIShare.UIViewModel.StepModel)
|
||||||
|
/// </summary>
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Model/Models/SubProgramItem.cs
Normal file
12
Model/Models/SubProgramItem.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace Model.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 子程序项纯数据类(对应 UIShare.UIViewModel.SubProgramItem)
|
||||||
|
/// </summary>
|
||||||
|
public class SubProgramItem
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = "";
|
||||||
|
|
||||||
|
public string FilePath { get; set; } = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 串口连接配置对话框 VM。
|
/// 串口连接配置对话框 VM。
|
||||||
/// 通过 DialogParameters 接收宿主 DeviceInfoModel;保存时把副本写回宿主。
|
/// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SerialPortConfigViewModel : DialogViewModelBase
|
public class SerialPortConfigViewModel : DialogViewModelBase
|
||||||
{
|
{
|
||||||
@@ -23,8 +23,8 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
set => SetProperty(ref _title, value);
|
set => SetProperty(ref _title, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SerialPortConnectionConfig _config = new();
|
private SerialPortConfigVM _config = new();
|
||||||
public SerialPortConnectionConfig Config
|
public SerialPortConfigVM Config
|
||||||
{
|
{
|
||||||
get => _config;
|
get => _config;
|
||||||
set => SetProperty(ref _config, value);
|
set => SetProperty(ref _config, value);
|
||||||
@@ -70,7 +70,7 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
public ICommand RefreshPortsCommand { get; }
|
public ICommand RefreshPortsCommand { get; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private DeviceInfoModel? _hostDevice;
|
private DeviceInfoVM? _hostDevice;
|
||||||
|
|
||||||
public SerialPortConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
public SerialPortConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||||
{
|
{
|
||||||
@@ -126,7 +126,7 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
|
|
||||||
if (_hostDevice != null)
|
if (_hostDevice != null)
|
||||||
{
|
{
|
||||||
_hostDevice.SerialPortConfig ??= new SerialPortConnectionConfig();
|
_hostDevice.SerialPortConfig ??= new SerialPortConfigVM();
|
||||||
Config.CopyTo(_hostDevice.SerialPortConfig);
|
Config.CopyTo(_hostDevice.SerialPortConfig);
|
||||||
_hostDevice.ConnectionType = "Serial";
|
_hostDevice.ConnectionType = "Serial";
|
||||||
}
|
}
|
||||||
@@ -143,13 +143,13 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
|
|
||||||
if (parameters.ContainsKey("Device"))
|
if (parameters.ContainsKey("Device"))
|
||||||
{
|
{
|
||||||
_hostDevice = parameters.GetValue<DeviceInfoModel>("Device");
|
_hostDevice = parameters.GetValue<DeviceInfoVM>("Device");
|
||||||
Title = $"串口连接配置 - {_hostDevice?.DeviceName}";
|
Title = $"串口连接配置 - {_hostDevice?.DeviceName}";
|
||||||
Config = new SerialPortConnectionConfig(_hostDevice?.SerialPortConfig);
|
Config = new SerialPortConfigVM(_hostDevice?.SerialPortConfig);
|
||||||
}
|
}
|
||||||
else if (parameters.ContainsKey("Config"))
|
else if (parameters.ContainsKey("Config"))
|
||||||
{
|
{
|
||||||
Config = new SerialPortConnectionConfig(parameters.GetValue<SerialPortConnectionConfig>("Config"));
|
Config = new SerialPortConfigVM(parameters.GetValue<SerialPortConfigVM>("Config"));
|
||||||
}
|
}
|
||||||
|
|
||||||
RefreshPorts();
|
RefreshPorts();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TCP 连接配置对话框 VM。
|
/// TCP 连接配置对话框 VM。
|
||||||
/// 通过 DialogParameters 接收宿主 DeviceInfoModel;保存时把副本写回宿主。
|
/// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TCPConfigViewModel : DialogViewModelBase
|
public class TCPConfigViewModel : DialogViewModelBase
|
||||||
{
|
{
|
||||||
@@ -23,8 +23,8 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>编辑用的副本,取消时不会污染宿主对象。</summary>
|
/// <summary>编辑用的副本,取消时不会污染宿主对象。</summary>
|
||||||
private TcpConnectionConfig _config = new();
|
private TcpConfigVM _config = new();
|
||||||
public TcpConnectionConfig Config
|
public TcpConfigVM Config
|
||||||
{
|
{
|
||||||
get => _config;
|
get => _config;
|
||||||
set => SetProperty(ref _config, value);
|
set => SetProperty(ref _config, value);
|
||||||
@@ -57,7 +57,7 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// 用于保存时把副本回写到原对象
|
// 用于保存时把副本回写到原对象
|
||||||
private DeviceInfoModel? _hostDevice;
|
private DeviceInfoVM? _hostDevice;
|
||||||
|
|
||||||
public TCPConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
public TCPConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||||
{
|
{
|
||||||
@@ -103,7 +103,7 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
// 把副本写回宿主
|
// 把副本写回宿主
|
||||||
if (_hostDevice != null)
|
if (_hostDevice != null)
|
||||||
{
|
{
|
||||||
_hostDevice.TcpConfig ??= new TcpConnectionConfig();
|
_hostDevice.TcpConfig ??= new TcpConfigVM();
|
||||||
Config.CopyTo(_hostDevice.TcpConfig);
|
Config.CopyTo(_hostDevice.TcpConfig);
|
||||||
_hostDevice.ConnectionType = "TCP";
|
_hostDevice.ConnectionType = "TCP";
|
||||||
}
|
}
|
||||||
@@ -120,13 +120,13 @@ namespace SettingModule.ViewModels.Dialogs
|
|||||||
|
|
||||||
if (parameters.ContainsKey("Device"))
|
if (parameters.ContainsKey("Device"))
|
||||||
{
|
{
|
||||||
_hostDevice = parameters.GetValue<DeviceInfoModel>("Device");
|
_hostDevice = parameters.GetValue<DeviceInfoVM>("Device");
|
||||||
Title = $"TCP 连接配置 - {_hostDevice?.DeviceName}";
|
Title = $"TCP 连接配置 - {_hostDevice?.DeviceName}";
|
||||||
Config = new TcpConnectionConfig(_hostDevice?.TcpConfig);
|
Config = new TcpConfigVM(_hostDevice?.TcpConfig);
|
||||||
}
|
}
|
||||||
else if (parameters.ContainsKey("Config"))
|
else if (parameters.ContainsKey("Config"))
|
||||||
{
|
{
|
||||||
Config = new TcpConnectionConfig(parameters.GetValue<TcpConnectionConfig>("Config"));
|
Config = new TcpConfigVM(parameters.GetValue<TcpConfigVM>("Config"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace SettingModule.ViewModels
|
|||||||
set => SetProperty(ref _testStatus, value);
|
set => SetProperty(ref _testStatus, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DeviceInfoModel? SelectedDevice
|
public DeviceInfoVM? SelectedDevice
|
||||||
{
|
{
|
||||||
get => _selectedDevice;
|
get => _selectedDevice;
|
||||||
set
|
set
|
||||||
@@ -40,7 +40,7 @@ namespace SettingModule.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableCollection<DeviceInfoModel> DeviceList
|
public ObservableCollection<DeviceInfoVM> DeviceList
|
||||||
{
|
{
|
||||||
get => _deviceList;
|
get => _deviceList;
|
||||||
set => SetProperty(ref _deviceList, value);
|
set => SetProperty(ref _deviceList, value);
|
||||||
@@ -70,8 +70,8 @@ namespace SettingModule.ViewModels
|
|||||||
private GlobalInfo _globalInfo { get; }
|
private GlobalInfo _globalInfo { get; }
|
||||||
private bool IsInitiated = false;
|
private bool IsInitiated = false;
|
||||||
private string _testStatus = string.Empty;
|
private string _testStatus = string.Empty;
|
||||||
private DeviceInfoModel? _selectedDevice;
|
private DeviceInfoVM? _selectedDevice;
|
||||||
private ObservableCollection<DeviceInfoModel> _deviceList;
|
private ObservableCollection<DeviceInfoVM> _deviceList;
|
||||||
private string _statusMessage = "请在左侧选择设备查看 / 编辑配置";
|
private string _statusMessage = "请在左侧选择设备查看 / 编辑配置";
|
||||||
#endregion
|
#endregion
|
||||||
public SettingViewModel(IContainerExtension container) : base(container)
|
public SettingViewModel(IContainerExtension container) : base(container)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Model;
|
using Model;
|
||||||
using static UIShare.UIViewModel.ParameterModel;
|
using static UIShare.UIViewModel.ParameterVM;
|
||||||
using UIShare.ViewModelBase;
|
using UIShare.ViewModelBase;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
@@ -34,14 +34,14 @@ namespace TestingModule.ViewModels
|
|||||||
get => _SearchText;
|
get => _SearchText;
|
||||||
set => SetProperty(ref _SearchText, value);
|
set => SetProperty(ref _SearchText, value);
|
||||||
}
|
}
|
||||||
private ObservableCollection<InstructionNode> _instructionTree = new();
|
private ObservableCollection<InstructionNodeVM> _instructionTree = new();
|
||||||
public ObservableCollection<InstructionNode> InstructionTree
|
public ObservableCollection<InstructionNodeVM> InstructionTree
|
||||||
{
|
{
|
||||||
get => _instructionTree;
|
get => _instructionTree;
|
||||||
set => SetProperty(ref _instructionTree, value);
|
set => SetProperty(ref _instructionTree, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgramModel Program
|
public ProgramVM Program
|
||||||
{
|
{
|
||||||
get => _ScopedContext.Program;
|
get => _ScopedContext.Program;
|
||||||
set
|
set
|
||||||
@@ -67,15 +67,15 @@ namespace TestingModule.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObservableCollection<SubProgramItem> _subPrograms = new();
|
private ObservableCollection<SubProgramItemVM> _subPrograms = new();
|
||||||
public ObservableCollection<SubProgramItem> SubPrograms
|
public ObservableCollection<SubProgramItemVM> SubPrograms
|
||||||
{
|
{
|
||||||
get => _subPrograms;
|
get => _subPrograms;
|
||||||
set => SetProperty(ref _subPrograms, value);
|
set => SetProperty(ref _subPrograms, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<object, InstructionNode> _treeNodeMap = new();
|
private Dictionary<object, InstructionNodeVM> _treeNodeMap = new();
|
||||||
public Dictionary<object, InstructionNode> TreeNodeMap
|
public Dictionary<object, InstructionNodeVM> TreeNodeMap
|
||||||
{
|
{
|
||||||
get => _treeNodeMap;
|
get => _treeNodeMap;
|
||||||
set => SetProperty(ref _treeNodeMap, value);
|
set => SetProperty(ref _treeNodeMap, value);
|
||||||
@@ -119,7 +119,7 @@ namespace TestingModule.ViewModels
|
|||||||
private void TreeDoubleClick(object obj)
|
private void TreeDoubleClick(object obj)
|
||||||
{
|
{
|
||||||
if (!_globalInfo.IsAdmin) return;
|
if (!_globalInfo.IsAdmin) return;
|
||||||
if(obj is InstructionNode Node)
|
if(obj is InstructionNodeVM Node)
|
||||||
{
|
{
|
||||||
if(Node.Children.Count == 0)
|
if(Node.Children.Count == 0)
|
||||||
{
|
{
|
||||||
@@ -140,7 +140,7 @@ namespace TestingModule.ViewModels
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(Node.Tag is SubProgramItem subProgram)
|
else if(Node.Tag is SubProgramItemVM subProgram)
|
||||||
{
|
{
|
||||||
AddSubProgramToProgram(subProgram, index);
|
AddSubProgramToProgram(subProgram, index);
|
||||||
}
|
}
|
||||||
@@ -211,7 +211,7 @@ namespace TestingModule.ViewModels
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SubPrograms.Add(new SubProgramItem
|
SubPrograms.Add(new SubProgramItemVM
|
||||||
{
|
{
|
||||||
Name = Path.GetFileNameWithoutExtension(filePath),
|
Name = Path.GetFileNameWithoutExtension(filePath),
|
||||||
FilePath = filePath
|
FilePath = filePath
|
||||||
@@ -229,7 +229,7 @@ namespace TestingModule.ViewModels
|
|||||||
private void LoadInstructionsToTreeView()
|
private void LoadInstructionsToTreeView()
|
||||||
{
|
{
|
||||||
InstructionTree.Clear();
|
InstructionTree.Clear();
|
||||||
var controlRootNode = new InstructionNode
|
var controlRootNode = new InstructionNodeVM
|
||||||
{
|
{
|
||||||
Name = "系统指令",
|
Name = "系统指令",
|
||||||
Tag = "ControlRoot"
|
Tag = "ControlRoot"
|
||||||
@@ -237,14 +237,14 @@ namespace TestingModule.ViewModels
|
|||||||
InstructionTree.Add(controlRootNode);
|
InstructionTree.Add(controlRootNode);
|
||||||
|
|
||||||
// 循环开始
|
// 循环开始
|
||||||
controlRootNode.Children.Add(new InstructionNode
|
controlRootNode.Children.Add(new InstructionNodeVM
|
||||||
{
|
{
|
||||||
Name = "循环开始",
|
Name = "循环开始",
|
||||||
Tag = "循环开始"
|
Tag = "循环开始"
|
||||||
});
|
});
|
||||||
|
|
||||||
// 循环结束
|
// 循环结束
|
||||||
controlRootNode.Children.Add(new InstructionNode
|
controlRootNode.Children.Add(new InstructionNodeVM
|
||||||
{
|
{
|
||||||
Name = "循环结束",
|
Name = "循环结束",
|
||||||
Tag = "循环结束"
|
Tag = "循环结束"
|
||||||
@@ -253,7 +253,7 @@ namespace TestingModule.ViewModels
|
|||||||
// ----------------------
|
// ----------------------
|
||||||
// 子程序 根节点
|
// 子程序 根节点
|
||||||
// ----------------------
|
// ----------------------
|
||||||
var subProgramRoot = new InstructionNode
|
var subProgramRoot = new InstructionNodeVM
|
||||||
{
|
{
|
||||||
Name = "子程序",
|
Name = "子程序",
|
||||||
Tag = "SubProgramRoot"
|
Tag = "SubProgramRoot"
|
||||||
@@ -262,7 +262,7 @@ namespace TestingModule.ViewModels
|
|||||||
|
|
||||||
foreach (var subProgram in SubPrograms)
|
foreach (var subProgram in SubPrograms)
|
||||||
{
|
{
|
||||||
subProgramRoot.Children.Add(new InstructionNode
|
subProgramRoot.Children.Add(new InstructionNodeVM
|
||||||
{
|
{
|
||||||
Name = subProgram.Name,
|
Name = subProgram.Name,
|
||||||
Tag = subProgram,
|
Tag = subProgram,
|
||||||
@@ -304,7 +304,7 @@ namespace TestingModule.ViewModels
|
|||||||
|
|
||||||
if (validTypes.Count > 0)
|
if (validTypes.Count > 0)
|
||||||
{
|
{
|
||||||
var assemblyNode = new InstructionNode
|
var assemblyNode = new InstructionNodeVM
|
||||||
{
|
{
|
||||||
Name = assembly.GetName().Name,
|
Name = assembly.GetName().Name,
|
||||||
Tag = assembly
|
Tag = assembly
|
||||||
@@ -320,7 +320,7 @@ namespace TestingModule.ViewModels
|
|||||||
// continue;
|
// continue;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
var typeNode = new InstructionNode
|
var typeNode = new InstructionNodeVM
|
||||||
{
|
{
|
||||||
Name = type.Name,
|
Name = type.Name,
|
||||||
Tag = type,
|
Tag = type,
|
||||||
@@ -346,7 +346,7 @@ namespace TestingModule.ViewModels
|
|||||||
var parameters = method.GetParameters();
|
var parameters = method.GetParameters();
|
||||||
var paramText = string.Join(", ", parameters.Select(p => $"{p.ParameterType.Name} {p.Name}"));
|
var paramText = string.Join(", ", parameters.Select(p => $"{p.ParameterType.Name} {p.Name}"));
|
||||||
|
|
||||||
var methodNode = new InstructionNode
|
var methodNode = new InstructionNodeVM
|
||||||
{
|
{
|
||||||
Name = $"{method.Name}({paramText})",
|
Name = $"{method.Name}({paramText})",
|
||||||
Tag = method,
|
Tag = method,
|
||||||
@@ -422,11 +422,11 @@ namespace TestingModule.ViewModels
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var newStep = new StepModel
|
var newStep = new StepVM
|
||||||
{
|
{
|
||||||
Name = method.Name,
|
Name = method.Name,
|
||||||
StepType = "方法",
|
StepType = "方法",
|
||||||
Method = new MethodModel
|
Method = new MethodVM
|
||||||
{
|
{
|
||||||
FullName = method.DeclaringType?.FullName,
|
FullName = method.DeclaringType?.FullName,
|
||||||
Name = method.Name
|
Name = method.Name
|
||||||
@@ -436,7 +436,7 @@ namespace TestingModule.ViewModels
|
|||||||
// 添加输入参数
|
// 添加输入参数
|
||||||
foreach (var param in method.GetParameters())
|
foreach (var param in method.GetParameters())
|
||||||
{
|
{
|
||||||
newStep.Method.Parameters.Add(new ParameterModel
|
newStep.Method.Parameters.Add(new ParameterVM
|
||||||
{
|
{
|
||||||
Name = param.Name!,
|
Name = param.Name!,
|
||||||
Type = param.ParameterType,
|
Type = param.ParameterType,
|
||||||
@@ -455,7 +455,7 @@ namespace TestingModule.ViewModels
|
|||||||
{
|
{
|
||||||
// 提取实际返回类型(如 Task<bool> -> bool)
|
// 提取实际返回类型(如 Task<bool> -> bool)
|
||||||
Type actualType = returnType.GetGenericArguments()[0];
|
Type actualType = returnType.GetGenericArguments()[0];
|
||||||
newStep.Method.Parameters.Add(new ParameterModel
|
newStep.Method.Parameters.Add(new ParameterVM
|
||||||
{
|
{
|
||||||
Name = "Result",
|
Name = "Result",
|
||||||
Type = actualType, // 使用实际类型
|
Type = actualType, // 使用实际类型
|
||||||
@@ -465,7 +465,7 @@ namespace TestingModule.ViewModels
|
|||||||
else if (returnType != typeof(void))
|
else if (returnType != typeof(void))
|
||||||
{
|
{
|
||||||
// 同步方法正常添加
|
// 同步方法正常添加
|
||||||
newStep.Method.Parameters.Add(new ParameterModel
|
newStep.Method.Parameters.Add(new ParameterVM
|
||||||
{
|
{
|
||||||
Name = "Result",
|
Name = "Result",
|
||||||
Type = returnType,
|
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
|
try
|
||||||
{
|
{
|
||||||
var newStep = new StepModel
|
var newStep = new StepVM
|
||||||
{
|
{
|
||||||
Name = subProgram.Name,
|
Name = subProgram.Name,
|
||||||
StepType = "子程序"
|
StepType = "子程序"
|
||||||
};
|
};
|
||||||
var jsonstr = File.ReadAllText($"{subProgram.FilePath}");
|
var jsonstr = File.ReadAllText($"{subProgram.FilePath}");
|
||||||
var tmp = JsonConvert.DeserializeObject<ProgramModel>(jsonstr);
|
var tmp = JsonConvert.DeserializeObject<ProgramVM>(jsonstr);
|
||||||
if (tmp != null)
|
if (tmp != null)
|
||||||
{
|
{
|
||||||
newStep.SubProgram = tmp;
|
newStep.SubProgram = tmp;
|
||||||
@@ -525,7 +525,7 @@ namespace TestingModule.ViewModels
|
|||||||
|
|
||||||
private void AddLoopStartStep(int insertIndex = -1)
|
private void AddLoopStartStep(int insertIndex = -1)
|
||||||
{
|
{
|
||||||
var newStep = new StepModel
|
var newStep = new StepVM
|
||||||
{
|
{
|
||||||
Name = "循环开始",
|
Name = "循环开始",
|
||||||
StepType = "循环开始",
|
StepType = "循环开始",
|
||||||
@@ -549,7 +549,7 @@ namespace TestingModule.ViewModels
|
|||||||
private void AddLoopEndStep(int insertIndex = -1)
|
private void AddLoopEndStep(int insertIndex = -1)
|
||||||
{
|
{
|
||||||
// 查找最近的未匹配循环开始
|
// 查找最近的未匹配循环开始
|
||||||
StepModel? lastUnmatchedLoopStart = null;
|
StepVM? lastUnmatchedLoopStart = null;
|
||||||
for (int i = Program.StepCollection.Count - 1; i >= 0; i--)
|
for (int i = Program.StepCollection.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (Program.StepCollection[i].StepType == "循环开始")
|
if (Program.StepCollection[i].StepType == "循环开始")
|
||||||
@@ -564,7 +564,7 @@ namespace TestingModule.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var newStep = new StepModel
|
var newStep = new StepVM
|
||||||
{
|
{
|
||||||
Name = "循环结束",
|
Name = "循环结束",
|
||||||
StepType = "循环结束",
|
StepType = "循环结束",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using UIShare.GlobalVariable;
|
using UIShare.GlobalVariable;
|
||||||
using static UIShare.UIViewModel.ParameterModel;
|
using static UIShare.UIViewModel.ParameterVM;
|
||||||
using UIShare.ViewModelBase;
|
using UIShare.ViewModelBase;
|
||||||
using Prism.Ioc;
|
using Prism.Ioc;
|
||||||
using Prism.Navigation.Regions;
|
using Prism.Navigation.Regions;
|
||||||
@@ -58,14 +58,14 @@ namespace TestingModule.ViewModels.Dialogs
|
|||||||
set => SetProperty(ref _Mode, value);
|
set => SetProperty(ref _Mode, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProgramModel _program;
|
private ProgramVM _program;
|
||||||
public ProgramModel Program
|
public ProgramVM Program
|
||||||
{
|
{
|
||||||
get => _program;
|
get => _program;
|
||||||
set => SetProperty(ref _program, value);
|
set => SetProperty(ref _program, value);
|
||||||
}
|
}
|
||||||
private ParameterModel _Parameter;
|
private ParameterVM _Parameter;
|
||||||
public ParameterModel Parameter
|
public ParameterVM Parameter
|
||||||
{
|
{
|
||||||
get => _Parameter;
|
get => _Parameter;
|
||||||
set => SetProperty(ref _Parameter, value);
|
set => SetProperty(ref _Parameter, value);
|
||||||
@@ -127,7 +127,7 @@ namespace TestingModule.ViewModels.Dialogs
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Parameter = new ParameterModel(_ScopedContext.SelectedParameter);
|
Parameter = new ParameterVM(_ScopedContext.SelectedParameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -22,15 +22,15 @@ namespace TestingModule.ViewModels
|
|||||||
// get { return _DeviceList; }
|
// get { return _DeviceList; }
|
||||||
// set { SetProperty(ref _DeviceList,value); }
|
// set { SetProperty(ref _DeviceList,value); }
|
||||||
//}
|
//}
|
||||||
private ObservableCollection<DeviceInfoModel> _DeviceInfoModel;
|
private ObservableCollection<DeviceInfoVM> _DeviceInfoModel;
|
||||||
|
|
||||||
public ObservableCollection<DeviceInfoModel> DeviceInfoModel
|
public ObservableCollection<DeviceInfoVM> DeviceInfoVM
|
||||||
{
|
{
|
||||||
get { return _DeviceInfoModel; }
|
get { return _DeviceInfoModel; }
|
||||||
set { SetProperty(ref _DeviceInfoModel, value); }
|
set { SetProperty(ref _DeviceInfoModel, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProgramModel Program
|
public ProgramVM Program
|
||||||
{
|
{
|
||||||
get => _ScopedContext.Program;
|
get => _ScopedContext.Program;
|
||||||
set
|
set
|
||||||
@@ -42,8 +42,8 @@ namespace TestingModule.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private ParameterModel _SelectedParameter;
|
private ParameterVM _SelectedParameter;
|
||||||
public ParameterModel SelectedParameter
|
public ParameterVM SelectedParameter
|
||||||
{
|
{
|
||||||
get => _SelectedParameter;
|
get => _SelectedParameter;
|
||||||
set
|
set
|
||||||
@@ -54,11 +54,11 @@ namespace TestingModule.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private DeviceInfoModel _SelectedDevice;
|
private DeviceInfoVM _SelectedDevice;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public DeviceInfoModel SelectedDevice
|
public DeviceInfoVM SelectedDevice
|
||||||
{
|
{
|
||||||
get { return _SelectedDevice; }
|
get { return _SelectedDevice; }
|
||||||
set { SetProperty(ref _SelectedDevice, value); }
|
set { SetProperty(ref _SelectedDevice, value); }
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ namespace TestingModule.ViewModels
|
|||||||
get => _ID;
|
get => _ID;
|
||||||
set => SetProperty(ref _ID, value);
|
set => SetProperty(ref _ID, value);
|
||||||
}
|
}
|
||||||
private StepModel _SelectedStep;
|
private StepVM _SelectedStep;
|
||||||
public StepModel SelectedStep
|
public StepVM SelectedStep
|
||||||
{
|
{
|
||||||
get => _SelectedStep;
|
get => _SelectedStep;
|
||||||
set => SetProperty(ref _SelectedStep, value);
|
set => SetProperty(ref _SelectedStep, value);
|
||||||
}
|
}
|
||||||
public ProgramModel Program
|
public ProgramVM Program
|
||||||
{
|
{
|
||||||
get => _ScopedContext.Program;
|
get => _ScopedContext.Program;
|
||||||
set
|
set
|
||||||
@@ -193,7 +193,7 @@ namespace TestingModule.ViewModels
|
|||||||
{
|
{
|
||||||
if (_ScopedContext.SelectedStep == null) return;
|
if (_ScopedContext.SelectedStep == null) return;
|
||||||
ID = _ScopedContext.SelectedStep.ID;
|
ID = _ScopedContext.SelectedStep.ID;
|
||||||
SelectedStep = new StepModel(_ScopedContext.SelectedStep);
|
SelectedStep = new StepVM(_ScopedContext.SelectedStep);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -44,14 +44,14 @@ namespace TestingModule.ViewModels
|
|||||||
get { return _selectedTabHeader; }
|
get { return _selectedTabHeader; }
|
||||||
set { SetProperty(ref _selectedTabHeader, value); }
|
set { SetProperty(ref _selectedTabHeader, value); }
|
||||||
}
|
}
|
||||||
private List<StepModel> _SelectedItems;
|
private List<StepVM> _SelectedItems;
|
||||||
public List<StepModel> SelectedItems
|
public List<StepVM> SelectedItems
|
||||||
{
|
{
|
||||||
get { return _SelectedItems; }
|
get { return _SelectedItems; }
|
||||||
set { SetProperty(ref _SelectedItems, value); }
|
set { SetProperty(ref _SelectedItems, value); }
|
||||||
}
|
}
|
||||||
private StepModel _SelectedStep;
|
private StepVM _SelectedStep;
|
||||||
public StepModel SelectedStep
|
public StepVM SelectedStep
|
||||||
{
|
{
|
||||||
get => _SelectedStep;
|
get => _SelectedStep;
|
||||||
set
|
set
|
||||||
@@ -62,7 +62,7 @@ namespace TestingModule.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public ProgramModel Program
|
public ProgramVM Program
|
||||||
{
|
{
|
||||||
get => _ScopedContext.Program;
|
get => _ScopedContext.Program;
|
||||||
set
|
set
|
||||||
@@ -77,7 +77,7 @@ namespace TestingModule.ViewModels
|
|||||||
ScopedContext _ScopedContext { get; set; }
|
ScopedContext _ScopedContext { get; set; }
|
||||||
private readonly SystemConfig _systemConfig;
|
private readonly SystemConfig _systemConfig;
|
||||||
private readonly GlobalInfo _globalInfo;
|
private readonly GlobalInfo _globalInfo;
|
||||||
private List<StepModel> tmpCopyList = new List<StepModel>();
|
private List<StepVM> tmpCopyList = new List<StepVM>();
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -115,7 +115,7 @@ namespace TestingModule.ViewModels
|
|||||||
var selectedList = parameter as IList;
|
var selectedList = parameter as IList;
|
||||||
if (selectedList != null)
|
if (selectedList != null)
|
||||||
{
|
{
|
||||||
SelectedItems = selectedList.Cast<StepModel>().ToList();
|
SelectedItems = selectedList.Cast<StepVM>().ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ namespace TestingModule.ViewModels
|
|||||||
foreach (var item in tmpCopyList)
|
foreach (var item in tmpCopyList)
|
||||||
{
|
{
|
||||||
// 创建新副本,避免引用同一个对象,并赋予新 ID
|
// 创建新副本,避免引用同一个对象,并赋予新 ID
|
||||||
var newStep = new StepModel(item) { ID = Guid.NewGuid() };
|
var newStep = new StepVM(item) { ID = Guid.NewGuid() };
|
||||||
Program.StepCollection.Insert(insertIndex, newStep);
|
Program.StepCollection.Insert(insertIndex, newStep);
|
||||||
insertIndex++; // 递增索引,保证粘贴的多项顺序一致
|
insertIndex++; // 递增索引,保证粘贴的多项顺序一致
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ namespace TestingModule.ViewModels
|
|||||||
|
|
||||||
foreach (var item in tmpCopyList)
|
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);
|
Program.ErrorStepCollection.Insert(insertIndex, newStep);
|
||||||
insertIndex++;
|
insertIndex++;
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ namespace TestingModule.ViewModels
|
|||||||
#region 辅助方法
|
#region 辅助方法
|
||||||
private void StepCollection_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
private void StepCollection_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var collection = sender as ObservableCollection<StepModel>;
|
var collection = sender as ObservableCollection<StepVM>;
|
||||||
// Add/Move/Remove 都会触发,这里判断具体情形
|
// Add/Move/Remove 都会触发,这里判断具体情形
|
||||||
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||
|
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add ||
|
||||||
e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move||
|
e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move||
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
<TreeView Grid.Row="1"
|
<TreeView Grid.Row="1"
|
||||||
ItemsSource="{Binding InstructionTree}">
|
ItemsSource="{Binding InstructionTree}">
|
||||||
<TreeView.Resources>
|
<TreeView.Resources>
|
||||||
<HierarchicalDataTemplate DataType="{x:Type model:InstructionNode}"
|
<HierarchicalDataTemplate DataType="{x:Type model:InstructionNodeVM}"
|
||||||
ItemsSource="{Binding Children}">
|
ItemsSource="{Binding Children}">
|
||||||
<TextBlock Text="{Binding Name}" />
|
<TextBlock Text="{Binding Name}" />
|
||||||
</HierarchicalDataTemplate>
|
</HierarchicalDataTemplate>
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
<TabItem Header="设备">
|
<TabItem Header="设备">
|
||||||
<DataGrid Padding="10"
|
<DataGrid Padding="10"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
ItemsSource="{Binding DeviceInfoModel}"
|
ItemsSource="{Binding DeviceInfoVM}"
|
||||||
AutoGenerateColumns="False"
|
AutoGenerateColumns="False"
|
||||||
CanUserAddRows="False"
|
CanUserAddRows="False"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace UIShare.Converters
|
|||||||
return allParameters;
|
return allParameters;
|
||||||
|
|
||||||
// 过滤出类型匹配的参数
|
// 过滤出类型匹配的参数
|
||||||
return allParameters.Cast<ParameterModel>()
|
return allParameters.Cast<ParameterVM>()
|
||||||
.Where(p => IsTypeMatch(currentParamType, p.Type))
|
.Where(p => IsTypeMatch(currentParamType, p.Type))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using static UIShare.UIViewModel.ParameterModel;
|
using static UIShare.UIViewModel.ParameterVM;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using static UIShare.UIViewModel.ParameterModel;
|
using static UIShare.UIViewModel.ParameterVM;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace UIShare.GlobalVariable
|
|||||||
public class ScopedContext
|
public class ScopedContext
|
||||||
{
|
{
|
||||||
private static readonly Random _randomSeed = new Random();
|
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 SelectedStepList { get; set; } = "主程序";
|
||||||
public string CurrentFilePath { get; set; }
|
public string CurrentFilePath { get; set; }
|
||||||
public bool? IsStop { get; set; }
|
public bool? IsStop { get; set; }
|
||||||
@@ -26,8 +26,8 @@ namespace UIShare.GlobalVariable
|
|||||||
public bool IsTerminate { get; set; } = false;
|
public bool IsTerminate { get; set; } = false;
|
||||||
public ObservableCollection<Assembly> Assemblies { get; set; } = new();
|
public ObservableCollection<Assembly> Assemblies { get; set; } = new();
|
||||||
public PackIconKind RunIcon { get; set; } = PackIconKind.Play;
|
public PackIconKind RunIcon { get; set; } = PackIconKind.Play;
|
||||||
public StepModel SelectedStep { get; set; }
|
public StepVM SelectedStep { get; set; }
|
||||||
public ParameterModel SelectedParameter { get; set; }
|
public ParameterVM SelectedParameter { get; set; }
|
||||||
|
|
||||||
public List<IBaseInterface> DeviceList { get; set; } = new();
|
public List<IBaseInterface> DeviceList { get; set; } = new();
|
||||||
// 【新增测试属性】:每个实例被 new 出来时独一无二的随机身份
|
// 【新增测试属性】:每个实例被 new 出来时独一无二的随机身份
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UIShare.GlobalVariable;
|
using UIShare.GlobalVariable;
|
||||||
using static UIShare.UIViewModel.ParameterModel;
|
using static UIShare.UIViewModel.ParameterVM;
|
||||||
|
|
||||||
|
|
||||||
namespace UIShare
|
namespace UIShare
|
||||||
@@ -26,7 +26,7 @@ namespace UIShare
|
|||||||
private IContainerProvider containerProvider;
|
private IContainerProvider containerProvider;
|
||||||
private IEventAggregator _eventAggregator;
|
private IEventAggregator _eventAggregator;
|
||||||
|
|
||||||
private readonly Dictionary<Guid, ParameterModel> tmpParameters = [];
|
private readonly Dictionary<Guid, ParameterVM> tmpParameters = [];
|
||||||
|
|
||||||
private readonly Stopwatch stepStopwatch = new();
|
private readonly Stopwatch stepStopwatch = new();
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ namespace UIShare
|
|||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
//_devices = containerProvider.Resolve<Devices>();
|
//_devices = containerProvider.Resolve<Devices>();
|
||||||
}
|
}
|
||||||
public async Task<bool> ExecuteErrorSteps(ProgramModel program, int depth = 0, CancellationToken cancellationToken = default)
|
public async Task<bool> ExecuteErrorSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
bool stepSuccess = false;
|
bool stepSuccess = false;
|
||||||
@@ -211,7 +211,7 @@ namespace UIShare
|
|||||||
|
|
||||||
return loopStack.Count == 0 && stepSuccess;
|
return loopStack.Count == 0 && stepSuccess;
|
||||||
}
|
}
|
||||||
public async Task<bool> ExecuteSteps(ProgramModel program, int depth = 0, CancellationToken cancellationToken = default)
|
public async Task<bool> ExecuteSteps(ProgramVM program, int depth = 0, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
bool stepSuccess = false;
|
bool stepSuccess = false;
|
||||||
@@ -388,7 +388,7 @@ namespace UIShare
|
|||||||
return loopStack.Count == 0 && stepSuccess;
|
return loopStack.Count == 0 && stepSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ExecuteMethodStep(StepModel step, Dictionary<Guid, ParameterModel> parameters, int depth, CancellationToken cancellationToken = default)
|
public async Task ExecuteMethodStep(StepVM step, Dictionary<Guid, ParameterVM> parameters, int depth, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -417,7 +417,7 @@ namespace UIShare
|
|||||||
// 3. 准备参数
|
// 3. 准备参数
|
||||||
var inputParams = new List<object?>();
|
var inputParams = new List<object?>();
|
||||||
var paramTypes = new List<Type>();
|
var paramTypes = new List<Type>();
|
||||||
ParameterModel? outputParam = null;
|
ParameterVM? outputParam = null;
|
||||||
foreach (var param in step.Method!.Parameters)
|
foreach (var param in step.Method!.Parameters)
|
||||||
{
|
{
|
||||||
if (param.Category == ParameterCategory.Input)
|
if (param.Category == ParameterCategory.Input)
|
||||||
@@ -656,7 +656,7 @@ namespace UIShare
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetAllStepStatus(ObservableCollection<StepModel> StepCollection)
|
public void ResetAllStepStatus(ObservableCollection<StepVM> StepCollection)
|
||||||
{
|
{
|
||||||
foreach (var step in 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)
|
if (stepResult && paraResult)
|
||||||
{
|
{
|
||||||
@@ -721,7 +721,7 @@ namespace UIShare
|
|||||||
public int LoopCount { get; set; }
|
public int LoopCount { get; set; }
|
||||||
public int CurrentLoop { get; set; }
|
public int CurrentLoop { get; set; }
|
||||||
public int StartIndex { get; set; }
|
public int StartIndex { get; set; }
|
||||||
public StepModel? LoopStartStep { get; set; }
|
public StepVM? LoopStartStep { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ namespace UIShare.GlobalVariable
|
|||||||
public string DefaultProgramFilePath { get; set; } = "";
|
public string DefaultProgramFilePath { get; set; } = "";
|
||||||
public string DefaultBLFFilePath { get; set; } = "";
|
public string DefaultBLFFilePath { get; set; } = "";
|
||||||
public string DefaultDBCFilePath { get; set; } = "";
|
public string DefaultDBCFilePath { get; set; } = "";
|
||||||
public ObservableCollection<DeviceInfoModel> DeviceList = new();
|
public ObservableCollection<DeviceInfoVM> DeviceList = new();
|
||||||
// public ObservableCollection<DeviceInfoModel> DeviceList { get; set; } = new()
|
// public ObservableCollection<DeviceInfoVM> DeviceList { get; set; } = new()
|
||||||
//{
|
//{
|
||||||
// new DeviceInfoModel
|
// new DeviceInfoVM
|
||||||
// {
|
// {
|
||||||
// DeviceName = "IT7800E",
|
// DeviceName = "IT7800E",
|
||||||
// DeviceType = "IT7800E",
|
// DeviceType = "IT7800E",
|
||||||
@@ -39,7 +39,7 @@ namespace UIShare.GlobalVariable
|
|||||||
// IsConnected = false
|
// IsConnected = false
|
||||||
// },
|
// },
|
||||||
|
|
||||||
// new DeviceInfoModel
|
// new DeviceInfoVM
|
||||||
// {
|
// {
|
||||||
// DeviceName = "N36200",
|
// DeviceName = "N36200",
|
||||||
// DeviceType = "N36200",
|
// DeviceType = "N36200",
|
||||||
@@ -49,7 +49,7 @@ namespace UIShare.GlobalVariable
|
|||||||
// IsConnected = false
|
// IsConnected = false
|
||||||
// },
|
// },
|
||||||
|
|
||||||
// new DeviceInfoModel
|
// new DeviceInfoVM
|
||||||
// {
|
// {
|
||||||
// DeviceName = "N36600",
|
// DeviceName = "N36600",
|
||||||
// DeviceType = "N36600",
|
// DeviceType = "N36600",
|
||||||
@@ -59,7 +59,7 @@ namespace UIShare.GlobalVariable
|
|||||||
// IsConnected = false
|
// IsConnected = false
|
||||||
// },
|
// },
|
||||||
|
|
||||||
// new DeviceInfoModel
|
// new DeviceInfoVM
|
||||||
// {
|
// {
|
||||||
// DeviceName = "N69200",
|
// DeviceName = "N69200",
|
||||||
// DeviceType = "N69200",
|
// DeviceType = "N69200",
|
||||||
@@ -69,7 +69,7 @@ namespace UIShare.GlobalVariable
|
|||||||
// IsConnected = false
|
// IsConnected = false
|
||||||
// },
|
// },
|
||||||
|
|
||||||
// new DeviceInfoModel
|
// new DeviceInfoVM
|
||||||
// {
|
// {
|
||||||
// DeviceName = "SDS2000X_HD",
|
// DeviceName = "SDS2000X_HD",
|
||||||
// DeviceType = "SDS2000X_HD",
|
// DeviceType = "SDS2000X_HD",
|
||||||
@@ -79,7 +79,7 @@ namespace UIShare.GlobalVariable
|
|||||||
// IsConnected = false
|
// IsConnected = false
|
||||||
// },
|
// },
|
||||||
|
|
||||||
// new DeviceInfoModel
|
// new DeviceInfoVM
|
||||||
// {
|
// {
|
||||||
// DeviceName = "SPAW7000",
|
// DeviceName = "SPAW7000",
|
||||||
// DeviceType = "SPAW7000",
|
// DeviceType = "SPAW7000",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace UIShare.UIViewModel
|
namespace UIShare.UIViewModel
|
||||||
{
|
{
|
||||||
public class CanMessageShowModel : BindableBase
|
public class CanMessageShowVM : BindableBase
|
||||||
{
|
{
|
||||||
// 字段声明
|
// 字段声明
|
||||||
private byte _通道;
|
private byte _通道;
|
||||||
@@ -2,17 +2,17 @@ using Prism.Mvvm;
|
|||||||
|
|
||||||
namespace UIShare.UIViewModel
|
namespace UIShare.UIViewModel
|
||||||
{
|
{
|
||||||
public class CustomPanelItem : BindableBase
|
public class CustomPanelItemVM : BindableBase
|
||||||
{
|
{
|
||||||
private string _name;
|
private string _name;
|
||||||
private string _pointY;
|
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get => _name;
|
get => _name;
|
||||||
set => SetProperty(ref _name, value);
|
set => SetProperty(ref _name, value);
|
||||||
}
|
}
|
||||||
|
private string _pointY;
|
||||||
public string PointY
|
public string PointY
|
||||||
{
|
{
|
||||||
get => _pointY;
|
get => _pointY;
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace UIShare.UIViewModel
|
namespace UIShare.UIViewModel
|
||||||
{
|
{
|
||||||
public class DeviceInfoModel : BindableBase
|
public class DeviceInfoVM : BindableBase
|
||||||
{
|
{
|
||||||
private string _deviceName;
|
private string _deviceName;
|
||||||
public string DeviceName
|
public string DeviceName
|
||||||
@@ -51,16 +51,16 @@ namespace UIShare.UIViewModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>TCP 连接参数(首次访问时自动初始化,便于 XAML 直接绑定)。</summary>
|
/// <summary>TCP 连接参数(首次访问时自动初始化,便于 XAML 直接绑定)。</summary>
|
||||||
private TcpConnectionConfig _tcpConfig = new();
|
private TcpConfigVM _tcpConfig = new();
|
||||||
public TcpConnectionConfig TcpConfig
|
public TcpConfigVM TcpConfig
|
||||||
{
|
{
|
||||||
get => _tcpConfig;
|
get => _tcpConfig;
|
||||||
set => SetProperty(ref _tcpConfig, value);
|
set => SetProperty(ref _tcpConfig, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>串口连接参数(首次访问时自动初始化,便于 XAML 直接绑定)。</summary>
|
/// <summary>串口连接参数(首次访问时自动初始化,便于 XAML 直接绑定)。</summary>
|
||||||
private SerialPortConnectionConfig _serialPortConfig = new();
|
private SerialPortConfigVM _serialPortConfig = new();
|
||||||
public SerialPortConnectionConfig SerialPortConfig
|
public SerialPortConfigVM SerialPortConfig
|
||||||
{
|
{
|
||||||
get => _serialPortConfig;
|
get => _serialPortConfig;
|
||||||
set => SetProperty(ref _serialPortConfig, value);
|
set => SetProperty(ref _serialPortConfig, value);
|
||||||
@@ -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<InstructionNode> Children { get; set; } = new();
|
|
||||||
public object Tag { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
36
UIShare/UIViewModel/InstructionNodeVM.cs
Normal file
36
UIShare/UIViewModel/InstructionNodeVM.cs
Normal file
@@ -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<InstructionNodeVM> _children = new();
|
||||||
|
public ObservableCollection<InstructionNodeVM> Children
|
||||||
|
{
|
||||||
|
get => _children;
|
||||||
|
set => SetProperty(ref _children, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private object? _tag;
|
||||||
|
public object? Tag
|
||||||
|
{
|
||||||
|
get => _tag;
|
||||||
|
set => SetProperty(ref _tag, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,17 +7,17 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace UIShare.UIViewModel
|
namespace UIShare.UIViewModel
|
||||||
{
|
{
|
||||||
public class MethodModel
|
public class MethodVM
|
||||||
{
|
{
|
||||||
|
|
||||||
#region 构造函数
|
#region 构造函数
|
||||||
|
|
||||||
public MethodModel()
|
public MethodVM()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodModel(MethodModel source)
|
public MethodVM(MethodVM source)
|
||||||
{
|
{
|
||||||
if (source == null) return;
|
if (source == null) return;
|
||||||
|
|
||||||
@@ -25,8 +25,8 @@ namespace UIShare.UIViewModel
|
|||||||
FullName = source.FullName;
|
FullName = source.FullName;
|
||||||
|
|
||||||
// 深拷贝参数
|
// 深拷贝参数
|
||||||
Parameters = new ObservableCollection<ParameterModel>(
|
Parameters = new ObservableCollection<ParameterVM>(
|
||||||
source.Parameters.Select(p => new ParameterModel(p)));
|
source.Parameters.Select(p => new ParameterVM(p)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -35,6 +35,6 @@ namespace UIShare.UIViewModel
|
|||||||
|
|
||||||
public string? FullName { get; set; }
|
public string? FullName { get; set; }
|
||||||
|
|
||||||
public ObservableCollection<ParameterModel> Parameters { get; set; } = [];
|
public ObservableCollection<ParameterVM> Parameters { get; set; } = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,16 +5,16 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace UIShare.UIViewModel
|
namespace UIShare.UIViewModel
|
||||||
{
|
{
|
||||||
public class ParameterModel : BindableBase
|
public class ParameterVM : BindableBase
|
||||||
{
|
{
|
||||||
#region 构造函数
|
#region 构造函数
|
||||||
|
|
||||||
public ParameterModel()
|
public ParameterVM()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParameterModel(ParameterModel source)
|
public ParameterVM(ParameterVM source)
|
||||||
{
|
{
|
||||||
if (source == null) return;
|
if (source == null) return;
|
||||||
|
|
||||||
@@ -139,10 +139,10 @@ namespace UIShare.UIViewModel
|
|||||||
Temp
|
Temp
|
||||||
}
|
}
|
||||||
|
|
||||||
public object? GetActualValue(Dictionary<Guid, ParameterModel> paraList)
|
public object? GetActualValue(Dictionary<Guid, ParameterVM> paraList)
|
||||||
{
|
{
|
||||||
HashSet<Guid> visitedIds = new HashSet<Guid>();
|
HashSet<Guid> visitedIds = new HashSet<Guid>();
|
||||||
ParameterModel current = this;
|
ParameterVM current = this;
|
||||||
|
|
||||||
while (current != null)
|
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)
|
if (next == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -184,10 +184,10 @@ namespace UIShare.UIViewModel
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParameterModel? GetCurrentParameter(Dictionary<Guid, ParameterModel> paraList)
|
public ParameterVM? GetCurrentParameter(Dictionary<Guid, ParameterVM> paraList)
|
||||||
{
|
{
|
||||||
HashSet<Guid> visitedIds = new HashSet<Guid>();
|
HashSet<Guid> visitedIds = new HashSet<Guid>();
|
||||||
ParameterModel current = this;
|
ParameterVM current = this;
|
||||||
|
|
||||||
while (current != null)
|
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)
|
if (next == null)
|
||||||
{
|
{
|
||||||
return null;
|
return 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<StepModel>(source.StepCollection.Select(p => new StepModel(p)));
|
|
||||||
ErrorStepCollection = new ObservableCollection<StepModel>(source.ErrorStepCollection.Select(p => new StepModel(p)));
|
|
||||||
Parameters = new ObservableCollection<ParameterModel>(source.Parameters.Select(p => new ParameterModel(p)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
public Guid ID { get; set; } = Guid.NewGuid();
|
|
||||||
|
|
||||||
private ObservableCollection<StepModel> _stepCollection = new ObservableCollection<StepModel>();
|
|
||||||
public ObservableCollection<StepModel> StepCollection
|
|
||||||
{
|
|
||||||
get => _stepCollection;
|
|
||||||
set => SetProperty(ref _stepCollection, value);
|
|
||||||
}
|
|
||||||
private ObservableCollection<StepModel> _errorStepCollection = new ObservableCollection<StepModel>();
|
|
||||||
public ObservableCollection<StepModel> ErrorStepCollection
|
|
||||||
{
|
|
||||||
get => _errorStepCollection;
|
|
||||||
set => SetProperty(ref _errorStepCollection, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObservableCollection<ParameterModel> _parameters = new ObservableCollection<ParameterModel>();
|
|
||||||
public ObservableCollection<ParameterModel> Parameters
|
|
||||||
{
|
|
||||||
get => _parameters;
|
|
||||||
set => SetProperty(ref _parameters, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
51
UIShare/UIViewModel/ProgramVM.cs
Normal file
51
UIShare/UIViewModel/ProgramVM.cs
Normal file
@@ -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<StepVM>(source.StepCollection.Select(p => new StepVM(p)));
|
||||||
|
ErrorStepCollection = new ObservableCollection<StepVM>(source.ErrorStepCollection.Select(p => new StepVM(p)));
|
||||||
|
Parameters = new ObservableCollection<ParameterVM>(source.Parameters.Select(p => new ParameterVM(p)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public Guid ID { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
|
private ObservableCollection<StepVM> _stepCollection = new ObservableCollection<StepVM>();
|
||||||
|
public ObservableCollection<StepVM> StepCollection
|
||||||
|
{
|
||||||
|
get => _stepCollection;
|
||||||
|
set => SetProperty(ref _stepCollection, value);
|
||||||
|
}
|
||||||
|
private ObservableCollection<StepVM> _errorStepCollection = new ObservableCollection<StepVM>();
|
||||||
|
public ObservableCollection<StepVM> ErrorStepCollection
|
||||||
|
{
|
||||||
|
get => _errorStepCollection;
|
||||||
|
set => SetProperty(ref _errorStepCollection, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObservableCollection<ParameterVM> _parameters = new ObservableCollection<ParameterVM>();
|
||||||
|
public ObservableCollection<ParameterVM> Parameters
|
||||||
|
{
|
||||||
|
get => _parameters;
|
||||||
|
set => SetProperty(ref _parameters, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
namespace UIShare.UIViewModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// TCP 连接配置(与 DeviceCommand.Base.Tcp 保持字段一致)。
|
|
||||||
/// </summary>
|
|
||||||
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() { }
|
|
||||||
|
|
||||||
/// <summary>拷贝构造,用于对话框编辑副本。</summary>
|
|
||||||
public TcpConnectionConfig(TcpConnectionConfig? src)
|
|
||||||
{
|
|
||||||
if (src == null) return;
|
|
||||||
IPAddress = src.IPAddress;
|
|
||||||
Port = src.Port;
|
|
||||||
SendTimeout = src.SendTimeout;
|
|
||||||
ReceiveTimeout = src.ReceiveTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>把字段拷回目标对象(保存时用)。</summary>
|
|
||||||
public void CopyTo(TcpConnectionConfig? dst)
|
|
||||||
{
|
|
||||||
if (dst == null) return;
|
|
||||||
dst.IPAddress = IPAddress;
|
|
||||||
dst.Port = Port;
|
|
||||||
dst.SendTimeout = SendTimeout;
|
|
||||||
dst.ReceiveTimeout = ReceiveTimeout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 串口连接配置(与 DeviceCommand.Base.Serial_Port 保持字段一致)。
|
/// 串口连接配置(与 DeviceCommand.Base.Serial_Port 保持字段一致)。
|
||||||
/// StopBits / Parity 用字符串保存,避免 UIShare 引入 System.IO.Ports 依赖。
|
/// StopBits / Parity 用字符串保存,避免 UIShare 引入 System.IO.Ports 依赖。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SerialPortConnectionConfig : BindableBase
|
public class SerialPortConfigVM : BindableBase
|
||||||
{
|
{
|
||||||
private string _portName = "COM1";
|
private string _portName = "COM1";
|
||||||
public string PortName
|
public string PortName
|
||||||
@@ -115,9 +63,9 @@ namespace UIShare.UIViewModel
|
|||||||
set => SetProperty(ref _writeTimeout, value);
|
set => SetProperty(ref _writeTimeout, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SerialPortConnectionConfig() { }
|
public SerialPortConfigVM() { }
|
||||||
|
|
||||||
public SerialPortConnectionConfig(SerialPortConnectionConfig? src)
|
public SerialPortConfigVM(SerialPortConfigVM? src)
|
||||||
{
|
{
|
||||||
if (src == null) return;
|
if (src == null) return;
|
||||||
PortName = src.PortName;
|
PortName = src.PortName;
|
||||||
@@ -129,7 +77,7 @@ namespace UIShare.UIViewModel
|
|||||||
WriteTimeout = src.WriteTimeout;
|
WriteTimeout = src.WriteTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyTo(SerialPortConnectionConfig? dst)
|
public void CopyTo(SerialPortConfigVM? dst)
|
||||||
{
|
{
|
||||||
if (dst == null) return;
|
if (dst == null) return;
|
||||||
dst.PortName = PortName;
|
dst.PortName = PortName;
|
||||||
@@ -4,13 +4,13 @@ using System;
|
|||||||
|
|
||||||
namespace UIShare.UIViewModel
|
namespace UIShare.UIViewModel
|
||||||
{
|
{
|
||||||
public class StepModel : BindableBase
|
public class StepVM : BindableBase
|
||||||
{
|
{
|
||||||
#region 构造函数
|
#region 构造函数
|
||||||
|
|
||||||
public StepModel() { }
|
public StepVM() { }
|
||||||
|
|
||||||
public StepModel(StepModel source)
|
public StepVM(StepVM source)
|
||||||
{
|
{
|
||||||
if (source == null) return;
|
if (source == null) return;
|
||||||
|
|
||||||
@@ -29,11 +29,11 @@ namespace UIShare.UIViewModel
|
|||||||
|
|
||||||
if (source.Method != null)
|
if (source.Method != null)
|
||||||
{
|
{
|
||||||
Method = new MethodModel(source.Method);
|
Method = new MethodVM(source.Method);
|
||||||
}
|
}
|
||||||
if (source.SubProgram != null)
|
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);
|
set => SetProperty(ref _stepType, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodModel? _method;
|
private MethodVM? _method;
|
||||||
|
|
||||||
public MethodModel? Method
|
public MethodVM? Method
|
||||||
{
|
{
|
||||||
get => _method;
|
get => _method;
|
||||||
set => SetProperty(ref _method, value);
|
set => SetProperty(ref _method, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProgramModel? _subProgram;
|
private ProgramVM? _subProgram;
|
||||||
|
|
||||||
public ProgramModel? SubProgram
|
public ProgramVM? SubProgram
|
||||||
{
|
{
|
||||||
get => _subProgram;
|
get => _subProgram;
|
||||||
set => SetProperty(ref _subProgram, value);
|
set => SetProperty(ref _subProgram, value);
|
||||||
@@ -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; } = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
28
UIShare/UIViewModel/SubProgramItemVM.cs
Normal file
28
UIShare/UIViewModel/SubProgramItemVM.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
62
UIShare/UIViewModel/TcpConfigVM.cs
Normal file
62
UIShare/UIViewModel/TcpConfigVM.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Prism.Mvvm;
|
||||||
|
|
||||||
|
namespace UIShare.UIViewModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// TCP 连接配置(与 DeviceCommand.Base.Tcp 保持字段一致)。
|
||||||
|
/// </summary>
|
||||||
|
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() { }
|
||||||
|
|
||||||
|
/// <summary>拷贝构造,用于对话框编辑副本。</summary>
|
||||||
|
public TcpConfigVM(TcpConfigVM? src)
|
||||||
|
{
|
||||||
|
if (src == null) return;
|
||||||
|
IPAddress = src.IPAddress;
|
||||||
|
Port = src.Port;
|
||||||
|
SendTimeout = src.SendTimeout;
|
||||||
|
ReceiveTimeout = src.ReceiveTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>把字段拷回目标对象(保存时用)。</summary>
|
||||||
|
public void CopyTo(TcpConfigVM? dst)
|
||||||
|
{
|
||||||
|
if (dst == null) return;
|
||||||
|
dst.IPAddress = IPAddress;
|
||||||
|
dst.Port = Port;
|
||||||
|
dst.SendTimeout = SendTimeout;
|
||||||
|
dst.ReceiveTimeout = ReceiveTimeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user