2021-10-12 20:23:25 +01:00
|
|
|
|
using System.Collections.Generic;
|
2021-10-24 17:38:45 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2021-10-11 23:19:19 +01:00
|
|
|
|
|
2021-10-11 18:17:36 +01:00
|
|
|
|
namespace Selector.CLI
|
|
|
|
|
{
|
2021-10-24 17:38:45 +01:00
|
|
|
|
static class OptionsHelper {
|
|
|
|
|
public static void ConfigureOptions(RootOptions options, IConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
config.GetSection(RootOptions.Key).Bind(options);
|
|
|
|
|
config.GetSection(FormatKeys( new[] { RootOptions.Key, WatcherOptions.Key})).Bind(options.WatcherOptions);
|
|
|
|
|
config.GetSection(FormatKeys( new[] { RootOptions.Key, DatabaseOptions.Key})).Bind(options.DatabaseOptions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static RootOptions ConfigureOptions(IConfiguration config)
|
|
|
|
|
{
|
|
|
|
|
var options = config.GetSection(RootOptions.Key).Get<RootOptions>();
|
|
|
|
|
ConfigureOptions(options, config);
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string FormatKeys(string[] args) => string.Join(":", args);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 18:17:36 +01:00
|
|
|
|
class RootOptions
|
|
|
|
|
{
|
|
|
|
|
public const string Key = "Selector";
|
|
|
|
|
|
2021-10-11 23:19:19 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Spotify client ID
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ClientId { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Spotify app secret
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string ClientSecret { get; set; }
|
|
|
|
|
public WatcherOptions WatcherOptions { get; set; } = new();
|
2021-10-24 17:38:45 +01:00
|
|
|
|
public DatabaseOptions DatabaseOptions { get; set; } = new();
|
2021-10-11 23:19:19 +01:00
|
|
|
|
public EqualityChecker Equality { get; set; } = EqualityChecker.Uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum EqualityChecker
|
|
|
|
|
{
|
|
|
|
|
Uri, String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class WatcherOptions
|
|
|
|
|
{
|
|
|
|
|
public const string Key = "Watcher";
|
|
|
|
|
|
2021-10-13 23:19:47 +01:00
|
|
|
|
public bool Enabled { get; set; } = true;
|
2021-10-11 23:19:19 +01:00
|
|
|
|
public List<WatcherInstanceOptions> Instances { get; set; } = new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class WatcherInstanceOptions
|
|
|
|
|
{
|
|
|
|
|
public const string Key = "Instances";
|
|
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string AccessKey { get; set; }
|
|
|
|
|
public string RefreshKey { get; set; }
|
|
|
|
|
public int PollPeriod { get; set; } = 5000;
|
|
|
|
|
public WatcherType Type { get; set; } = WatcherType.Player;
|
2021-10-13 23:19:47 +01:00
|
|
|
|
public List<Consumers> Consumers { get; set; } = default;
|
2021-10-12 20:23:25 +01:00
|
|
|
|
#nullable enable
|
2021-10-11 23:19:19 +01:00
|
|
|
|
public string? PlaylistUri { get; set; }
|
2021-10-12 23:29:05 +01:00
|
|
|
|
public string? WatcherCollection { get; set; }
|
2021-10-12 20:23:25 +01:00
|
|
|
|
#nullable disable
|
2021-10-11 23:19:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:19:47 +01:00
|
|
|
|
enum Consumers
|
|
|
|
|
{
|
|
|
|
|
AudioFeatures
|
|
|
|
|
}
|
2021-10-24 17:38:45 +01:00
|
|
|
|
|
|
|
|
|
class DatabaseOptions {
|
|
|
|
|
public const string Key = "Database";
|
|
|
|
|
|
|
|
|
|
public bool Enabled { get; set; } = false;
|
|
|
|
|
public string ConnectionString { get; set; }
|
|
|
|
|
}
|
2021-10-11 18:17:36 +01:00
|
|
|
|
}
|