using System; using System.Configuration; using System.IO; using System.Xml; namespace BeWo.Service.Core { public static class MergedConfig { public static string GetSetting(WebConfigSetting config) { return getSetting(config.ToString()); } public static string GetSecretSetting(WebSecretConfigSetting webSecretConfigSetting) { if (webSecretConfigSetting == WebSecretConfigSetting.None) throw new ArgumentNullException("webSecretConfigSetting"); return getSecretSetting(webSecretConfigSetting.ToString()); } private static string getSetting(string key) { return ConfigurationManager.AppSettings[key]; } private static string getSecretSetting(string key) { var localConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Web.Secrets.config"); if (!File.Exists(localConfigPath)) return null; var xml = new XmlDocument(); xml.Load(localConfigPath); var node = xml.SelectSingleNode($"/appSettings/add[@key='{key}']"); if (node is XmlElement element) return element.GetAttribute("value"); return null; } } }