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进行了调整和优化
73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using DMS.Core.Models;
|
|
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";
|
|
public string Server { get; set; } = "127.0.0.1";
|
|
public int Port { get; set; } = 3306;
|
|
public string UserId { get; set; } = "root";
|
|
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 MinimizeToTrayOnClose { get; set; } = true;
|
|
|
|
|
|
|
|
public void Load()
|
|
{
|
|
if (File.Exists(SettingsFilePath))
|
|
{
|
|
string json = File.ReadAllText(SettingsFilePath);
|
|
AppSettings? appSettings = JsonConvert.DeserializeObject<AppSettings>(json);
|
|
if (appSettings != null)
|
|
{
|
|
this.Db= appSettings.Db;
|
|
this.VariableImportTemplate = appSettings.VariableImportTemplate;
|
|
this.Theme=appSettings.Theme;
|
|
this.MinimizeToTrayOnClose=appSettings.MinimizeToTrayOnClose;
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException("加载配置文件出现了错误。");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
|
|
File.WriteAllText(SettingsFilePath, json);
|
|
}
|
|
|
|
public string ToConnectionString()
|
|
{
|
|
return $"server={Db.Server};port={Db.Port};user={Db.UserId};password={Db.Password};database={Db.DbName};";
|
|
}
|
|
}
|
|
}
|