using BlazorDownloadFile; using BlazorTable; using CurrieTechnologies.Razor.SweetAlert2; using HealthChecks.UI.Client; using Logging.Net; using Moonlight.App.ApiClients.CloudPanel; using Moonlight.App.ApiClients.Daemon; using Moonlight.App.ApiClients.Paper; using Moonlight.App.ApiClients.Wings; using Moonlight.App.Database; using Moonlight.App.Diagnostics.HealthChecks; using Moonlight.App.Events; using Moonlight.App.Helpers; using Moonlight.App.Helpers.Wings; using Moonlight.App.LogMigrator; using Moonlight.App.Repositories; using Moonlight.App.Repositories.Domains; using Moonlight.App.Repositories.LogEntries; using Moonlight.App.Repositories.Servers; using Moonlight.App.Services; using Moonlight.App.Services.Background; using Moonlight.App.Services.DiscordBot; using Moonlight.App.Services.Files; using Moonlight.App.Services.Interop; using Moonlight.App.Services.LogServices; using Moonlight.App.Services.Mail; using Moonlight.App.Services.Minecraft; using Moonlight.App.Services.Notifications; using Moonlight.App.Services.Sessions; using Moonlight.App.Services.Statistics; using Moonlight.App.Services.SupportChat; namespace Moonlight { public class Program { // App version. Change for release public static readonly string AppVersion = $"InDev {Formatter.FormatDateOnly(DateTime.Now.Date)}"; public static async Task Main(string[] args) { Logger.UsedLogger = new CacheLogger(); Logger.Info($"Working dir: {Directory.GetCurrentDirectory()}"); Logger.Info("Running pre-init tasks"); // This will also copy all default config files var configService = new ConfigService(new StorageService()); var databaseCheckupService = new DatabaseCheckupService(configService); await databaseCheckupService.Perform(); var builder = WebApplication.CreateBuilder(args); // Switch to logging.net injection // TODO: Enable in production //builder.Logging.ClearProviders(); //builder.Logging.AddProvider(new LogMigratorProvider()); // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor() .AddHubOptions(options => { options.MaximumReceiveMessageSize = 10000000; options.ClientTimeoutInterval = TimeSpan.FromSeconds(30); options.HandshakeTimeout = TimeSpan.FromSeconds(10); }); builder.Services.AddHttpContextAccessor(); builder.Services.AddHealthChecks() .AddCheck("Database") .AddCheck("Nodes") .AddCheck("Daemons"); // Databases builder.Services.AddDbContext(); // Repositories builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(typeof(Repository<>)); // Services builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); // Loggers builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); // Support chat builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); // Helpers builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); // Background services builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); // Third party services builder.Services.AddBlazorTable(); builder.Services.AddSweetAlert2(options => { options.Theme = SweetAlertTheme.Dark; }); builder.Services.AddBlazorContextMenu(); builder.Services.AddBlazorDownloadFile(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseStaticFiles(); app.UseRouting(); app.UseWebSockets(); app.MapControllers(); app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); app.MapHealthChecks("/_health", new() { ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); // AutoStart services _ = app.Services.GetRequiredService(); _ = app.Services.GetRequiredService(); _ = app.Services.GetRequiredService(); _ = app.Services.GetRequiredService(); _ = app.Services.GetRequiredService(); // Discord bot service //var discordBotService = app.Services.GetRequiredService(); await app.RunAsync(); } } }