Improved implementation of ApplicationContext
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user