support alias as default source

This commit is contained in:
Paul Schneider 2022-12-11 16:11:12 +00:00
commit 51dcb39c93

View file

@ -1,4 +1,6 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace isn namespace isn
{ {
@ -14,6 +16,28 @@ namespace isn
public Dictionary<string, SourceSettings> Sources { get; set; } public Dictionary<string, SourceSettings> Sources { get; set; }
public bool AutoUpdateApiKey { get; set; } = false; public bool AutoUpdateApiKey { get; set; } = false;
public string DefaultSource { get; set; }
private string source;
/// <summary>
/// Default Url or alias for the source
/// </summary>
/// <value></value>
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 .");
}
}
} }
} }