2021-10-08 23:48:07 +01:00
|
|
|
|
using System;
|
2021-10-11 01:06:43 +01:00
|
|
|
|
using System.Threading.Tasks;
|
2021-10-08 23:48:07 +01:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-10-11 01:06:43 +01:00
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-10-08 23:48:07 +01:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2021-10-11 01:06:43 +01:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2021-10-11 18:17:36 +01:00
|
|
|
|
using NLog.Extensions.Logging;
|
2021-10-08 23:48:07 +01:00
|
|
|
|
|
|
|
|
|
namespace Selector.CLI
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2021-10-11 01:06:43 +01:00
|
|
|
|
public static async Task Main(string[] args)
|
2021-10-08 23:48:07 +01:00
|
|
|
|
{
|
2021-10-11 01:06:43 +01:00
|
|
|
|
var host = CreateHostBuilder(args);
|
|
|
|
|
await host.RunConsoleAsync();
|
2021-10-08 23:48:07 +01:00
|
|
|
|
}
|
2021-10-11 01:06:43 +01:00
|
|
|
|
|
|
|
|
|
static IHostBuilder CreateHostBuilder(string[] args)
|
|
|
|
|
=> Host.CreateDefaultBuilder(args)
|
|
|
|
|
.ConfigureServices((context, services) => {
|
2021-10-11 18:17:36 +01:00
|
|
|
|
|
2021-10-13 23:19:47 +01:00
|
|
|
|
Console.WriteLine("~~~ Selector CLI ~~~");
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
|
2021-10-15 19:58:07 +01:00
|
|
|
|
Console.WriteLine("> Configuring...");
|
2021-10-11 18:17:36 +01:00
|
|
|
|
// CONFIG
|
2021-10-11 23:19:19 +01:00
|
|
|
|
services.Configure<RootOptions>(options => {
|
|
|
|
|
context.Configuration.GetSection(RootOptions.Key).Bind(options);
|
|
|
|
|
context.Configuration.GetSection($"{RootOptions.Key}:{WatcherOptions.Key}").Bind(options.WatcherOptions);
|
|
|
|
|
});
|
2021-10-15 19:58:07 +01:00
|
|
|
|
var config = context.Configuration.GetSection(RootOptions.Key).Get<RootOptions>();
|
2021-10-11 18:17:36 +01:00
|
|
|
|
|
2021-10-15 19:58:07 +01:00
|
|
|
|
Console.WriteLine("> Adding Services...");
|
2021-10-11 18:17:36 +01:00
|
|
|
|
// SERVICES
|
2021-10-12 23:29:05 +01:00
|
|
|
|
services.AddSingleton<IWatcherFactory, WatcherFactory>();
|
2021-10-13 23:19:47 +01:00
|
|
|
|
services.AddSingleton<IConsumerFactory, AudioFeatureInjectorFactory>();
|
2021-10-12 23:29:05 +01:00
|
|
|
|
services.AddSingleton<IWatcherCollectionFactory, WatcherCollectionFactory>();
|
|
|
|
|
// For generating spotify clients
|
2021-10-15 19:58:07 +01:00
|
|
|
|
//services.AddSingleton<IRefreshTokenFactoryProvider, RefreshTokenFactoryProvider>();
|
|
|
|
|
services.AddSingleton<IRefreshTokenFactoryProvider, CachingRefreshTokenFactoryProvider>();
|
2021-10-11 23:19:19 +01:00
|
|
|
|
|
2021-10-15 19:58:07 +01:00
|
|
|
|
switch(config.Equality)
|
2021-10-11 23:19:19 +01:00
|
|
|
|
{
|
|
|
|
|
case EqualityChecker.Uri:
|
2021-10-15 19:58:07 +01:00
|
|
|
|
Console.WriteLine("> Using Uri Equality");
|
2021-10-11 23:19:19 +01:00
|
|
|
|
services.AddTransient<IEqual, UriEqual>();
|
|
|
|
|
break;
|
|
|
|
|
case EqualityChecker.String:
|
2021-10-15 19:58:07 +01:00
|
|
|
|
Console.WriteLine("> Using String Equality");
|
2021-10-11 23:19:19 +01:00
|
|
|
|
services.AddTransient<IEqual, StringEqual>();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-10-11 18:17:36 +01:00
|
|
|
|
|
|
|
|
|
// HOSTED SERVICES
|
2021-10-15 19:58:07 +01:00
|
|
|
|
if(config.WatcherOptions.Enabled)
|
2021-10-13 23:19:47 +01:00
|
|
|
|
{
|
2021-10-15 19:58:07 +01:00
|
|
|
|
Console.WriteLine("> Adding Watcher Service");
|
2021-10-13 23:19:47 +01:00
|
|
|
|
services.AddHostedService<WatcherService>();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 01:06:43 +01:00
|
|
|
|
})
|
2021-10-11 18:17:36 +01:00
|
|
|
|
.ConfigureLogging((context, builder) => {
|
|
|
|
|
builder.ClearProviders();
|
|
|
|
|
builder.SetMinimumLevel(LogLevel.Trace);
|
|
|
|
|
builder.AddNLog(context.Configuration);
|
2021-10-11 01:06:43 +01:00
|
|
|
|
});
|
2021-10-08 23:48:07 +01:00
|
|
|
|
}
|
|
|
|
|
}
|