From 81e18ac5536c4a72acffddeeb64423e7a6c19fc2 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Mon, 13 May 2024 11:33:27 +0200 Subject: [PATCH] Config: Add 'required' option to scales --- Elwig/App.xaml.cs | 4 +++- Elwig/Helpers/Config.cs | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Elwig/App.xaml.cs b/Elwig/App.xaml.cs index 2a3fbe9..da3ad8a 100644 --- a/Elwig/App.xaml.cs +++ b/Elwig/App.xaml.cs @@ -159,7 +159,9 @@ namespace Elwig { list.Add(Scale.FromConfig(s)); } catch (Exception e) { list.Add(new InvalidScale(s.Id)); - MessageBox.Show($"Unable to create scale {s.Id}:\n\n{e.Message}", "Scale Error", MessageBoxButton.OK, MessageBoxImage.Error); + if (s.Required) + MessageBox.Show($"Unable to create scale {s.Id}:\n\n{e.Message}", "Scale Error", + MessageBoxButton.OK, MessageBoxImage.Error); } } Scales = list; diff --git a/Elwig/Helpers/Config.cs b/Elwig/Helpers/Config.cs index 51f3004..ba732bd 100644 --- a/Elwig/Helpers/Config.cs +++ b/Elwig/Helpers/Config.cs @@ -13,10 +13,11 @@ namespace Elwig.Helpers { public string? Empty; public string? Filling; public string? Limit; + public bool Required; public string? Log; public string? _Log; - public ScaleConfig(string id, string? type, string? model, string? cnx, string? empty, string? filling, string? limit, string? log) { + public ScaleConfig(string id, string? type, string? model, string? cnx, string? empty, string? filling, string? limit, bool? required, string? log) { Id = id; Type = type; Model = model; @@ -24,6 +25,7 @@ namespace Elwig.Helpers { Empty = empty; Filling = filling; Limit = limit; + Required = required ?? true; _Log = log; Log = log != null ? Path.Combine(App.DataPath, log) : null; } @@ -91,7 +93,9 @@ namespace Elwig.Helpers { foreach (var s in scales) { ScaleList.Add(new( s, config[$"scale.{s}:type"], config[$"scale.{s}:model"], config[$"scale.{s}:connection"], - config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"], config[$"scale.{s}:log"] + config[$"scale.{s}:empty"], config[$"scale.{s}:filling"], config[$"scale.{s}:limit"], + config[$"scale.{s}:required"] != null ? TrueValues.Contains(config[$"scale.{s}:required"]?.ToLower()) : null, + config[$"scale.{s}:log"] )); } }