This commit is contained in:
2025-02-12 12:10:56 +01:00
parent 705e99b4a7
commit c02a73213b
14 changed files with 1761 additions and 0 deletions

91
Epi2O365/ConfigLoader.cs Normal file
View File

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.IO;
using System.Text.Json;
namespace Epi2Exchange2
{
public class ConfigLoader
{
public AzureAdConfig AzureAd { get; set; }
public GraphConfig Graph { get; set; }
public EpirentConfig Epirent { get; set; }
private static readonly string configFilePath = "appsettings.json";
private static ConfigLoader _instance;
// Singleton-Instanz für globale Nutzung
public static ConfigLoader Instance => _instance ??= LoadConfig();
public ConfigLoader() { }
/// <summary>
/// Lädt die Konfiguration aus der appsettings.json Datei
/// </summary>
public static ConfigLoader LoadConfig()
{
Logger.Info("Lade Konfigurationsdatei...");
try
{
if (!File.Exists(configFilePath))
{
Logger.Error($"Konfigurationsdatei '{configFilePath}' wurde nicht gefunden!");
throw new FileNotFoundException($"Config-Datei '{configFilePath}' wurde nicht gefunden!");
}
string json = File.ReadAllText(configFilePath);
var config = JsonSerializer.Deserialize<ConfigLoader>(json);
if (config == null)
{
Logger.Error("Fehler: Konfiguration konnte nicht deserialisiert werden.");
throw new Exception("Konfiguration konnte nicht geladen werden.");
}
Logger.Info("Konfiguration erfolgreich geladen.");
return config;
}
catch (Exception ex)
{
Logger.Error("Fehler beim Laden der Konfiguration!", ex);
throw;
}
}
}
/// <summary>
/// Azure AD Konfiguration (für Microsoft Graph API)
/// </summary>
public class AzureAdConfig
{
public string ClientId { get; set; }
public string TenantId { get; set; }
public string ClientSecret { get; set; }
}
/// <summary>
/// Microsoft Graph API Konfiguration
/// </summary>
public class GraphConfig
{
public string BaseUrl { get; set; }
public List<string> Users { get; set; }
}
/// <summary>
/// Epirent Konfiguration
/// </summary>
public class EpirentConfig
{
public string Server { get; set; }
public int Port { get; set; }
public string Token { get; set; }
public int Mandant { get; set; }
}
}