2025-11-28 14:54:24 +01:00
|
|
|
|
using System;
|
2025-05-05 13:27:22 +02:00
|
|
|
|
using System.Configuration;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BeWo.Service.Core
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class MergedConfig
|
|
|
|
|
|
{
|
2025-06-03 15:46:41 +02:00
|
|
|
|
public static string GetSetting(WebConfigSetting config)
|
2025-05-05 13:27:22 +02:00
|
|
|
|
{
|
2025-06-03 15:46:41 +02:00
|
|
|
|
return getSetting(config.ToString());
|
|
|
|
|
|
}
|
2025-05-05 13:27:22 +02:00
|
|
|
|
|
2025-06-03 15:46:41 +02:00
|
|
|
|
public static string GetSecretSetting(WebSecretConfigSetting webSecretConfigSetting)
|
|
|
|
|
|
{
|
2025-06-17 15:46:04 +02:00
|
|
|
|
if (webSecretConfigSetting == WebSecretConfigSetting.None)
|
|
|
|
|
|
throw new ArgumentNullException("webSecretConfigSetting");
|
|
|
|
|
|
|
2025-06-03 15:46:41 +02:00
|
|
|
|
return getSecretSetting(webSecretConfigSetting.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string getSetting(string key)
|
|
|
|
|
|
{
|
2025-05-05 13:27:22 +02:00
|
|
|
|
return ConfigurationManager.AppSettings[key];
|
|
|
|
|
|
}
|
2025-05-27 10:32:21 +02:00
|
|
|
|
|
2025-06-03 15:46:41 +02:00
|
|
|
|
private static string getSecretSetting(string key)
|
2025-05-27 10:32:21 +02:00
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
2025-05-05 13:27:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|