diff --git a/Manager.App/DependencyInjection.cs b/Manager.App/DependencyInjection.cs index 04b0e1c..ad2dbaa 100644 --- a/Manager.App/DependencyInjection.cs +++ b/Manager.App/DependencyInjection.cs @@ -1,12 +1,29 @@ using DotBased.Logging; using DotBased.Logging.MEL; using DotBased.Logging.Serilog; +using Manager.App.Models.Settings; using Serilog; namespace Manager.App; public static class DependencyInjection { + public static void SetupSettings(this WebApplicationBuilder builder) + { + builder.Services.AddOptions() + .Bind(builder.Configuration.GetSection("Library")) + .ValidateDataAnnotations() + .PostConfigure(settings => + { + settings.Path = settings.Path.Replace("{workdir}", Environment.CurrentDirectory, StringComparison.InvariantCultureIgnoreCase); + }) + .ValidateOnStart(); + builder.Services.AddOptions() + .Bind(builder.Configuration.GetSection("Downloads")) + .ValidateDataAnnotations() + .ValidateOnStart(); + } + public static void SetupLogging(this WebApplicationBuilder builder) { var isDevelopment = builder.Environment.IsDevelopment(); diff --git a/Manager.App/Models/Settings/DownloadSettings.cs b/Manager.App/Models/Settings/DownloadSettings.cs new file mode 100644 index 0000000..86b4409 --- /dev/null +++ b/Manager.App/Models/Settings/DownloadSettings.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; + +namespace Manager.App.Models.Settings; + +public class DownloadSettings +{ + [ConfigurationKeyName("MaxConcurrentDownloads")] + [Range(-1, 20)] + public int MaxConcurrentDownloads { get; set; } +} \ No newline at end of file diff --git a/Manager.App/Models/Settings/LibrarySettings.cs b/Manager.App/Models/Settings/LibrarySettings.cs new file mode 100644 index 0000000..813cd58 --- /dev/null +++ b/Manager.App/Models/Settings/LibrarySettings.cs @@ -0,0 +1,10 @@ +using System.ComponentModel.DataAnnotations; + +namespace Manager.App.Models.Settings; + +public class LibrarySettings +{ + [ConfigurationKeyName("Path")] + [Required] + public required string Path { get; set; } +} \ No newline at end of file diff --git a/Manager.App/Program.cs b/Manager.App/Program.cs index f8f59b7..8b4fa63 100644 --- a/Manager.App/Program.cs +++ b/Manager.App/Program.cs @@ -8,10 +8,10 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); -builder.SetupLogging(); /* App setup */ - +builder.SetupLogging(); +builder.SetupSettings(); /* MudBlazor */ builder.Services.AddMudServices(); diff --git a/Manager.App/appsettings.Development.json b/Manager.App/appsettings.Development.json index 876c4e3..771cac8 100644 --- a/Manager.App/appsettings.Development.json +++ b/Manager.App/appsettings.Development.json @@ -16,5 +16,11 @@ "Default": "Trace", "Microsoft.AspNetCore": "Debug" } + }, + "Library": { + "Path": "{workdir}/" + }, + "Downloads": { + "MaxConcurrentDownloads": 5 } } diff --git a/Manager.App/appsettings.json b/Manager.App/appsettings.json index b044c11..f0fea47 100644 --- a/Manager.App/appsettings.json +++ b/Manager.App/appsettings.json @@ -17,5 +17,11 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "Library": { + "Path": "{workdir}/Library" + }, + "Downloads": { + "MaxConcurrentDownloads": 5 + } }