using System.Net; using AutoMapper; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.FileProviders; using OnecMonitor.Server; using OnecMonitor.Server.AutoMapper; using OnecMonitor.Server.Helpers; using OnecMonitor.Server.Hubs; using OnecMonitor.Server.Services; using OneSwiss.Common.Services; var builder = WebApplication.CreateBuilder(args); builder.Services.AddWindowsService(options => { options.ServiceName = "OnecMonitor"; }); builder.Services.AddSystemd(); builder.WebHost.ConfigureKestrel((context, options) => { options.AllowSynchronousIO = true; options.Limits.MaxRequestBodySize = long.MaxValue; // configure http listener var host = context.Configuration.GetValue("OnecMonitor:Http:Host", "0.0.0.0"); var port = context.Configuration.GetValue("OnecMonitor:Http:Port", 7002); options.Listen(IPAddress.Parse(host), port, configure => { configure.Protocols = HttpProtocols.Http1; }); }); builder.Services.AddSignalR(opt => { opt.EnableDetailedErrors = true; opt.MaximumReceiveMessageSize = 20 * 1024 * 1024; }); builder.Services.AddAutoMapper(typeof(DtoProfile)); builder.Services.AddAutoMapper(typeof(CommonProfile)); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddControllersWithViews(); builder.Services.AddScoped(); builder.Services.AddDbContext(); builder.Services.AddCors(); builder.Services.AddHostedService(sp => sp.GetRequiredService()); builder.Services.AddSingleton(); builder.Services.AddHostedService(); builder.Services.AddHostedService(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseDefaultFiles(); app.UseStaticFiles(); var dataPath = Path.Combine(builder.Environment.ContentRootPath, "Data"); if (!Path.Exists(dataPath)) Directory.CreateDirectory(dataPath); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(dataPath), RequestPath = "/Data" }); app.UseRouting(); app.UseWebSockets(); app.UseCors(options => { options.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .Build(); }); await using var scope = app.Services.CreateAsyncScope(); var appDbContext = scope.ServiceProvider.GetRequiredService(); await appDbContext.Database.MigrateAsync(); // Init techlog repository settings var mapper = scope.ServiceProvider.GetRequiredService(); var techLogManager = scope.ServiceProvider.GetRequiredService(); TechLogHelper.UpdateTechLogSettings(mapper, techLogManager, appDbContext); app.MapHub("/MaintenanceTaskLogs"); app.MapControllerRoute( name: "default", pattern: "{controller=Agents}/{action=Index}/{id?}"); app.Run();