// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.Web.AdminPanel; using System.IO; using Blazored.Toast; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting.StaticWebAssets; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; using MUnique.OpenMU.DataModel; using MUnique.OpenMU.DataModel.Configuration; using MUnique.OpenMU.DataModel.Entities; using MUnique.OpenMU.Persistence; using MUnique.OpenMU.Persistence.Initialization.Updates; using MUnique.OpenMU.Persistence.Initialization.VersionSeasonSix; using MUnique.OpenMU.Web.AdminPanel.Components; using MUnique.OpenMU.Web.AdminPanel.Services; using MUnique.OpenMU.Web.Shared.Components.Modal; using MUnique.OpenMU.Web.Shared.Models; using MUnique.OpenMU.Web.Shared.Services; /// /// Extensions for the . /// public static class WebApplicationExtensions { /// /// Adds the map application to the web app. /// When using the DaprService, call the BuildAndConfigure-Method with the parameter to add Blazor. /// /// The web application builder which should be configured. /// If set to true, the map app is included. /// /// The web application builder. /// public static WebApplicationBuilder AddAdminPanel(this WebApplicationBuilder builder, bool includeMapApp = false) { // Ensure that DataInitialization plugins will get collected - for the setup functionality. _ = DataInitialization.Id; var services = builder.Services; var supportedCultures = CultureHelper .GetAvailableCultures() .Select(culture => culture.TwoLetterISOLanguageName) .ToArray(); services.AddLocalization() .Configure(o => { o.AddSupportedCultures(supportedCultures); o.AddSupportedUICultures(supportedCultures); }); services.AddRazorComponents() .AddInteractiveServerComponents(); if (includeMapApp) { AdminPanelEnvironment.IsHostingEmbedded = true; } services.AddControllers() .ConfigureApplicationPartManager(setup => setup.FeatureProviders.Add(new GenericControllerFeatureProvider())); services.AddBlazoredToast(); services.AddScoped(); services.AddScoped(sp => sp.GetRequiredService()); services.AddScoped(); services.AddScoped(); services.AddSingleton, GameConfigurationDataSource>(); services.AddSingleton, AccountDataSource>(); services.AddSingleton(); services.AddSingleton(); services.AddScoped(); services.AddScoped(); services.AddScoped>(serviceProvider => serviceProvider.GetService()!); services.AddScoped(); services.AddScoped>(serviceProvider => serviceProvider.GetService()!); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped>(serviceProvider => serviceProvider.GetService()!); services.AddScoped(); services.AddScoped>(serviceProvider => serviceProvider.GetService()!); StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration); return builder; } /// /// Configures the admin panel. /// /// The application. /// The configured web application. public static WebApplication ConfigureAdminPanel(this WebApplication app) { if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error", createScopeForErrors: true); } app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "logs")), RequestPath = "/logs", }); app.UseAntiforgery(); app.MapStaticAssets(); app.UseRequestLocalization(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); app.MapControllers(); AdminPanelEnvironment.IsHostingEmbedded = true; return app; } }