You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DSWMS/Vue.Net/VOL.Core/Configuration/AppSetting.cs

184 lines
6.0 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using System.IO;
using VOL.Core.Const;
using VOL.Core.Extensions;
namespace VOL.Core.Configuration
{
public static class AppSetting
{
public static IConfiguration Configuration { get; private set; }
public static string DbConnectionString
{
get { return _connection.DbConnectionString; }
}
public static string RedisConnectionString
{
get { return _connection.RedisConnectionString; }
}
public static bool UseRedis
{
get { return _connection.UseRedis; }
}
public static string RemoteServer
{
get { return _connection.RemoteServer; }
}
public static CompanySetting CompanySetting
{
get { return _companySetting; }
}
public static Secret Secret { get; private set; }
public static CreateMember CreateMember { get; private set; }
public static ModifyMember ModifyMember { get; private set; }
private static Connection _connection;
private static CompanySetting _companySetting;
public static string TokenHeaderName = "Authorization";
/// <summary>
/// Actions权限过滤
/// </summary>
public static GlobalFilter GlobalFilter { get; set; }
/// <summary>
/// JWT有效期(分钟=默认120)
/// </summary>
public static int ExpMinutes { get; private set; } = 120;
public static string CurrentPath { get; private set; } = null;
public static string DownLoadPath { get { return CurrentPath + "\\Download\\"; } }
public static void Init(IServiceCollection services, IConfiguration configuration)
{
Configuration = configuration;
services.Configure<Secret>(configuration.GetSection("Secret"));
services.Configure<Connection>(configuration.GetSection("Connection"));
services.Configure<CompanySetting>(configuration.GetSection("CompanySetting"));
services.Configure<CreateMember>(configuration.GetSection("CreateMember"));
services.Configure<ModifyMember>(configuration.GetSection("ModifyMember"));
services.Configure<GlobalFilter>(configuration.GetSection("GlobalFilter"));
var provider = services.BuildServiceProvider();
IWebHostEnvironment environment = provider.GetRequiredService<IWebHostEnvironment>();
CurrentPath = Path.Combine(environment.ContentRootPath, "").ReplacePath();
Secret = provider.GetRequiredService<IOptions<Secret>>().Value;
//设置修改或删除时需要设置为默认用户信息的字段
CreateMember = provider.GetRequiredService<IOptions<CreateMember>>().Value ?? new CreateMember();
ModifyMember = provider.GetRequiredService<IOptions<ModifyMember>>().Value ?? new ModifyMember();
GlobalFilter = provider.GetRequiredService<IOptions<GlobalFilter>>().Value ?? new GlobalFilter();
GlobalFilter.Actions = GlobalFilter.Actions ?? new string[0];
_connection = provider.GetRequiredService<IOptions<Connection>>().Value;
_companySetting = provider.GetRequiredService<IOptions<CompanySetting>>().Value;
ExpMinutes = (configuration["ExpMinutes"] ?? "120").GetInt();
DBType.Name = _connection.DBType;
if (string.IsNullOrEmpty(_connection.DbConnectionString))
throw new System.Exception("未配置好数据库默认连接");
try
{
_connection.DbConnectionString = _connection.DbConnectionString.DecryptDES(Secret.DB);
}
catch { }
if (!string.IsNullOrEmpty(_connection.RedisConnectionString))
{
try
{
_connection.RedisConnectionString = _connection.RedisConnectionString.DecryptDES(Secret.Redis);
}
catch { }
}
}
// 多个节点name格式 ["key:key1"]
public static string GetSettingString(string key)
{
return Configuration[key];
}
// 多个节点,通过.GetSection("key")["key1"]获取
public static IConfigurationSection GetSection(string key)
{
return Configuration.GetSection(key);
}
}
public class Connection
{
public string DBType { get; set; }
public string DbConnectionString { get; set; }
public string RedisConnectionString { get; set; }
public bool UseRedis { get; set; }
public string RemoteServer { get; set; }
}
public class CompanySetting {
public string COMPANYNAME { get; set; }
public bool CanOutMore { get; set; }
/// <summary>
/// 负数库存在完全出清前是否参与计算
/// </summary>
public bool NegativeStockFee { get; set; }
public string WUNIUKey { get; set; }
public string WUNIUappId { get; set; }
public int? INDOStep { get; set; }
public string BILLBSNONAME { get; set; }
public string STORAGEBSNONAME { get; set; }
public bool? INPLANAudit { get; set; }
/// <summary>
/// 是否允许重复生成账单,默认为是
/// 如为否 则不会生成已有在当日费用的
/// </summary>
public bool FeeBillCanRepeat { get; set; } = true;
}
public class CreateMember: TableDefaultColumns
{
}
public class ModifyMember: TableDefaultColumns
{
}
public abstract class TableDefaultColumns
{
public string UserIdField { get; set; }
public string UserNameField { get; set; }
public string DateField { get; set; }
}
public class GlobalFilter
{
public string Message { get; set; }
public bool Enable { get; set; }
public string[] Actions { get; set; }
}
}