93 lines
2.6 KiB
C#
Executable file
93 lines
2.6 KiB
C#
Executable file
#pragma warning disable IDE0079
|
|
#pragma warning disable IDE0005
|
|
global using static Program;
|
|
#pragma warning restore
|
|
|
|
// Media Organizer
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using ConsoleAppFramework;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration.Json;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.FileProviders;
|
|
|
|
ConfigurationManager configuration = new();
|
|
ManifestEmbeddedFileProvider embeddedFileProvider = new(typeof(Program).Assembly, "Properties");
|
|
configuration.Sources.Insert(0, new JsonConfigurationSource()
|
|
{
|
|
FileProvider = embeddedFileProvider,
|
|
Path = "appsettings.json",
|
|
Optional = true,
|
|
ReloadOnChange = true
|
|
});
|
|
|
|
configuration.AddEnvironmentVariables("DOTNET_");
|
|
|
|
const string environment =
|
|
#if DEBUG
|
|
"Development"
|
|
#else
|
|
"Production"
|
|
#endif
|
|
;
|
|
var environmentAppSettingsName = $"appsettings.{configuration.GetValue("Environment", environment)}.json";
|
|
|
|
configuration.Sources.Insert(2, new JsonConfigurationSource()
|
|
{
|
|
FileProvider = embeddedFileProvider,
|
|
Path = environmentAppSettingsName,
|
|
Optional = true,
|
|
ReloadOnChange = true
|
|
});
|
|
PhysicalFileProvider baseDirectoryFileProvider = new(AppContext.BaseDirectory);
|
|
configuration.Sources.Insert(3, new JsonConfigurationSource()
|
|
{
|
|
FileProvider = baseDirectoryFileProvider,
|
|
Path = "appsettings.json",
|
|
Optional = true,
|
|
ReloadOnChange = true
|
|
});
|
|
configuration.Sources.Insert(4, new JsonConfigurationSource()
|
|
{
|
|
FileProvider = baseDirectoryFileProvider,
|
|
Path = environmentAppSettingsName,
|
|
Optional = true,
|
|
ReloadOnChange = true
|
|
});
|
|
PhysicalFileProvider currentDirectoryFileProvider = new(Environment.CurrentDirectory);
|
|
configuration.Sources.Insert(5, new JsonConfigurationSource()
|
|
{
|
|
FileProvider = currentDirectoryFileProvider,
|
|
Path = "appsettings.json",
|
|
Optional = true,
|
|
ReloadOnChange = true
|
|
});
|
|
configuration.Sources.Insert(6, new JsonConfigurationSource()
|
|
{
|
|
FileProvider = currentDirectoryFileProvider,
|
|
Path = environmentAppSettingsName,
|
|
Optional = true,
|
|
ReloadOnChange = true
|
|
});
|
|
|
|
// Configuration Sources:
|
|
// - Embedded: Properties\appsettings.json
|
|
// - InMemory
|
|
// - Embedded: Properties\appsettings.${Environment}.json
|
|
// - Physical: BaseDirectory\appsettings.json
|
|
// - Physical: BaseDirectory\appsettings${Environment}.json
|
|
// - Physical: CurrentDirectory\appsettings.json
|
|
// - Physical: CurrentDirectory\appsettings${Environment}.json
|
|
|
|
ServiceCollection services = new();
|
|
services.AddSingleton<IConfiguration>(configuration);
|
|
services.AddOptions();
|
|
ConsoleApp.ServiceProvider = services.BuildServiceProvider();
|
|
ConsoleApp.Create().Run(args);
|
|
|
|
internal static partial class Program
|
|
{
|
|
}
|