using Microsoft.AspNetCore.Http;
|
using Microsoft.Extensions.Configuration;
|
using Rhea.Common;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Security.AccessControl;
|
using System.Text;
|
|
namespace Tiger.IBusiness
|
{
|
public class ApiConfig
|
{
|
public static IServiceProvider ServiceProvider;
|
public static IConfiguration Configuration;
|
|
public static void InitConfig(IConfiguration _configuration)
|
{
|
Configuration = _configuration;
|
}
|
|
private static string _AllowUrl = string.Empty;
|
/// <summary>
|
/// 链接白名单(可不做身份验证)
|
/// </summary>
|
public static List<string> AllowUrl
|
{
|
get
|
{
|
if (string.IsNullOrEmpty(_AllowUrl))
|
{
|
_AllowUrl = Configuration["AllowUrl"];
|
}
|
List<string> listUrls = new List<string>();
|
if (!string.IsNullOrEmpty(_AllowUrl))
|
{
|
string[] urls = System.Text.RegularExpressions.Regex.Split(_AllowUrl, ",");
|
if (urls.Length > 0)
|
{
|
foreach (string url in urls)
|
{
|
if (!listUrls.Contains(url))
|
{
|
listUrls.Add(url);
|
}
|
}
|
}
|
|
}
|
return listUrls;
|
}
|
}
|
|
private static string _FilePath = string.Empty;
|
/// <summary>
|
/// 文件路径
|
/// </summary>
|
public static string FilePath
|
{
|
get
|
{
|
if (string.IsNullOrEmpty(_FilePath))
|
{
|
_FilePath = Configuration["CommonSettings:FilePath"];
|
}
|
return _FilePath;
|
}
|
}
|
|
|
/// <summary>
|
/// 更新路径
|
/// </summary>
|
public static string UpgradePath => (string.IsNullOrEmpty(Configuration["Upgrade:Path"]) ? (AppDomain.CurrentDomain.BaseDirectory + "Upgrade") : Configuration["Upgrade:Path"]) + "\\";
|
|
private static string _IsOpenCache = string.Empty;
|
/// <summary>
|
/// 是否使用Redis
|
/// </summary>
|
public static bool IsOpenCache
|
{
|
get
|
{
|
if (string.IsNullOrEmpty(_IsOpenCache))
|
{
|
_IsOpenCache = Configuration["Redis:IsOpenRedis"];
|
}
|
if (_IsOpenCache.ToLower() == "true")
|
{
|
return true;
|
}
|
return false;
|
}
|
}
|
|
private static string _RedisConnectionString = string.Empty;
|
/// <summary>
|
/// Redis默认连接串
|
/// </summary>
|
public static string RedisConnectionString
|
{
|
get
|
{
|
if (string.IsNullOrEmpty(_RedisConnectionString))
|
{
|
_RedisConnectionString = Configuration["Redis:ConnectionString"];
|
}
|
return _RedisConnectionString;
|
}
|
}
|
|
/// <summary>
|
/// 统一请求页面实体
|
/// </summary>
|
public static HttpContext HttpCurrent
|
{
|
get
|
{
|
object factory = ServiceProvider.GetService(typeof(IHttpContextAccessor));
|
HttpContext context = ((IHttpContextAccessor)factory).HttpContext;
|
return context;
|
}
|
}
|
|
/// <summary>
|
/// 事务超时小时数
|
/// </summary>
|
public static int Transaction_TimeoutHours
|
{
|
get => Convert.ToInt32(Configuration["Transaction:TimeoutHours"] ?? "12");
|
}
|
|
/// <summary>
|
/// 事务超时分钟数
|
/// </summary>
|
public static double Client_TimeoutMinutes
|
{
|
get => Convert.ToDouble(Configuration["Timeout:Client_Minutes"] ?? "60");
|
}
|
|
/// <summary>
|
/// 是否测试版本
|
/// </summary>
|
public static bool IsTestVersion
|
{
|
get => Configuration.AsEnumerable().Where(q => q.Key.StartsWith("StartUpSetting:UseUrls") && q.Value == "http://*:9520").Any();
|
}
|
|
/// <summary>
|
/// 旧系统版本
|
/// </summary>
|
public static bool IsOldVersion
|
{
|
get => Configuration.AsEnumerable().Where(q => q.Key.StartsWith("StartUpSetting:UseUrls") && q.Value == "http://*:9527").Any();
|
}
|
|
/// <summary>
|
/// 是否开发版本
|
/// </summary>
|
public static bool IsDevVersion
|
{
|
get => Configuration.AsEnumerable().Where(q => q.Key.StartsWith("StartUpSetting:UseUrls") && q.Value == "http://*:9510").Any();
|
}
|
|
/// <summary>
|
/// RunInterface
|
/// </summary>
|
public static bool RunInterface
|
{
|
get => (Configuration["RunInterface"] ?? "").ToLower() == "true";
|
}
|
|
public static bool IsTestServer
|
{
|
get => (BizConfig.Configuration["IsTestServer"] ?? "").ToLower() == "true";
|
}
|
}
|
|
public class BizConfig
|
{
|
public static IConfiguration Configuration => RheaConfig.Configuration;
|
public static string DB_ModelAssembly => RheaConfig.DB_ModelAssembly;
|
public static string DefaultLanguage => Configuration?["DefaultLanguage"] ?? "zh-cn";
|
public static void InitConfig(IConfiguration _configuration, Dictionary<string, Dictionary<string, string>> language)
|
{
|
//Init Rhea
|
Rhea.Common.RheaConfig.InitConfig(_configuration);
|
Rhea.Common.Language.Default = DefaultLanguage;
|
Rhea.Common.Language.Dictionary = language;
|
}
|
}
|
}
|