Files
BeWoPlaner/BeWo/DebugConfig.cs
2025-09-12 14:58:20 +02:00

161 lines
4.1 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
namespace BeWo
{
public enum DebugConfigMode
{
SimpleAutoLogin,
FeatureCustomerWohnhilfe,
FeatureWohnheimWohneinheit,
FeatureAuswertungenQuittierungsbelege,
FeatureDakota,
FeatureAiModule
}
public class DebugConfig
{
private static readonly string config_file_name = "DebugConfig.txt";
public static DebugConfig CurrentConfig { get; } = LoadCurrentDebugConfig();
/// <summary>
/// Wird verwendet, wenn keine DebugConfig geladen wurde oder DefaultProfilename empty ist
/// </summary>
public static string ServerUrl { get; set; }
= "http://localhost:3777/Host";
// = "http://178.63.79.124/service";
public DebugConfigMode DebugConfigMode { get; set; }
public string DefaultLoginUsername { get; set; }
public string DefaultLoginPassword { get; set; }
public string DefaultProfilename { 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; }
public bool EnableAutoRemoteDebugging { get; set; }
public bool EnableAllUserRightsInDebug { get; set; } = false;
public static DebugConfig SimpleAutoLogin => new DebugConfig()
{
DebugConfigMode = DebugConfigMode.SimpleAutoLogin,
AutoLogin = !Environment.MachineName.Equals("OWNSOFT-JETTEN")
};
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 = true,
SelectView = UIContext.Organisation,
SelectIndex = 8,
DefaultLoginUsername = "m1",
DefaultLoginPassword = "bewobewo",
DefaultProfilename = "5000000000",
EnableAutoRemoteDebugging = true
});
name2config.Add("FeatureAiModule",
new DebugConfig()
{
DebugConfigMode = DebugConfigMode.FeatureAiModule,
AutoLogin = true,
SelectView = UIContext.ServiceRecord,
//SelectIndex = 8,
//DefaultLoginUsername = "m1",
//DefaultLoginPassword = "bewobewo",
//DefaultProfilename = "5000000000",
EnableAutoRemoteDebugging = true
});
return name2config;
}
#endif
}
}