Files
OnDoc/API_NetFramework/TableConfigProvider.cs
2026-02-13 06:42:52 +01:00

47 lines
1.4 KiB
C#

using Newtonsoft.Json;
using System.IO;
using System.Web;
namespace WebApp
{
public class TableConfigRoot
{
public System.Collections.Generic.List<TableConfig> Tables { get; set; }
}
public class TableConfig
{
public string Key { get; set; }
public string DisplayName { get; set; }
public string SqlList { get; set; }
public string SqlById { get; set; }
public string IdField { get; set; }
public string DisplayField { get; set; }
public string JsonField { get; set; }
}
public static class TableConfigProvider
{
private static TableConfigRoot _cache;
public static TableConfigRoot LoadConfig()
{
if (_cache != null)
return _cache;
// ✅ HttpContext.Current verwenden statt Context
string path = HttpContext.Current.Server.MapPath("~/App_Data/TableConfig.json");
if (!File.Exists(path))
throw new FileNotFoundException("TableConfig.json nicht gefunden", path);
string json = File.ReadAllText(path);
_cache = JsonConvert.DeserializeObject<TableConfigRoot>(json);
if (_cache.Tables == null) _cache.Tables = new System.Collections.Generic.List<TableConfig>();
return _cache;
}
public static void ResetCache() => _cache = null;
}
}