Use branch name in config

This commit is contained in:
2023-05-25 19:03:10 +02:00
parent 7468af3970
commit 9229f27cf7
2 changed files with 11 additions and 11 deletions

View File

@ -32,13 +32,13 @@ namespace Elwig {
}
protected override void OnStartup(StartupEventArgs evt) {
IEnumerable<string> branches = Array.Empty<string>();
Dictionary<string, string> branches = new();
using (var ctx = new AppDbContext()) {
if (!ctx.Database.CanConnect()) {
MessageBox.Show($"Invalid Database:\n\n{Config.DatabaseFile}", "Invalid Database", MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown();
} else {
branches = ctx.Branches.Select(b => b.ZwstId).ToList();
branches = ctx.Branches.ToDictionary(b => b.Name.ToLower(), b => b.ZwstId);
}
}
Utils.RunBackground("HTML Initialization", () => Documents.Html.Init(PrintingReadyChanged));
@ -67,15 +67,15 @@ namespace Elwig {
}
Scales = list;
if (Config.ZwstId != null) {
if (!branches.Contains(Config.ZwstId)) {
MessageBox.Show("Invalid branch id in config!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error);
if (Config.Branch != null) {
if (!branches.ContainsKey(Config.Branch.ToLower())) {
MessageBox.Show("Invalid branch name in config!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown();
} else {
ZwstId = Config.ZwstId;
ZwstId = branches[Config.Branch.ToLower()];
}
} else if (branches.Count() == 1) {
ZwstId = branches.First();
} else if (branches.Count == 1) {
ZwstId = branches.First().Value;
} else {
MessageBox.Show("Unable to determine local branch!", "Invalid Branch Config", MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown();