From 0401a6ca83f1aeb03e9059f91424bc4b7f046159 Mon Sep 17 00:00:00 2001 From: MD-V Date: Sat, 18 Nov 2023 21:09:23 +0100 Subject: [PATCH 1/5] Add MatchFactory --- PugSharp.Match.Tests/MatchTests.cs | 22 ++++++++--------- PugSharp.Match/Match.cs | 36 +++++++++++++++------------- PugSharp.Match/MatchFactory.cs | 38 ++++++++++++++++++++++++++++++ PugSharp/Application.cs | 9 ++++--- PugSharp/PugSharp.cs | 9 +++---- 5 files changed, 76 insertions(+), 38 deletions(-) create mode 100644 PugSharp.Match/MatchFactory.cs diff --git a/PugSharp.Match.Tests/MatchTests.cs b/PugSharp.Match.Tests/MatchTests.cs index 2e2744f7..5981c20c 100644 --- a/PugSharp.Match.Tests/MatchTests.cs +++ b/PugSharp.Match.Tests/MatchTests.cs @@ -28,7 +28,7 @@ private static IServiceProvider CreateTestProvider() services.AddSingleton(); services.AddSingleton(); - services.AddTransient(); + services.AddTransient(); services.AddSingleton(); services.AddSingleton(); @@ -46,8 +46,8 @@ public void CreateDotGraphTest() MatchConfig config = CreateExampleConfig(); var serviceProvider = CreateTestProvider(); - var match = serviceProvider.GetRequiredService(); - match.Initialize(config); + var matchFactory = serviceProvider.GetRequiredService(); + var match = matchFactory.CreateMatch(config); var dotGraphString = match.CreateDotGraph(); Assert.True(!string.IsNullOrEmpty(dotGraphString)); @@ -59,8 +59,8 @@ public void WrongPlayerConnectTest() MatchConfig config = CreateExampleConfig(); var serviceProvider = CreateTestProvider(); - var match = serviceProvider.GetRequiredService(); - match.Initialize(config); + var matchFactory = serviceProvider.GetRequiredService(); + var match = matchFactory.CreateMatch(config); Assert.Equal(MatchState.WaitingForPlayersConnectedReady, match.CurrentState); @@ -75,8 +75,8 @@ public void CorrectPlayerConnectTest() MatchConfig config = CreateExampleConfig(); var serviceProvider = CreateTestProvider(); - var match = serviceProvider.GetRequiredService(); - match.Initialize(config); + var matchFactory = serviceProvider.GetRequiredService(); + var match = matchFactory.CreateMatch(config); Assert.Equal(MatchState.WaitingForPlayersConnectedReady, match.CurrentState); @@ -96,8 +96,8 @@ public async Task MatchTest() var csServer = serviceProvider.GetRequiredService(); csServer.LoadAllPlayers().Returns(matchPlayers); - var match = serviceProvider.GetRequiredService(); - match.Initialize(config); + var matchFactory = serviceProvider.GetRequiredService(); + var match = matchFactory.CreateMatch(config); Assert.Equal(MatchState.WaitingForPlayersConnectedReady, match.CurrentState); @@ -121,8 +121,8 @@ public async Task MatchTestWithOneMap() var csServer = serviceProvider.GetRequiredService(); csServer.LoadAllPlayers().Returns(matchPlayers); - var match = serviceProvider.GetRequiredService(); - match.Initialize(config); + var matchFactory = serviceProvider.GetRequiredService(); + var match = matchFactory.CreateMatch(config); Assert.Equal(MatchState.WaitingForPlayersConnectedReady, match.CurrentState); diff --git a/PugSharp.Match/Match.cs b/PugSharp.Match/Match.cs index 4e8e3665..00e00db4 100644 --- a/PugSharp.Match/Match.cs +++ b/PugSharp.Match/Match.cs @@ -35,19 +35,34 @@ public class Match : IDisposable private DemoUploader? _DemoUploader; private readonly List _TeamVotes = new() { new("T"), new("CT") }; - private List? _MapsToSelect; + private List _MapsToSelect = new List(); private MatchTeam? _CurrentMatchTeamToVote; private bool disposedValue; public MatchState CurrentState => _MatchStateMachine.State; - public MatchInfo MatchInfo { get; private set; } = default!; + public MatchInfo MatchInfo { get; private set; } public event EventHandler? MatchFinalized; public IEnumerable AllMatchPlayers => MatchInfo?.MatchTeam1.Players.Concat(MatchInfo.MatchTeam2.Players) ?? Enumerable.Empty(); - public Match(IServiceProvider serviceProvider, ILogger logger, IApiProvider apiProvider, ITextHelper textHelper, ICsServer csServer) + internal Match(IServiceProvider serviceProvider, ILogger logger, IApiProvider apiProvider, ITextHelper textHelper, ICsServer csServer, Config.MatchConfig matchConfig) : + this(serviceProvider, logger, apiProvider, textHelper, csServer) + { + Initialize(new MatchInfo(matchConfig)); + InitializeStateMachine(); + } + + internal Match(IServiceProvider serviceProvider, ILogger logger, IApiProvider apiProvider, ITextHelper textHelper, ICsServer csServer, MatchInfo matchInfo, string roundBackupFile) : + this(serviceProvider, logger, apiProvider, textHelper, csServer) + { + _RoundBackupFile = roundBackupFile; + Initialize(matchInfo); + _Logger.LogInformation("Continue Match on map {mapNumber}({mapName})!", MatchInfo!.CurrentMap.MapNumber, MatchInfo.CurrentMap.MapName); + } + + private Match(IServiceProvider serviceProvider, ILogger logger, IApiProvider apiProvider, ITextHelper textHelper, ICsServer csServer) { _ServiceProvider = serviceProvider; _Logger = logger; @@ -55,6 +70,8 @@ public Match(IServiceProvider serviceProvider, ILogger logger, IApiProvid _TextHelper = textHelper; _CsServer = csServer; _MatchStateMachine = new StateMachine(MatchState.None); + + MatchInfo ??= default!; } private void Initialize(MatchInfo matchInfo) @@ -85,19 +102,6 @@ private void Initialize(MatchInfo matchInfo) } } - public void Initialize(Config.MatchConfig matchConfig) - { - Initialize(new MatchInfo(matchConfig)); - InitializeStateMachine(); - } - - public void Initialize(MatchInfo matchInfo, string roundBackupFile) - { - _RoundBackupFile = roundBackupFile; - Initialize(matchInfo); - _Logger.LogInformation("Continue Match on map {mapNumber}({mapName})!", MatchInfo!.CurrentMap.MapNumber, MatchInfo.CurrentMap.MapName); - } - private void SetServerCulture(string locale) { try diff --git a/PugSharp.Match/MatchFactory.cs b/PugSharp.Match/MatchFactory.cs new file mode 100644 index 00000000..ede73294 --- /dev/null +++ b/PugSharp.Match/MatchFactory.cs @@ -0,0 +1,38 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using PugSharp.Api.Contract; +using PugSharp.Config; +using PugSharp.Server.Contract; +using PugSharp.Translation; + +namespace PugSharp.Match; +public class MatchFactory +{ + private readonly IServiceProvider _ServiceProvider; + + public MatchFactory(IServiceProvider serviceProvider) + { + _ServiceProvider = serviceProvider; + } + + public Match CreateMatch(MatchInfo matchInfo, string roundBackupFile) + { + return new Match(_ServiceProvider, + _ServiceProvider.GetRequiredService>(), + _ServiceProvider.GetRequiredService(), + _ServiceProvider.GetRequiredService(), + _ServiceProvider.GetRequiredService(), + matchInfo, + roundBackupFile); + } + + public Match CreateMatch(MatchConfig matchConfig) + { + return new Match(_ServiceProvider, + _ServiceProvider.GetRequiredService>(), + _ServiceProvider.GetRequiredService(), + _ServiceProvider.GetRequiredService(), + _ServiceProvider.GetRequiredService(), + matchConfig); + } +} diff --git a/PugSharp/Application.cs b/PugSharp/Application.cs index 042017ac..2d454fd5 100644 --- a/PugSharp/Application.cs +++ b/PugSharp/Application.cs @@ -1273,17 +1273,17 @@ private void SetMatchVariable(MatchConfig matchConfig) private void InitializeMatch(MatchConfig matchConfig) { ResetForMatch(matchConfig); - _Match = _ServiceProvider.GetRequiredService(); + var matchFactory = _ServiceProvider.GetRequiredService(); + _Match = matchFactory.CreateMatch(matchConfig); _Match.MatchFinalized += OnMatchFinalized; - _Match.Initialize(matchConfig); } private void InitializeMatch(MatchInfo matchInfo, string roundBackupFile) { ResetForMatch(matchInfo.Config); - _Match = _ServiceProvider.GetRequiredService(); + var matchFactory = _ServiceProvider.GetRequiredService(); + _Match = matchFactory.CreateMatch(matchInfo, roundBackupFile); _Match.MatchFinalized += OnMatchFinalized; - _Match.Initialize(matchInfo, roundBackupFile); } private void OnMatchFinalized(object? sender, MatchFinalizedEventArgs e) @@ -1291,7 +1291,6 @@ private void OnMatchFinalized(object? sender, MatchFinalizedEventArgs e) StopMatch(); } - private void ResetForMatch(MatchConfig matchConfig) { ResetServer(matchConfig.VoteMap); diff --git a/PugSharp/PugSharp.cs b/PugSharp/PugSharp.cs index 07930ab9..48ae3dee 100644 --- a/PugSharp/PugSharp.cs +++ b/PugSharp/PugSharp.cs @@ -8,10 +8,7 @@ using PugSharp.Translation; using CounterStrikeSharp.API.Modules.Utils; using PugSharp.ApiStats; -using NLog.Extensions.Logging; -using Microsoft.Extensions.Configuration; -using NLog.Config; -using NLog.Targets; +using PugSharp.Match; namespace PugSharp; @@ -56,13 +53,13 @@ public override void Load(bool hotReload) services.AddSingleton(); - services.AddTransient(); + services.AddTransient(); // TODO Add HttpClients for ApiProviders services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(services => new TextHelper(services.GetRequiredService>(), ChatColors.Blue, ChatColors.Green, ChatColors.Red)); + services.AddSingleton(sp => new TextHelper(sp.GetRequiredService>(), ChatColors.Blue, ChatColors.Green, ChatColors.Red)); services.AddSingleton(); services.AddSingleton(); From 958d0271ca7c08ddd3de179da684034561cd87ac Mon Sep 17 00:00:00 2001 From: MD-V Date: Sat, 18 Nov 2023 21:42:47 +0100 Subject: [PATCH 2/5] Use HttpClient from DI --- PugSharp.Api.G5Api/G5ApiClient.cs | 49 +++--------------------------- PugSharp.ApiStats/ApiStats.cs | 7 +---- PugSharp.ApiStats/BaseApi.cs | 35 ++++----------------- PugSharp.ApiStats/DemoUploader.cs | 2 +- PugSharp.Match.Tests/MatchTests.cs | 7 ----- PugSharp/Application.cs | 2 +- PugSharp/PugSharp.cs | 24 ++++++++++++++- 7 files changed, 37 insertions(+), 89 deletions(-) diff --git a/PugSharp.Api.G5Api/G5ApiClient.cs b/PugSharp.Api.G5Api/G5ApiClient.cs index 65d2f40b..43613703 100644 --- a/PugSharp.Api.G5Api/G5ApiClient.cs +++ b/PugSharp.Api.G5Api/G5ApiClient.cs @@ -1,27 +1,22 @@ using Microsoft.Extensions.Logging; -using Polly; -using Polly.Extensions.Http; using System.Text; using System.Text.Json; namespace PugSharp.Api.G5Api; -public sealed class G5ApiClient : IDisposable +public sealed class G5ApiClient { - private const int _RetryCount = 3; - private const int _RetryDelayFactor = 2; private readonly ILogger _Logger; - private readonly HttpClient _HttpClient = new(); - private IAsyncPolicy? _RetryPolicy; + private readonly HttpClient _HttpClient; private string? _ApiUrl; private string? _ApiHeader; private string? _ApiHeadeValue; - private bool _DisposedValue; - public G5ApiClient(ILogger logger) + public G5ApiClient(HttpClient httpClient,ILogger logger) { + _HttpClient = httpClient; _Logger = logger; } @@ -36,15 +31,6 @@ public void Initialize(string g5ApiUrl, string g5ApiHeader, string g5ApiHeaderVa { return; } - - _RetryPolicy = HttpPolicyExtensions - .HandleTransientHttpError() - .WaitAndRetryAsync(_RetryCount, - retryAttempt => TimeSpan.FromSeconds(Math.Pow(_RetryDelayFactor, retryAttempt)), - onRetry: (response, calculatedWaitDuration) => - { - _Logger.LogError(response.Exception, "G5Api failed attempt. Waited for {CalculatedWaitDuration}. Retrying.", calculatedWaitDuration); - }); } public void UpdateConfig(string g5ApiUrl, string g5ApiHeader, string g5ApiHeaderValue) @@ -56,11 +42,6 @@ public void UpdateConfig(string g5ApiUrl, string g5ApiHeader, string g5ApiHeader public async Task SendEventAsync(EventBase eventToSend, CancellationToken cancellationToken) { - if (_HttpClient == null || _RetryPolicy == null) - { - return; - } - try { using var jsonContent = new StringContent( @@ -78,8 +59,7 @@ public async Task SendEventAsync(EventBase eventToSend, CancellationToken cancel httpRequest.Headers.Add(_ApiHeader, _ApiHeadeValue); } - using var httpResponseMessage = await _RetryPolicy.ExecuteAsync( - () => _HttpClient.SendAsync(httpRequest, cancellationToken)).ConfigureAwait(false); + using var httpResponseMessage = await _HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (httpResponseMessage == null) { @@ -100,23 +80,4 @@ public async Task SendEventAsync(EventBase eventToSend, CancellationToken cancel _Logger.LogError(ex, "Error sending event to G5 API. EventName {EventName}", eventToSend.EventName); } } - - private void Dispose(bool disposing) - { - if (!_DisposedValue) - { - if (disposing) - { - _HttpClient?.Dispose(); - } - - _DisposedValue = true; - } - } - - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - } } diff --git a/PugSharp.ApiStats/ApiStats.cs b/PugSharp.ApiStats/ApiStats.cs index a8b12af3..b8631832 100644 --- a/PugSharp.ApiStats/ApiStats.cs +++ b/PugSharp.ApiStats/ApiStats.cs @@ -8,7 +8,7 @@ public class ApiStats : BaseApi, IApiProvider { private readonly ILogger _Logger; - public ApiStats(ILogger logger) : base(logger) + public ApiStats(HttpClient httpClient, ILogger logger) : base(httpClient, logger) { _Logger = logger; } @@ -21,11 +21,6 @@ public void Initialize(string? apiStatsUrl, string? apiStatsKey) public async Task GoingLiveAsync(GoingLiveParams goingLiveParams, CancellationToken cancellationToken) { - if (HttpClient == null) - { - return; - } - try { var queryParams = new Dictionary(StringComparer.OrdinalIgnoreCase) diff --git a/PugSharp.ApiStats/BaseApi.cs b/PugSharp.ApiStats/BaseApi.cs index f273744d..7321afa4 100644 --- a/PugSharp.ApiStats/BaseApi.cs +++ b/PugSharp.ApiStats/BaseApi.cs @@ -3,16 +3,15 @@ namespace PugSharp.ApiStats; -public class BaseApi : IDisposable +public class BaseApi { private readonly ILogger _Logger; - private bool _DisposedValue; + protected readonly HttpClient HttpClient; - protected HttpClient? HttpClient { get; private set; } - - protected BaseApi(ILogger logger) + protected BaseApi(HttpClient httpClient, ILogger logger) { + HttpClient = httpClient; _Logger = logger; } @@ -31,10 +30,8 @@ protected void InitializeBase(string? baseUrl, string? authKey) } _Logger.LogInformation("Using BaseURL : \"{url}\" and authKey \"{authKey}\"", baseUrl, authKey); - HttpClient = new HttpClient() - { - BaseAddress = new Uri(baseUrl), - }; + + HttpClient.BaseAddress = new Uri(baseUrl); if (!string.IsNullOrEmpty(authKey)) { @@ -78,24 +75,4 @@ protected async Task HandleResponseAsync(HttpResponseMessage? httpResponseMessag _Logger.LogError(e, "Error handling response"); } } - - protected virtual void Dispose(bool disposing) - { - if (!_DisposedValue) - { - if (disposing) - { - HttpClient?.Dispose(); - } - - _DisposedValue = true; - } - } - - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - GC.SuppressFinalize(this); - } } diff --git a/PugSharp.ApiStats/DemoUploader.cs b/PugSharp.ApiStats/DemoUploader.cs index 86cede58..56b5379b 100644 --- a/PugSharp.ApiStats/DemoUploader.cs +++ b/PugSharp.ApiStats/DemoUploader.cs @@ -6,7 +6,7 @@ public class DemoUploader : BaseApi { private readonly ILogger _Logger; - public DemoUploader(ILogger logger) : base(logger) + public DemoUploader(HttpClient httpClient, ILogger logger) : base(httpClient, logger) { _Logger = logger; } diff --git a/PugSharp.Match.Tests/MatchTests.cs b/PugSharp.Match.Tests/MatchTests.cs index 5981c20c..902cf04f 100644 --- a/PugSharp.Match.Tests/MatchTests.cs +++ b/PugSharp.Match.Tests/MatchTests.cs @@ -2,8 +2,6 @@ using Microsoft.Extensions.Logging; using NSubstitute; using PugSharp.Api.Contract; -using PugSharp.Api.Json; -using PugSharp.ApiStats; using PugSharp.Config; using PugSharp.Match.Contract; using PugSharp.Server.Contract; @@ -29,12 +27,7 @@ private static IServiceProvider CreateTestProvider() services.AddSingleton(); services.AddTransient(); - - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(Substitute.For()); - services.AddSingleton(); // Build service provider return services.BuildServiceProvider(); diff --git a/PugSharp/Application.cs b/PugSharp/Application.cs index 2d454fd5..4dcb456c 100644 --- a/PugSharp/Application.cs +++ b/PugSharp/Application.cs @@ -1308,7 +1308,7 @@ private void ResetForMatch(MatchConfig matchConfig) { var g5Stats = _ServiceProvider.GetRequiredService(); g5Stats.Initialize(matchConfig.G5ApiUrl, matchConfig.G5ApiHeader ?? string.Empty, matchConfig.G5ApiHeaderValue ?? string.Empty); - var g5ApiProvider = new G5ApiProvider(g5Stats, _CsServer); + var g5ApiProvider = _ServiceProvider.GetRequiredService(); _Plugin.RegisterConsoleCommandAttributeHandlers(g5ApiProvider); _ApiProvider.AddApiProvider(g5ApiProvider); } diff --git a/PugSharp/PugSharp.cs b/PugSharp/PugSharp.cs index 48ae3dee..020e437f 100644 --- a/PugSharp/PugSharp.cs +++ b/PugSharp/PugSharp.cs @@ -9,11 +9,17 @@ using CounterStrikeSharp.API.Modules.Utils; using PugSharp.ApiStats; using PugSharp.Match; +using Polly.Extensions.Http; +using Polly; +using PugSharp.Api.G5Api; namespace PugSharp; public class PugSharp : BasePlugin, IBasePlugin { + private const int _RetryCount = 3; + private const int _RetryDelayFactor = 2; + private ServiceProvider? _ServiceProvider; private IApplication? _Application; @@ -55,12 +61,28 @@ public override void Load(bool hotReload) services.AddTransient(); - // TODO Add HttpClients for ApiProviders + var retryPolicy = HttpPolicyExtensions + .HandleTransientHttpError() + .WaitAndRetryAsync(_RetryCount, + retryAttempt => TimeSpan.FromSeconds(Math.Pow(_RetryDelayFactor, retryAttempt))); + + services.AddHttpClient() + .AddPolicyHandler(retryPolicy); + services.AddSingleton(); services.AddSingleton(); + + services.AddHttpClient() + .AddPolicyHandler(retryPolicy); services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(sp => new TextHelper(sp.GetRequiredService>(), ChatColors.Blue, ChatColors.Green, ChatColors.Red)); + + services.AddHttpClient() + .AddPolicyHandler(retryPolicy); services.AddSingleton(); + services.AddSingleton(); // Build service provider From 28936cc1b0137c21086bc014ac2a1cb5e2280631 Mon Sep 17 00:00:00 2001 From: MD-V Date: Sat, 18 Nov 2023 21:57:26 +0100 Subject: [PATCH 3/5] Add HttpClient to ConfigProvider Add note for G5Api todo --- PugSharp.Config/ConfigProvider.cs | 32 ++++--------------------------- PugSharp/G5CommandProvider.cs | 1 + PugSharp/PugSharp.cs | 11 +++++++---- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/PugSharp.Config/ConfigProvider.cs b/PugSharp.Config/ConfigProvider.cs index ecadcf0b..42e80317 100644 --- a/PugSharp.Config/ConfigProvider.cs +++ b/PugSharp.Config/ConfigProvider.cs @@ -6,17 +6,18 @@ namespace PugSharp.Config; -public class ConfigProvider : IDisposable +public class ConfigProvider { + private readonly HttpClient _HttpClient; private readonly ILogger _Logger; - private readonly HttpClient _HttpClient = new(); private string _ConfigDirectory = string.Empty; private bool _DisposedValue; - public ConfigProvider(ILogger logger) + public ConfigProvider(HttpClient httpClient, ILogger logger) { + _HttpClient = httpClient; _Logger = logger; } @@ -68,7 +69,6 @@ public async Task, MatchConfig>> LoadMatchConfigFromUrlAsync RequestUri = new Uri(url), }; - if (!string.IsNullOrEmpty(authToken)) { httpRequestMessage.Headers.Add(HeaderNames.Authorization, authToken); @@ -115,28 +115,4 @@ public async Task, MatchConfig>> LoadMatchConfigFromUrlAsync return new Error($"Failed loading config from {url}."); } } - - #region IDisposable - - protected virtual void Dispose(bool disposing) - { - if (!_DisposedValue) - { - if (disposing) - { - _HttpClient.Dispose(); - } - - _DisposedValue = true; - } - } - - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - - #endregion } diff --git a/PugSharp/G5CommandProvider.cs b/PugSharp/G5CommandProvider.cs index bf564a78..4fda2f54 100644 --- a/PugSharp/G5CommandProvider.cs +++ b/PugSharp/G5CommandProvider.cs @@ -88,6 +88,7 @@ private IEnumerable CommandEndMatch(string[] arg) private IEnumerable CommandLoadMatchUrl(string[] args) { + // TODO reply from G5Api is different than the callback from eventula! All the cvars are ignored _CsServer.ExecuteCommand($"ps_loadconfig {string.Join(' ', args.Skip(1).Where(x => !x.Contains("Authorization", StringComparison.OrdinalIgnoreCase)).Select(x => $"\"{x}\""))}"); return Enumerable.Empty(); } diff --git a/PugSharp/PugSharp.cs b/PugSharp/PugSharp.cs index 020e437f..9446ffbc 100644 --- a/PugSharp/PugSharp.cs +++ b/PugSharp/PugSharp.cs @@ -57,15 +57,18 @@ public override void Load(bool hotReload) services.AddSingleton(); - services.AddSingleton(); - - services.AddTransient(); - var retryPolicy = HttpPolicyExtensions .HandleTransientHttpError() .WaitAndRetryAsync(_RetryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(_RetryDelayFactor, retryAttempt))); + services.AddHttpClient() + .AddPolicyHandler(retryPolicy); + + services.AddSingleton(); + + services.AddTransient(); + services.AddHttpClient() .AddPolicyHandler(retryPolicy); services.AddSingleton(); From 2ed9863de8ce96cce6ad3842ae7ddf6af06e83db Mon Sep 17 00:00:00 2001 From: MD-V Date: Sat, 18 Nov 2023 22:02:44 +0100 Subject: [PATCH 4/5] Remove using --- PugSharp.Config/ConfigProvider.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/PugSharp.Config/ConfigProvider.cs b/PugSharp.Config/ConfigProvider.cs index 42e80317..93d385b1 100644 --- a/PugSharp.Config/ConfigProvider.cs +++ b/PugSharp.Config/ConfigProvider.cs @@ -12,8 +12,6 @@ public class ConfigProvider private readonly ILogger _Logger; private string _ConfigDirectory = string.Empty; - private bool _DisposedValue; - public ConfigProvider(HttpClient httpClient, ILogger logger) { From 11d7e90d30efddee15bf9672491a416e1cd4ba2a Mon Sep 17 00:00:00 2001 From: TheR00st3r Date: Sun, 19 Nov 2023 12:24:13 +0100 Subject: [PATCH 5/5] Resolve Warnings --- PugSharp.Api.G5Api/G5ApiClient.cs | 5 ----- PugSharp.ApiStats/ApiStats.cs | 5 ----- PugSharp.Match/Match.cs | 3 ++- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/PugSharp.Api.G5Api/G5ApiClient.cs b/PugSharp.Api.G5Api/G5ApiClient.cs index 43613703..ab122ccc 100644 --- a/PugSharp.Api.G5Api/G5ApiClient.cs +++ b/PugSharp.Api.G5Api/G5ApiClient.cs @@ -26,11 +26,6 @@ public void Initialize(string g5ApiUrl, string g5ApiHeader, string g5ApiHeaderVa _ApiUrl = g5ApiUrl; _ApiHeader = g5ApiHeader; _ApiHeadeValue = g5ApiHeaderValue; - - if (string.IsNullOrEmpty(g5ApiUrl)) - { - return; - } } public void UpdateConfig(string g5ApiUrl, string g5ApiHeader, string g5ApiHeaderValue) diff --git a/PugSharp.ApiStats/ApiStats.cs b/PugSharp.ApiStats/ApiStats.cs index b8631832..756c16a6 100644 --- a/PugSharp.ApiStats/ApiStats.cs +++ b/PugSharp.ApiStats/ApiStats.cs @@ -187,11 +187,6 @@ public async Task FinalizeAsync(SeriesResultParams seriesResultParams, Cancellat return; } - if (HttpClient == null) - { - return; - } - var queryParams = new Dictionary(StringComparer.OrdinalIgnoreCase) { {ApiStatsConstants.StatsSeriesWinner, seriesResultParams.WinnerTeamName}, diff --git a/PugSharp.Match/Match.cs b/PugSharp.Match/Match.cs index 00e00db4..35872510 100644 --- a/PugSharp.Match/Match.cs +++ b/PugSharp.Match/Match.cs @@ -29,7 +29,7 @@ public class Match : IDisposable private readonly IApiProvider _ApiProvider; private readonly ITextHelper _TextHelper; private readonly ICsServer _CsServer; - private string _RoundBackupFile = string.Empty; + private readonly string _RoundBackupFile = string.Empty; private readonly StateMachine _MatchStateMachine; private DemoUploader? _DemoUploader; @@ -59,6 +59,7 @@ internal Match(IServiceProvider serviceProvider, ILogger logger, IApiProv { _RoundBackupFile = roundBackupFile; Initialize(matchInfo); + InitializeStateMachine(); _Logger.LogInformation("Continue Match on map {mapNumber}({mapName})!", MatchInfo!.CurrentMap.MapNumber, MatchInfo.CurrentMap.MapName); }