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:
57
DMS.Application/Configurations/AppSettings.cs
Normal file
57
DMS.Application/Configurations/AppSettings.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
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 DatabaseSettings Database { get; set; } = new DatabaseSettings();
|
||||
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");
|
||||
|
||||
public AppSettings Load()
|
||||
{
|
||||
if (File.Exists(SettingsFilePath))
|
||||
{
|
||||
string json = File.ReadAllText(SettingsFilePath);
|
||||
AppSettings appSettings = JsonConvert.DeserializeObject<AppSettings>(json);
|
||||
|
||||
return appSettings;
|
||||
}
|
||||
return new AppSettings();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
File.WriteAllText(SettingsFilePath, json);
|
||||
}
|
||||
|
||||
public string ToConnectionString()
|
||||
{
|
||||
return $"server={Database.Server};port={Database.Port};user={Database.UserId};password={Database.Password};database={Database.Database};";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user