Improved implementation of ApplicationContext

This commit is contained in:
Chomp
2025-01-14 12:23:44 +00:00
parent f0b534a6e0
commit b9a5835bd2
3 changed files with 31 additions and 10 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
using Core.Annotations;
using Core.Annotations;
using Core.Context;
using Core.Controllers;
using Core.Models.Eft.Bot;
@@ -60,7 +60,7 @@ public class BotCallbacks
if (difficulty == "core")
return _httpResponseUtil.NoBody(_botController.GetBotCoreDifficulty());
var raidConfig = (GetRaidConfigurationRequestData)_applicationContext.GetLatestValue(ContextVariableType.RAID_CONFIGURATION)?.Value;
var raidConfig = _applicationContext.GetLatestValue(ContextVariableType.RAID_CONFIGURATION)?.GetValue<GetRaidConfigurationRequestData>();
return _httpResponseUtil.NoBody(_botController.GetBotDifficulty(type, difficulty, raidConfig));
}
+2 -2
View File
@@ -1,4 +1,4 @@
using Core.Annotations;
using Core.Annotations;
using Core.Context;
using Core.DI;
using Core.Servers;
@@ -18,7 +18,7 @@ public class HttpCallbacks : OnLoad
public async Task OnLoad()
{
_httpServer.Load((WebApplicationBuilder) _applicationContext.GetLatestValue(ContextVariableType.APP_BUILDER).Value);
_httpServer.Load( _applicationContext.GetLatestValue(ContextVariableType.APP_BUILDER).GetValue<WebApplicationBuilder>());
_applicationContext.ClearValues(ContextVariableType.APP_BUILDER);
}
+27 -6
View File
@@ -1,8 +1,29 @@
namespace Core.Context;
namespace Core.Context;
public class ContextVariable(object value, ContextVariableType contextVariableType)
public class ContextVariable
{
public object Value { get; } = value;
public DateTime Timestamp { get; } = DateTime.Now;
public ContextVariableType Type { get; } = contextVariableType;
}
private readonly object _value;
private readonly ContextVariableType _internalType;
private readonly DateTime _timestamp;
public ContextVariable(object value, ContextVariableType contextVariableInternalType)
{
_value = value;
_timestamp = DateTime.Now;
_internalType = contextVariableInternalType;
}
public T GetValue<T>() {
return (T)_value;
}
public DateTime GetTimestamp()
{
return _timestamp;
}
public ContextVariableType GetContextType()
{
return _internalType;
}
}