using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.Configuration; using System.Linq; using APT.Infrastructure.Core; namespace APT.Infrastructure.Api { public static class ConfigurationManager { public static IConfiguration Configuration { get; private set; } public static IConfigurationSection AppSettings { get; set; } public static IConfigurationSection WexinSettings { get; set; } public static IConfigurationSection ConnectionStrings { get; set; } public static IConfigurationSection RedisStrings { get; set; } public static IConfigurationSection InfluxDbStrings { get; set; } public static void Register(IConfiguration configuration) { Configuration = configuration; AppSettings = Configuration.GetSection("AppSettings"); RedisStrings = Configuration.GetSection("RedisConfig"); InfluxDbStrings = Configuration.GetSection("InflexdbConfig"); ConnectionStrings = Configuration.GetSection("ConnectionStrings"); WexinSettings = Configuration.GetSection("WexinSettings"); } public static bool IsRedis { get { return LibUtils.ToBoolean(RedisStrings["IsRedis"]); } } private static InfluxDbOption _option; public static InfluxDbOption InfluxDbOption { get { if (_option == null) { _option = new InfluxDbOption(); var s = InfluxDbStrings.GetChildren(); _option.Url = s.Any(i => i.Key == "Url") ? s.FirstOrDefault(i => i.Key == "Url").Value : ""; _option.UserName = s.Any(i => i.Key == "UserName") ? s.FirstOrDefault(i => i.Key == "UserName").Value : ""; _option.PassWord = s.Any(i => i.Key == "PassWord") ? s.FirstOrDefault(i => i.Key == "PassWord").Value : ""; _option.SrcTagDbName = s.Any(i => i.Key == "SrcTagDbName") ? s.FirstOrDefault(i => i.Key == "SrcTagDbName").Value : ""; _option.CorrectWaring = s.Any(i => i.Key == "CorrectWaring") ? s.FirstOrDefault(i => i.Key == "CorrectWaring").Value : ""; _option.LogDbName = s.Any(i => i.Key == "LogDbName") ? s.FirstOrDefault(i => i.Key == "LogDbName").Value : ""; _option.MaxDemandDbName = s.Any(i => i.Key == "MaxDemandDbName") ? s.FirstOrDefault(i => i.Key == "MaxDemandDbName").Value : ""; _option.DosageDbName = s.Any(i => i.Key == "DosageDbName") ? s.FirstOrDefault(i => i.Key == "DosageDbName").Value : ""; _option.EnergyValDbName = s.Any(i => i.Key == "EnergyValDbName") ? s.FirstOrDefault(i => i.Key == "EnergyValDbName").Value : ""; _option.AppOnline = s.Any(i => i.Key == "AppOnline") ? s.FirstOrDefault(i => i.Key == "AppOnline").Value : ""; } return _option; } } private static RedisOption _redisPotion; public static RedisOption RedisOption { get { if (_redisPotion == null) { var s = RedisStrings.GetChildren(); var conn = s.Any(i => i.Key == "RedisConnectionString") ? s.FirstOrDefault(i => i.Key == "RedisConnectionString").Value : ""; var pwd = s.Any(i => i.Key == "RedisConnectionPwd") ? s.FirstOrDefault(i => i.Key == "RedisConnectionPwd").Value : ""; var pKey = s.Any(i => i.Key == "RedisPrefixKey") ? s.FirstOrDefault(i => i.Key == "RedisPrefixKey").Value : ""; _redisPotion= new RedisOption() { RedisConnectionString = conn, RedisConnectionPwd = pwd, RedisPrefixKey = pKey }; } return _redisPotion; } } } }