R1: Umbau auf Multi-Projekt-Struktur (Vorbild PolytraderSharp) Kurskorrektur: Vorbild ist PolytraderSharp (C#), nicht die veraltete Python-Version. Reiner Strukturumbau, Verhalten unveraendert. - src/IBKRTrader.Core (classlib): Core-Code + UI-Contract (ModuleFormBase, WindowManager) - src/IBKRTrader.Modules.CongressTrading (classlib, referenziert nur Core) - Root: IBKRTrader.App (WinExe) referenziert Core + Modul - tests/IBKRTrader.Tests: Referenzen auf Core + Modul - Neue .slnx; ungenutztes HtmlAgilityPack entfernt - docs/ARCHITECTURE.md: korrigierter Ziel-Stand + R-Phasenplan - Build + 38/38 Tests gruen; App startet Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> @
50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System.Text.Json;
|
||
using System.Text.Json.Serialization;
|
||
|
||
namespace IBKRTrader.Core.Settings;
|
||
|
||
/// <summary>
|
||
/// Lädt und speichert settings.json neben der EXE.
|
||
/// Singleton – wird beim App-Start einmalig geladen.
|
||
/// </summary>
|
||
public class SettingsService
|
||
{
|
||
private static readonly string SettingsPath =
|
||
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
|
||
|
||
private static readonly JsonSerializerOptions JsonOptions = new()
|
||
{
|
||
WriteIndented = true,
|
||
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
|
||
PropertyNameCaseInsensitive = true
|
||
};
|
||
|
||
public AppSettings Settings { get; private set; } = new();
|
||
|
||
public void Load()
|
||
{
|
||
if (!File.Exists(SettingsPath))
|
||
{
|
||
Save(); // Defaults auf Disk schreiben
|
||
return;
|
||
}
|
||
|
||
try
|
||
{
|
||
var json = File.ReadAllText(SettingsPath);
|
||
Settings = JsonSerializer.Deserialize<AppSettings>(json, JsonOptions) ?? new AppSettings();
|
||
}
|
||
catch
|
||
{
|
||
Settings = new AppSettings();
|
||
Save();
|
||
}
|
||
}
|
||
|
||
public void Save()
|
||
{
|
||
var json = JsonSerializer.Serialize(Settings, JsonOptions);
|
||
File.WriteAllText(SettingsPath, json);
|
||
}
|
||
}
|