Files
BeWoPlaner/Service/Core/MergedConfig.cs
2025-06-03 15:46:41 +02:00

45 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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)
{
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;
}
}
}