79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Specialized;
|
|
using System.Configuration;
|
|
|
|
namespace YiDa_WinForm.Config
|
|
{
|
|
/// <summary>
|
|
/// 应用配置辅助类(读取 app.config 中的配置)
|
|
/// </summary>
|
|
public static class AppConfig
|
|
{
|
|
#region 数据库配置
|
|
/// <summary>
|
|
/// MySQL 连接字符串
|
|
/// </summary>
|
|
public static string MySqlConnectionString
|
|
{
|
|
get
|
|
{
|
|
// 读取 connectionStrings 节点中的配置
|
|
return ConfigurationManager.ConnectionStrings["MySqlConnection"]?.ConnectionString
|
|
?? throw new Exception("未配置 MySQL 连接字符串");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 宜搭接口配置
|
|
/// <summary>
|
|
/// 宜搭 Token AppKey
|
|
/// </summary>
|
|
public static string YiDaTokenAppKey => GetYiDaConfig("TokenAppKey");
|
|
|
|
/// <summary>
|
|
/// 宜搭 Token AppSecret
|
|
/// </summary>
|
|
public static string YiDaTokenAppSecret => GetYiDaConfig("TokenAppSecret");
|
|
|
|
/// <summary>
|
|
/// 宜搭 AppType
|
|
/// </summary>
|
|
public static string YiDaAppType => GetYiDaConfig("AppType");
|
|
|
|
/// <summary>
|
|
/// 宜搭 SystemToken
|
|
/// </summary>
|
|
public static string YiDaSystemToken => GetYiDaConfig("SystemToken");
|
|
|
|
/// <summary>
|
|
/// 宜搭 UserId
|
|
/// </summary>
|
|
public static string YiDaUserId => GetYiDaConfig("UserId");
|
|
|
|
/// <summary>
|
|
/// 宜搭 FormUuid
|
|
/// </summary>
|
|
public static string YiDaFormUuid => GetYiDaConfig("FormUuid");
|
|
|
|
/// <summary>
|
|
/// 宜搭 ProcessCode
|
|
/// </summary>
|
|
public static string YiDaProcessCode => GetYiDaConfig("ProcessCode");
|
|
|
|
/// <summary>
|
|
/// 读取宜搭配置项的通用方法
|
|
/// </summary>
|
|
/// <param name="key">配置项Key</param>
|
|
/// <returns>配置值</returns>
|
|
private static string GetYiDaConfig(string key)
|
|
{
|
|
var yiDaConfig = ConfigurationManager.GetSection("YiDaConfig") as NameValueCollection;
|
|
if (yiDaConfig == null || string.IsNullOrEmpty(yiDaConfig[key]))
|
|
{
|
|
throw new Exception($"未配置宜搭参数:{key}");
|
|
}
|
|
return yiDaConfig[key];
|
|
}
|
|
#endregion
|
|
}
|
|
} |