1 refactor(config): 将AppSettings移至Application层并更新配置结构
2
3 - 将AppSettings从DMS.Infrastructure移至DMS.Application
4 - 将DatabaseSettings重命名为AppSettings.Database并更新所有引用
5 - 将配置文件从appSettings.json更改为dms_config.json
6 - 更新所有项目引用以使用新的AppSettings命名空间
7 - 移除DI容器中的SqlSugarDbContext直接实例化
8 - 添加Material Design Icons字体并更新设置视图UI
9 - 通过移除不必要的变量映射更新来优化S7服务
10 - 将数据库连接字符串属性名从Database更新为DbName
This commit is contained in:
@@ -1,46 +1,46 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DMS.Application.Configurations
|
||||
{
|
||||
public class DatabaseSettings
|
||||
{
|
||||
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 Database { get; set; } = "pmswpf";
|
||||
}
|
||||
|
||||
|
||||
public class AppSettings
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
|
||||
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 DatabaseSettings Database { get; set; } = new DatabaseSettings();
|
||||
|
||||
public Database Db { get; set; } = new Database();
|
||||
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, "appSettings.json");
|
||||
private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigJsonFileName);
|
||||
|
||||
private const string ConfigJsonFileName = "dms_config.json";
|
||||
|
||||
public AppSettings Load()
|
||||
public AppSettings? Load()
|
||||
{
|
||||
if (File.Exists(SettingsFilePath))
|
||||
{
|
||||
string json = File.ReadAllText(SettingsFilePath);
|
||||
AppSettings appSettings = JsonConvert.DeserializeObject<AppSettings>(json);
|
||||
|
||||
return appSettings;
|
||||
AppSettings? appSettings = JsonConvert.DeserializeObject<AppSettings>(json);
|
||||
return appSettings ?? throw new InvalidOperationException("加载配置文件出现了错误。");
|
||||
}
|
||||
return new AppSettings();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
@@ -51,7 +51,7 @@ namespace DMS.Application.Configurations
|
||||
|
||||
public string ToConnectionString()
|
||||
{
|
||||
return $"server={Database.Server};port={Database.Port};user={Database.UserId};password={Database.Password};database={Database.Database};";
|
||||
return $"server={Db.Server};port={Db.Port};user={Db.UserId};password={Db.Password};database={Db.DbName};";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user