1 feat: 添加变量导入模板配置和工厂模式实现
2
3 -
在AppSettings中添加VariableImportTemplate配置项,用于设置变量导入的默认参数(IsActive、PollingIn
terval、IsHistoryEnabled、HistoryDeadband)
4 - 修改AppSettings.Load()方法,优化配置加载逻辑
5 -
实现IVariableItemViewModelFactory和VariableItemViewModelFactory,使用工厂模式创建VariableItemVie
wModel实例
6 - 在ImportOpcUaDialogViewModel中使用工厂创建VariableItemViewModel实例,以应用默认配置
7 -
在SettingViewModel和SettingView中添加变量导入设置界面和相关属性(VariablePollingInterval、Variab
leIsActive、VariableIsHistoryEnabled、VariableHistoryDeadband)
8 - 移除VariableItemViewModel构造函数中的轮询间隔默认值设置,改由工厂模式设置
9 - 优化SplashViewModel中配置加载逻辑
10 - 移除MainView.xaml.cs中已注释的代码
11 - 调整VariableTableView.xaml的UI布局和菜单结构
12 - 注册IVariableItemViewModelFactory服务
这些修改主要实现了几个关键功能:
1. 引入了工厂模式来创建VariableItemViewModel实例,确保所有新创建的变量项都应用默认配置
2. 添加了变量导入模板设置,用户可以在设置界面自定义导入变量的默认属性
3. 对相关UI进行了调整和优化
This commit is contained in:
@@ -3,10 +3,15 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace DMS.Application.Configurations
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigJsonFileName);
|
||||
|
||||
private const string ConfigJsonFileName = "dms_config.json";
|
||||
|
||||
|
||||
public class Database
|
||||
{
|
||||
public string DbType { get; set; } = "MySql";
|
||||
@@ -16,37 +21,47 @@ namespace DMS.Application.Configurations
|
||||
public string Password { get; set; } = "Pgw15221236646";
|
||||
public string DbName { get; set; } = "dms_test";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Database Db { get; set; } = new Database();
|
||||
|
||||
public Variable VariableImportTemplate = new Variable()
|
||||
{
|
||||
IsActive = true,
|
||||
PollingInterval = 30000,
|
||||
IsHistoryEnabled = true,
|
||||
HistoryDeadband = 0
|
||||
};
|
||||
|
||||
public string Theme { get; set; } = "跟随系统";
|
||||
public bool EnableS7Service { get; set; } = true;
|
||||
public bool EnableMqttService { get; set; } = true;
|
||||
public bool EnableOpcUaService { get; set; } = true;
|
||||
public bool MinimizeToTrayOnClose { get; set; } = true;
|
||||
public List<MenuBean> Menus { get; set; } = new List<MenuBean>();
|
||||
|
||||
public int DefaultPollingInterval { get; set; } = 30000; // 默认轮询间隔30秒
|
||||
|
||||
private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigJsonFileName);
|
||||
|
||||
private const string ConfigJsonFileName = "dms_config.json";
|
||||
|
||||
public AppSettings? Load()
|
||||
public void Load()
|
||||
{
|
||||
if (File.Exists(SettingsFilePath))
|
||||
{
|
||||
string json = File.ReadAllText(SettingsFilePath);
|
||||
AppSettings? appSettings = JsonConvert.DeserializeObject<AppSettings>(json);
|
||||
return appSettings ?? throw new InvalidOperationException("加载配置文件出现了错误。");
|
||||
if (appSettings != null)
|
||||
{
|
||||
this.Db= appSettings.Db;
|
||||
this.VariableImportTemplate = appSettings.VariableImportTemplate;
|
||||
this.Theme=appSettings.Theme;
|
||||
this.MinimizeToTrayOnClose=appSettings.MinimizeToTrayOnClose;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("加载配置文件出现了错误。");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
File.WriteAllText(SettingsFilePath, json);
|
||||
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
File.WriteAllText(SettingsFilePath, json);
|
||||
}
|
||||
|
||||
public string ToConnectionString()
|
||||
|
||||
Reference in New Issue
Block a user