From 50d744e9d739388ea46f688ba91c216a000421b7 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 Jan 2025 11:43:22 +0000 Subject: [PATCH] fixed load order --- Core/Context/ContextVariableType.cs | 3 ++- Core/DI/OnLoadOrder.cs | 16 ++++++++-------- Core/Servers/HttpServer.cs | 2 +- Core/Utils/App.cs | 9 +++++---- Server/Program.cs | 13 ++++++++++++- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Core/Context/ContextVariableType.cs b/Core/Context/ContextVariableType.cs index 878a0b3b..3221f1fc 100644 --- a/Core/Context/ContextVariableType.cs +++ b/Core/Context/ContextVariableType.cs @@ -18,5 +18,6 @@ public enum ContextVariableType /** Data returned from client request object from endLocalRaid() */ TRANSIT_INFO = 5, APP_BUILDER = 6, - LOADED_MOD_ASSEMBLIES = 6 + LOADED_MOD_ASSEMBLIES = 7, + WEB_APPLICATION = 8 } diff --git a/Core/DI/OnLoadOrder.cs b/Core/DI/OnLoadOrder.cs index 82ba878c..9e9b75d7 100644 --- a/Core/DI/OnLoadOrder.cs +++ b/Core/DI/OnLoadOrder.cs @@ -5,12 +5,12 @@ public static class OnLoadOrder public const int Database = 0; public const int PostDBModLoader = 1; public const int HandbookCallbacks = 2; - public const int PresetCallbacks = 3; - public const int SaveCallbacks = 4; - public const int TraderCallbacks = 5; - public const int RagfairPriceService = 6; - public const int RagfairCallbacks = 7; - public const int ModCallbacks = 8; - public const int GameCallbacks = 9; - public const int HttpCallbacks = 10; + public const int HttpCallbacks = 3; + public const int PresetCallbacks = 4; + public const int SaveCallbacks = 5; + public const int TraderCallbacks = 6; + public const int RagfairPriceService = 7; + public const int RagfairCallbacks = 8; + public const int ModCallbacks = 9; + public const int GameCallbacks = 10; } diff --git a/Core/Servers/HttpServer.cs b/Core/Servers/HttpServer.cs index ed6b9342..d21ebc10 100644 --- a/Core/Servers/HttpServer.cs +++ b/Core/Servers/HttpServer.cs @@ -59,7 +59,7 @@ public class HttpServer }); // app.UseEndpoints(endpointBuilder => { endpointBuilder.MapFallback(HandleFallback); }); started = true; - app.Run($"http://{httpConfig.Ip}:{httpConfig.Port}"); + _applicationContext.AddValue(ContextVariableType.WEB_APPLICATION, app); } private Task HandleFallback(HttpContext context) diff --git a/Core/Utils/App.cs b/Core/Utils/App.cs index 9635b0ad..6c7a3421 100644 --- a/Core/Utils/App.cs +++ b/Core/Utils/App.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Core.Annotations; using Core.DI; using Core.Models.Enums; @@ -49,7 +50,7 @@ public class App _coreConfig = configServer.GetConfig(ConfigTypes.CORE); } - public async Task Load() + public async Task Run() { // execute onLoad callbacks _logger.Info(_localisationService.GetText("executing_startup_callbacks")); @@ -86,10 +87,10 @@ public class App Console.WriteLine($"finish Onload: {onLoad.GetRoute()}"); } - var timer = new Timer(_ => + new Timer(_ => { Console.WriteLine($"Start OnUpdate"); - update(_onUpdate); + Update(_onUpdate); Console.WriteLine($"Finish OnUpdate"); }, @@ -98,7 +99,7 @@ public class App TimeSpan.FromMilliseconds(5000)); } - protected async Task update(IEnumerable onUpdateComponents) + protected async Task Update(IEnumerable onUpdateComponents) { // If the server has failed to start, skip any update calls if (!_httpServer.IsStarted() || !_databaseService.IsDatabaseValid()) return; diff --git a/Server/Program.cs b/Server/Program.cs index ac1217c7..a128af0f 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -1,6 +1,10 @@ using System.Reflection; +using System.Security.Cryptography; using Core.Annotations; using Core.Context; +using Core.Models.Enums; +using Core.Models.Spt.Config; +using Core.Servers; using Core.Utils; namespace Server; @@ -24,9 +28,16 @@ public static class Program // TODO: var preSptModLoader = serviceProvider.GetService(); var app = serviceProvider.GetService(); var appContext = serviceProvider.GetService(); + // These are the mod assemblies we are gonna use on the PreSpt, PostDb and PostSpt loaders appContext.AddValue(ContextVariableType.LOADED_MOD_ASSEMBLIES, assemblies); + // This is the builder that will get use by the HttpServer to start up the web application appContext.AddValue(ContextVariableType.APP_BUILDER, builder); - app.Load().Wait(); + app.Run().Wait(); + + var httpConfig = serviceProvider.GetService().GetConfig(ConfigTypes.HTTP); + // When we application gets started by the HttpServer it will add into the AppContext the WebApplication + // object, which we can use here to start the webapp. + (appContext.GetLatestValue(ContextVariableType.WEB_APPLICATION).Value as WebApplication).Run($"http://{httpConfig.Ip}:{httpConfig.Port}"); } catch (Exception ex) {