You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.5 KiB
76 lines
2.5 KiB
using System;
|
|
using CK.SCP.Utils;
|
|
|
|
namespace ChangkeTec.SDMS.Model
|
|
{
|
|
public static class GlobalConfig
|
|
{
|
|
public const string CommonFileName = "通用设置.ini";
|
|
public const string DataCenterDbFileName = "数据中心数据库设置.ini";
|
|
public const string ExchangeCenterDbFileName = "交换中心数据库设置.ini";
|
|
public const string UpdateFileName = "自动更新设置.ini";
|
|
|
|
|
|
private static DbSetting _dcDB;
|
|
private static DbSetting _ecDB;
|
|
|
|
|
|
public static GlobalSetting Setting = new GlobalSetting();
|
|
|
|
|
|
public static DbSetting DataCenterDB
|
|
{
|
|
get { return _dcDB ?? (_dcDB = GetConfigValues<DbSetting>(DataCenterDbFileName)); }
|
|
|
|
set { _dcDB = value; }
|
|
}
|
|
|
|
public static DbSetting ExchangeCenterDB
|
|
{
|
|
get { return _ecDB ?? (_ecDB = GetConfigValues<DbSetting>(ExchangeCenterDbFileName)); }
|
|
|
|
set { _ecDB = value; }
|
|
}
|
|
|
|
public static T GetConfigValues<T>(string filename) where T : new()
|
|
{
|
|
var t = new T();
|
|
if (FileHelper.Exists(filename))
|
|
t = JsonHelper.ReadConfigFromFile<T>(filename);
|
|
else
|
|
throw new Exception($"配置文件【{filename}】丢失,请重新配置");
|
|
|
|
return t;
|
|
}
|
|
|
|
public static void TestDataCenterDbConnection()
|
|
{
|
|
try
|
|
{
|
|
var db = DbContextFactory.CreateDataCenterInstance();
|
|
db.Database.ExecuteSqlCommand("select getdate()");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(
|
|
$"系统无法连接到{DataCenterDbFileName} {DataCenterDB.数据库类型}数据库:{DataCenterDB},请检查配置的服务器,数据库,用户名和密码等信息是否正确。" +
|
|
ex);
|
|
}
|
|
}
|
|
|
|
public static void TestExchangeCenterDbConnection()
|
|
{
|
|
try
|
|
{
|
|
var db = DbContextFactory.CreateExchangeCenterInstance();
|
|
db.Database.ExecuteSqlCommand("select getdate()");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(
|
|
$"系统无法连接到{ExchangeCenterDbFileName} {DataCenterDB.数据库类型}数据库:{DataCenterDB},请检查配置的服务器,数据库,用户名和密码等信息是否正确。" +
|
|
ex);
|
|
}
|
|
}
|
|
}
|
|
}
|