From 51dcb39c9398123bf6bdf803d09f5f1d6bb6a1d7 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 11 Dec 2022 16:11:12 +0000 Subject: [PATCH] support alias as default source --- src/isn/Settings.cs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/isn/Settings.cs b/src/isn/Settings.cs index 7bf03b9..bbad901 100644 --- a/src/isn/Settings.cs +++ b/src/isn/Settings.cs @@ -1,4 +1,6 @@ +using System; using System.Collections.Generic; +using System.Linq; namespace isn { @@ -10,10 +12,32 @@ namespace isn public class Settings { - public string DataProtectionTitle {get; set; } + public string DataProtectionTitle { get; set; } public Dictionary Sources { get; set; } public bool AutoUpdateApiKey { get; set; } = false; - public string DefaultSource { get; set; } + + private string source; + /// + /// Default Url or alias for the source + /// + /// + public string DefaultSource + { + get => source; + set + { + if (Sources.ContainsKey(value)) + { + source = value; + return; + } + if (Sources.Values.Any(s => s.Alias == value)) + { + source = Sources[value].Alias; + } + throw new InvalidOperationException("Add it to Sources before, with an API key, as source or alias ."); + } + } } -} \ No newline at end of file +}