Files
BeWoPlaner/BeWo/DebugConfig.cs
2024-11-14 16:57:13 +01:00

132 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
namespace BeWo
{
public enum DebugConfigMode
{
SimpleAutoLogin,
FeatureCustomerWohnhilfe,
FeatureWohnheimWohneinheit,
FeatureAuswertungenQuittierungsbelege,
FeatureDakota
}
public class DebugConfig
{
private static readonly string config_file_name = "DebugConfig.txt";
public static DebugConfig CurrentConfig { get; } = LoadCurrentDebugConfig();
public static string ServerUrl { get; set; } = "http://localhost:3777/Host";
public DebugConfigMode DebugConfigMode { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Profilename { get; set; }
public bool AutoLogin { get; set; }
public UIContext? SelectView { get; set; }
/// <summary>
/// Beschreibt den Index der jeweils gewählten View (UIContext)
///
/// Z.b.:
/// Customer:
/// - Details: 0
/// - ...: 1
/// - ...: 2
/// - ...: 3
/// - VermittlungArbeit: 4
/// - Wohnhilfe: 5
/// </summary>
public int? SelectIndex { get; set; }
private static DebugConfig LoadCurrentDebugConfig()
{
#if DEBUG
try
{
var path = AppDomain.CurrentDomain.BaseDirectory;
var project_path = Directory.GetParent(path).Parent.Parent.FullName;
var config_path = Path.Combine(project_path, config_file_name);
if (!File.Exists(config_path))
return null;
var current_config = File.ReadAllText(config_path);
if (string.IsNullOrWhiteSpace(current_config))
return null;
var name2config = GetName2Config();
if (name2config.TryGetValue(current_config, out DebugConfig current))
{
return current;
}
}
catch (Exception)
{
}
#endif
return null;
}
#if DEBUG
private static Dictionary<string, DebugConfig> GetName2Config()
{
var name2config = new Dictionary<string, DebugConfig>();
name2config.Add("SimpleAutoLogin",
new DebugConfig()
{
DebugConfigMode = DebugConfigMode.SimpleAutoLogin,
AutoLogin = true
});
name2config.Add("FeatureCustomerWohnhilfe",
new DebugConfig()
{
DebugConfigMode = DebugConfigMode.FeatureCustomerWohnhilfe,
AutoLogin = true,
SelectView = UIContext.Customer,
SelectIndex = 5
});
name2config.Add("FeatureWohnheimWohneinheit",
new DebugConfig()
{
DebugConfigMode = DebugConfigMode.FeatureWohnheimWohneinheit,
AutoLogin = true,
SelectView = UIContext.Wohnheim
});
name2config.Add("FeatureAuswertungenQuittierungsbelege",
new DebugConfig()
{
DebugConfigMode = DebugConfigMode.FeatureAuswertungenQuittierungsbelege,
AutoLogin = true,
SelectView = UIContext.Report
});
name2config.Add("FeatureDakota",
new DebugConfig()
{
DebugConfigMode = DebugConfigMode.FeatureDakota,
AutoLogin = false,
//SelectView = UIContext.Finance,
SelectIndex = 8,
Username = "m1",
Password = "bewobewo",
Profilename = "5000000000"
});
return name2config;
}
#endif
}
}