2025-07-19 22:29:50 +08:00
|
|
|
using DMS.Core.Models;
|
|
|
|
|
using Newtonsoft.Json;
|
2025-07-06 11:09:57 +08:00
|
|
|
|
2025-10-04 18:40:36 +08:00
|
|
|
namespace DMS.Application.Configurations
|
2025-07-06 11:09:57 +08:00
|
|
|
{
|
2025-10-04 18:42:12 +08:00
|
|
|
|
2025-07-19 22:29:50 +08:00
|
|
|
|
|
|
|
|
public class AppSettings
|
|
|
|
|
{
|
2025-10-04 18:42:12 +08:00
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-02 12:35:42 +08:00
|
|
|
|
2025-10-04 18:42:12 +08:00
|
|
|
public Database Db { get; set; } = new Database();
|
2025-07-12 12:55:46 +08:00
|
|
|
public string Theme { get; set; } = "跟随系统";
|
2025-07-07 21:15:27 +08:00
|
|
|
public bool EnableS7Service { get; set; } = true;
|
|
|
|
|
public bool EnableMqttService { get; set; } = true;
|
2025-07-08 17:33:20 +08:00
|
|
|
public bool EnableOpcUaService { get; set; } = true;
|
2025-07-09 20:48:14 +08:00
|
|
|
public bool MinimizeToTrayOnClose { get; set; } = true;
|
2025-07-19 22:29:50 +08:00
|
|
|
public List<MenuBean> Menus { get; set; } = new List<MenuBean>();
|
2025-10-04 18:42:12 +08:00
|
|
|
|
2025-10-02 12:35:42 +08:00
|
|
|
public int DefaultPollingInterval { get; set; } = 30000; // 默认轮询间隔30秒
|
2025-07-06 11:09:57 +08:00
|
|
|
|
2025-10-04 18:42:12 +08:00
|
|
|
private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigJsonFileName);
|
|
|
|
|
|
|
|
|
|
private const string ConfigJsonFileName = "dms_config.json";
|
2025-07-06 11:09:57 +08:00
|
|
|
|
2025-10-04 18:42:12 +08:00
|
|
|
public AppSettings? Load()
|
2025-07-06 11:09:57 +08:00
|
|
|
{
|
|
|
|
|
if (File.Exists(SettingsFilePath))
|
|
|
|
|
{
|
|
|
|
|
string json = File.ReadAllText(SettingsFilePath);
|
2025-10-04 18:42:12 +08:00
|
|
|
AppSettings? appSettings = JsonConvert.DeserializeObject<AppSettings>(json);
|
|
|
|
|
return appSettings ?? throw new InvalidOperationException("加载配置文件出现了错误。");
|
2025-07-06 11:09:57 +08:00
|
|
|
}
|
2025-10-04 18:42:12 +08:00
|
|
|
return null;
|
2025-07-06 11:09:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
|
|
|
|
|
File.WriteAllText(SettingsFilePath, json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ToConnectionString()
|
|
|
|
|
{
|
2025-10-04 18:42:12 +08:00
|
|
|
return $"server={Db.Server};port={Db.Port};user={Db.UserId};password={Db.Password};database={Db.DbName};";
|
2025-07-06 11:09:57 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|