automapper框架优化
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
namespace UIShare.UIViewModel
|
||||
{
|
||||
public class CanMessageShowModel : BindableBase
|
||||
public class CanMessageShowVM : BindableBase
|
||||
{
|
||||
// 字段声明
|
||||
private byte _通道;
|
||||
@@ -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;
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/// <summary>TCP 连接参数(首次访问时自动初始化,便于 XAML 直接绑定)。</summary>
|
||||
private TcpConnectionConfig _tcpConfig = new();
|
||||
public TcpConnectionConfig TcpConfig
|
||||
private TcpConfigVM _tcpConfig = new();
|
||||
public TcpConfigVM TcpConfig
|
||||
{
|
||||
get => _tcpConfig;
|
||||
set => SetProperty(ref _tcpConfig, value);
|
||||
}
|
||||
|
||||
/// <summary>串口连接参数(首次访问时自动初始化,便于 XAML 直接绑定)。</summary>
|
||||
private SerialPortConnectionConfig _serialPortConfig = new();
|
||||
public SerialPortConnectionConfig SerialPortConfig
|
||||
private SerialPortConfigVM _serialPortConfig = new();
|
||||
public SerialPortConfigVM SerialPortConfig
|
||||
{
|
||||
get => _serialPortConfig;
|
||||
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
|
||||
{
|
||||
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<ParameterModel>(
|
||||
source.Parameters.Select(p => new ParameterModel(p)));
|
||||
Parameters = new ObservableCollection<ParameterVM>(
|
||||
source.Parameters.Select(p => new ParameterVM(p)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -35,6 +35,6 @@ namespace UIShare.UIViewModel
|
||||
|
||||
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
|
||||
{
|
||||
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<Guid, ParameterModel> paraList)
|
||||
public object? GetActualValue(Dictionary<Guid, ParameterVM> paraList)
|
||||
{
|
||||
HashSet<Guid> visitedIds = new HashSet<Guid>();
|
||||
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<Guid, ParameterModel> paraList)
|
||||
public ParameterVM? GetCurrentParameter(Dictionary<Guid, ParameterVM> paraList)
|
||||
{
|
||||
HashSet<Guid> visitedIds = new HashSet<Guid>();
|
||||
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;
|
||||
@@ -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
|
||||
{
|
||||
/// <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>
|
||||
/// 串口连接配置(与 DeviceCommand.Base.Serial_Port 保持字段一致)。
|
||||
/// StopBits / Parity 用字符串保存,避免 UIShare 引入 System.IO.Ports 依赖。
|
||||
/// </summary>
|
||||
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;
|
||||
@@ -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);
|
||||
@@ -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