重构服务类和仓库类
This commit is contained in:
52
DMS.Infrastructure/Configurations/AppSettings.cs
Normal file
52
DMS.Infrastructure/Configurations/AppSettings.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using DMS.Core.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace DMS.Config
|
||||
{
|
||||
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
|
||||
{
|
||||
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>();
|
||||
|
||||
private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appSettings.json");
|
||||
|
||||
public static AppSettings Load()
|
||||
{
|
||||
if (File.Exists(SettingsFilePath))
|
||||
{
|
||||
string json = File.ReadAllText(SettingsFilePath);
|
||||
return JsonConvert.DeserializeObject<AppSettings>(json);
|
||||
}
|
||||
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