using System; using System.Collections.Generic; using Microsoft.Extensions.Configuration; namespace Selector.Web { static class OptionsHelper { public static void ConfigureOptions(RootOptions options, IConfiguration config) { config.GetSection(RootOptions.Key).Bind(options); config.GetSection(FormatKeys(new[] { RootOptions.Key, RedisOptions.Key })).Bind(options.RedisOptions); config.GetSection(FormatKeys(new[] { RootOptions.Key, NowPlayingOptions.Key })).Bind(options.NowOptions); config.GetSection(FormatKeys(new[] { RootOptions.Key, PastOptions.Key })).Bind(options.PastOptions); } public static RootOptions ConfigureOptions(IConfiguration config) { var options = config.GetSection(RootOptions.Key).Get(); ConfigureOptions(options, config); return options; } public static string FormatKeys(string[] args) => string.Join(":", args); } public class RootOptions { public const string Key = "Selector"; /// /// Spotify client ID /// public string ClientId { get; set; } /// /// Spotify app secret /// public string ClientSecret { get; set; } /// /// Spotify callback for authentication /// public string SpotifyCallback { get; set; } public string LastfmClient { get; set; } public string LastfmSecret { get; set; } public TimeSpan CookieExpiry { get; set; } = TimeSpan.FromDays(30); public RedisOptions RedisOptions { get; set; } = new(); public NowPlayingOptions NowOptions { get; set; } = new(); public PastOptions PastOptions { get; set; } = new(); } public class RedisOptions { public const string Key = "Redis"; public bool Enabled { get; set; } = false; public string ConnectionString { get; set; } } }