fix refactor issue
This commit is contained in:
parent
8730a3fab8
commit
505a2c4c2d
@ -34,6 +34,7 @@ using IW4MAdmin.Plugins.Stats.Client.Abstractions;
|
||||
using IW4MAdmin.Plugins.Stats.Client;
|
||||
using Stats.Client.Abstractions;
|
||||
using Stats.Client;
|
||||
using Stats.Config;
|
||||
using Stats.Helpers;
|
||||
|
||||
namespace IW4MAdmin.Application
|
||||
@ -346,6 +347,8 @@ namespace IW4MAdmin.Application
|
||||
await defaultConfigHandler.BuildAsync();
|
||||
var commandConfigHandler = new BaseConfigurationHandler<CommandConfiguration>("CommandConfiguration");
|
||||
await commandConfigHandler.BuildAsync();
|
||||
var statsCommandHandler = new BaseConfigurationHandler<StatsConfiguration>();
|
||||
await statsCommandHandler.BuildAsync();
|
||||
var defaultConfig = defaultConfigHandler.Configuration();
|
||||
var appConfig = appConfigHandler.Configuration();
|
||||
var masterUri = Utilities.IsDevelopment
|
||||
@ -386,6 +389,7 @@ namespace IW4MAdmin.Application
|
||||
.AddSingleton((IConfigurationHandler<ApplicationConfiguration>) appConfigHandler)
|
||||
.AddSingleton<IConfigurationHandler<CommandConfiguration>>(commandConfigHandler)
|
||||
.AddSingleton(appConfig)
|
||||
.AddSingleton(statsCommandHandler.Configuration() ?? new StatsConfiguration())
|
||||
.AddSingleton(serviceProvider =>
|
||||
serviceProvider.GetRequiredService<IConfigurationHandler<CommandConfiguration>>()
|
||||
.Configuration() ?? new CommandConfiguration())
|
||||
|
@ -179,17 +179,15 @@ namespace IW4MAdmin.Application.Misc
|
||||
manager.AdditionalEventParsers.Add(eventParser);
|
||||
manager.AdditionalRConParsers.Add(rconParser);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
var configWrapper = new ScriptPluginConfigurationWrapper(Name, _scriptEngine);
|
||||
await configWrapper.InitializeAsync();
|
||||
_scriptEngine.SetValue("_configHandler", configWrapper);
|
||||
await OnLoadAsync(manager);
|
||||
}
|
||||
}
|
||||
|
||||
catch (RuntimeBinderException) { }
|
||||
catch (RuntimeBinderException)
|
||||
{
|
||||
var configWrapper = new ScriptPluginConfigurationWrapper(Name, _scriptEngine);
|
||||
await configWrapper.InitializeAsync();
|
||||
_scriptEngine.SetValue("_configHandler", configWrapper);
|
||||
await OnLoadAsync(manager);
|
||||
}
|
||||
|
||||
if (!firstRun)
|
||||
{
|
||||
|
@ -3,9 +3,7 @@ using Stats.Client.Abstractions;
|
||||
using Stats.Client.Game;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using IW4MAdmin.Plugins.Stats.Config;
|
||||
using SharedLibraryCore;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using Stats.Config;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
@ -16,10 +14,10 @@ namespace Stats.Client
|
||||
private readonly ILogger _logger;
|
||||
private readonly StatsConfiguration _config;
|
||||
|
||||
public WeaponNameParser(ILogger<WeaponNameParser> logger, IConfigurationHandler<StatsConfiguration> config)
|
||||
public WeaponNameParser(ILogger<WeaponNameParser> logger, StatsConfiguration config)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config.Configuration();
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public WeaponInfo Parse(string weaponName, Server.Game gameName)
|
||||
@ -67,4 +65,4 @@ namespace Stats.Client
|
||||
return weaponInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
private readonly ConcurrentDictionary<long, ServerStats> _servers;
|
||||
private readonly ILogger _log;
|
||||
private readonly IDatabaseContextFactory _contextFactory;
|
||||
private readonly IConfigurationHandler<StatsConfiguration> _configHandler;
|
||||
private readonly StatsConfiguration _config;
|
||||
private static List<EFServer> serverModels;
|
||||
public static string CLIENT_STATS_KEY = "ClientStats";
|
||||
public static string CLIENT_DETECTIONS_KEY = "ClientDetections";
|
||||
@ -47,13 +47,13 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
private readonly IServerDistributionCalculator _serverDistributionCalculator;
|
||||
|
||||
public StatManager(ILogger<StatManager> logger, IManager mgr, IDatabaseContextFactory contextFactory,
|
||||
IConfigurationHandler<StatsConfiguration> configHandler,
|
||||
StatsConfiguration statsConfig,
|
||||
IServerDistributionCalculator serverDistributionCalculator)
|
||||
{
|
||||
_servers = new ConcurrentDictionary<long, ServerStats>();
|
||||
_log = logger;
|
||||
_contextFactory = contextFactory;
|
||||
_configHandler = configHandler;
|
||||
_config = statsConfig;
|
||||
_serverDistributionCalculator = serverDistributionCalculator;
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
r.When > fifteenDaysAgo &&
|
||||
r.RatingHistory.Client.Level != EFClient.Permission.Banned &&
|
||||
r.Newest &&
|
||||
r.ActivityAmount >= _configHandler.Configuration().TopPlayersMinPlayTime;
|
||||
r.ActivityAmount >= _config.TopPlayersMinPlayTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -87,7 +87,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
{
|
||||
await using var context = _contextFactory.CreateContext(enableTracking: false);
|
||||
|
||||
if (_configHandler.Configuration().EnableAdvancedMetrics)
|
||||
if (_config.EnableAdvancedMetrics)
|
||||
{
|
||||
var clientRanking = await context.Set<EFClientRankingHistory>()
|
||||
.Where(r => r.ClientId == clientId)
|
||||
@ -126,7 +126,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
&& ranking.PerformanceMetric != null
|
||||
&& ranking.Newest
|
||||
&& ranking.Client.TotalConnectionTime >=
|
||||
_configHandler.Configuration().TopPlayersMinPlayTime;
|
||||
_config.TopPlayersMinPlayTime;
|
||||
}
|
||||
|
||||
public async Task<int> GetTotalRankedPlayers(long serverId)
|
||||
@ -217,7 +217,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
|
||||
public async Task<List<TopStatsInfo>> GetTopStats(int start, int count, long? serverId = null)
|
||||
{
|
||||
if (_configHandler.Configuration().EnableAdvancedMetrics)
|
||||
if (_config.EnableAdvancedMetrics)
|
||||
{
|
||||
return await GetNewTopStats(start, count, serverId);
|
||||
}
|
||||
@ -570,7 +570,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
{
|
||||
clientStats = UpdateStats(clientStats, pl);
|
||||
await SaveClientStats(clientStats);
|
||||
if (_configHandler.Configuration().EnableAdvancedMetrics)
|
||||
if (_config.EnableAdvancedMetrics)
|
||||
{
|
||||
await UpdateHistoricalRanking(pl.ClientId, clientStats, serverId);
|
||||
}
|
||||
@ -973,7 +973,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
|
||||
// update their performance
|
||||
if ((DateTime.UtcNow - attackerStats.LastStatHistoryUpdate).TotalMinutes >=
|
||||
(Utilities.IsDevelopment ? 0.5 : _configHandler.Configuration().EnableAdvancedMetrics ? 5.0 : 2.5))
|
||||
(Utilities.IsDevelopment ? 0.5 : _config.EnableAdvancedMetrics ? 5.0 : 2.5))
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -982,7 +982,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
// for stat history update, but one is already processing that invalidates the original
|
||||
await attackerStats.ProcessingHit.WaitAsync(Utilities.DefaultCommandTimeout,
|
||||
Plugin.ServerManager.CancellationToken);
|
||||
if (_configHandler.Configuration().EnableAdvancedMetrics)
|
||||
if (_config.EnableAdvancedMetrics)
|
||||
{
|
||||
await UpdateHistoricalRanking(attacker.ClientId, attackerStats, serverId);
|
||||
}
|
||||
@ -1190,7 +1190,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
public async Task UpdateHistoricalRanking(int clientId, EFClientStatistics clientStats, long serverId)
|
||||
{
|
||||
await using var context = _contextFactory.CreateContext();
|
||||
var minPlayTime = _configHandler.Configuration().TopPlayersMinPlayTime;
|
||||
var minPlayTime = _config.TopPlayersMinPlayTime;
|
||||
|
||||
var performances = await context.Set<EFClientStatistics>()
|
||||
.AsNoTracking()
|
||||
@ -1208,7 +1208,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
|
||||
var serverRanking = await context.Set<EFClientStatistics>()
|
||||
.Where(stats => stats.ClientId != clientStats.ClientId)
|
||||
.Where(AdvancedClientStatsResourceQueryHelper.GetRankingFunc(
|
||||
_configHandler.Configuration().TopPlayersMinPlayTime, clientStats.ZScore, serverId))
|
||||
_config.TopPlayersMinPlayTime, clientStats.ZScore, serverId))
|
||||
.CountAsync();
|
||||
|
||||
var serverRankingSnapshot = new EFClientRankingHistory
|
||||
|
@ -442,7 +442,7 @@ namespace IW4MAdmin.Plugins.Stats
|
||||
}
|
||||
|
||||
ServerManager = manager;
|
||||
Manager = new StatManager(_managerLogger, manager, _databaseContextFactory, Config, _serverDistributionCalculator);
|
||||
Manager = new StatManager(_managerLogger, manager, _databaseContextFactory, Config.Configuration(), _serverDistributionCalculator);
|
||||
await _serverDistributionCalculator.Initialize();
|
||||
}
|
||||
|
||||
|
@ -19,13 +19,12 @@ namespace WebfrontCore.Controllers
|
||||
public class ClientController : BaseController
|
||||
{
|
||||
private readonly IMetaService _metaService;
|
||||
private readonly IConfigurationHandler<StatsConfiguration> _configurationHandler;
|
||||
private readonly StatsConfiguration _config;
|
||||
|
||||
public ClientController(IManager manager, IMetaService metaService,
|
||||
IConfigurationHandler<StatsConfiguration> configurationHandler) : base(manager)
|
||||
public ClientController(IManager manager, IMetaService metaService, StatsConfiguration config) : base(manager)
|
||||
{
|
||||
_metaService = metaService;
|
||||
_configurationHandler = configurationHandler;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> ProfileAsync(int id, MetaType? metaFilterType)
|
||||
@ -114,7 +113,7 @@ namespace WebfrontCore.Controllers
|
||||
ViewBag.Title += " " + Localization["WEBFRONT_CLIENT_PROFILE_TITLE"];
|
||||
ViewBag.Description = $"Client information for {strippedName}";
|
||||
ViewBag.Keywords = $"IW4MAdmin, client, profile, {strippedName}";
|
||||
ViewBag.UseNewStats = _configurationHandler.Configuration()?.EnableAdvancedMetrics ?? true;
|
||||
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
|
||||
|
||||
return View("Profile/Index", clientDto);
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ namespace WebfrontCore.Controllers
|
||||
|
||||
public ClientStatisticsController(IManager manager,
|
||||
IResourceQueryHelper<StatsInfoRequest, AdvancedStatsInfo> queryHelper,
|
||||
IConfigurationHandler<DefaultSettings> configurationHandler) : base(manager)
|
||||
DefaultSettings defaultConfig) : base(manager)
|
||||
{
|
||||
_queryHelper = queryHelper;
|
||||
_defaultConfig = configurationHandler.Configuration();
|
||||
_defaultConfig = defaultConfig;
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}/advanced")]
|
||||
@ -35,4 +35,4 @@ namespace WebfrontCore.Controllers
|
||||
return View("~/Views/Client/Statistics/Advanced.cshtml", hitInfo.Results.First());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,19 +27,18 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
|
||||
private readonly IResourceQueryHelper<ChatSearchQuery, MessageResponse> _chatResourceQueryHelper;
|
||||
private readonly ITranslationLookup _translationLookup;
|
||||
private readonly IDatabaseContextFactory _contextFactory;
|
||||
private readonly IConfigurationHandler<StatsConfiguration> _configurationHandler;
|
||||
private readonly StatsConfiguration _config;
|
||||
|
||||
public StatsController(ILogger<StatsController> logger, IManager manager, IResourceQueryHelper<ChatSearchQuery,
|
||||
MessageResponse> resourceQueryHelper, ITranslationLookup translationLookup,
|
||||
IDatabaseContextFactory contextFactory,
|
||||
IConfigurationHandler<StatsConfiguration> configurationHandler) : base(manager)
|
||||
IDatabaseContextFactory contextFactory, StatsConfiguration config) : base(manager)
|
||||
{
|
||||
_logger = logger;
|
||||
_manager = manager;
|
||||
_chatResourceQueryHelper = resourceQueryHelper;
|
||||
_translationLookup = translationLookup;
|
||||
_contextFactory = contextFactory;
|
||||
_configurationHandler = configurationHandler;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -70,7 +69,7 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
|
||||
serverId = StatManager.GetIdForServer(server);
|
||||
}
|
||||
|
||||
var results = _configurationHandler.Configuration().EnableAdvancedMetrics
|
||||
var results = _config?.EnableAdvancedMetrics ?? true
|
||||
? await Plugin.Manager.GetNewTopStats(offset, count, serverId)
|
||||
: await Plugin.Manager.GetTopStats(offset, count, serverId);
|
||||
|
||||
@ -80,7 +79,7 @@ namespace IW4MAdmin.Plugins.Web.StatsWeb.Controllers
|
||||
return Ok();
|
||||
}
|
||||
|
||||
ViewBag.UseNewStats = _configurationHandler.Configuration().EnableAdvancedMetrics;
|
||||
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics;
|
||||
return View("~/Views/Client/Statistics/Components/TopPlayers/_List.cshtml", results);
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ namespace WebfrontCore
|
||||
services.AddSingleton(Program.ApplicationServiceProvider
|
||||
.GetRequiredService<IConfigurationHandler<DefaultSettings>>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider
|
||||
.GetRequiredService<IConfigurationHandler<StatsConfiguration>>());
|
||||
.GetRequiredService<StatsConfiguration>());
|
||||
services.AddSingleton(Program.ApplicationServiceProvider.GetRequiredService<IServerDataViewer>());
|
||||
}
|
||||
|
||||
|
@ -3,18 +3,17 @@ using System.Threading.Tasks;
|
||||
using IW4MAdmin.Plugins.Stats;
|
||||
using IW4MAdmin.Plugins.Stats.Helpers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using Stats.Config;
|
||||
|
||||
namespace WebfrontCore.ViewComponents
|
||||
{
|
||||
public class TopPlayersViewComponent : ViewComponent
|
||||
{
|
||||
private readonly IConfigurationHandler<StatsConfiguration> _configurationHandler;
|
||||
private readonly StatsConfiguration _config;
|
||||
|
||||
public TopPlayersViewComponent(IConfigurationHandler<StatsConfiguration> configurationHandler)
|
||||
public TopPlayersViewComponent(StatsConfiguration config)
|
||||
{
|
||||
_configurationHandler = configurationHandler;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync(int count, int offset, long? serverId = null)
|
||||
@ -32,7 +31,7 @@ namespace WebfrontCore.ViewComponents
|
||||
}
|
||||
|
||||
|
||||
ViewBag.UseNewStats = _configurationHandler.Configuration()?.EnableAdvancedMetrics ?? true;
|
||||
ViewBag.UseNewStats = _config?.EnableAdvancedMetrics ?? true;
|
||||
return View("~/Views/Client/Statistics/Components/TopPlayers/_List.cshtml",
|
||||
ViewBag.UseNewStats
|
||||
? await Plugin.Manager.GetNewTopStats(offset, count, serverId)
|
||||
|
Loading…
Reference in New Issue
Block a user