Skip to content

Commit

Permalink
debugging code
Browse files Browse the repository at this point in the history
  • Loading branch information
devhl-labs committed Apr 4, 2024
1 parent d95216d commit af28c59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CocApi.Cache/CocApi.Cache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Authors>devhl</Authors>
<Product />
<Description>Caches response from the Clash of Clans API.</Description>
<Version>2.11.6-debug.1</Version>
<Version>2.11.6-debug.2</Version>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
19 changes: 19 additions & 0 deletions src/CocApi.Cache/Services/ClanService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public sealed class ClanService : ServiceBase
internal event AsyncEventHandler<ClanWarLeagueGroupUpdatedEventArgs>? ClanWarLeagueGroupUpdated;
internal event AsyncEventHandler<ClanWarLogUpdatedEventArgs>? ClanWarLogUpdated;

public ILogger<ClanService> Logger { get; }

internal IApiFactory ApiFactory { get; }
internal Synchronizer Synchronizer { get; }
Expand All @@ -38,6 +39,7 @@ public ClanService(
: base(logger, scopeFactory, Microsoft.Extensions.Options.Options.Create(options.Value.Clans))
{
Instantiated = Library.WarnOnSubsequentInstantiations(logger, Instantiated);
Logger = logger;
ApiFactory = apiFactory;
Synchronizer = synchronizer;
Ttl = ttl;
Expand Down Expand Up @@ -117,6 +119,9 @@ private async Task TryUpdateAsync(CachedClan cachedClan, CancellationToken cance
if (options.DownloadClan && cachedClan.Download && cachedClan.IsExpired)
tasks.Add(MonitorClanAsync(clansApi, cachedClan, cancellationToken));

if (cachedClan.Tag.Equals("#2PJJPGJ9U"))
Logger.LogWarning("Updating clan #2PJJPGJ9U");

if (options.DownloadCurrentWar && cachedClan.CurrentWar.Download && cachedClan.CurrentWar.IsExpired && ((cachedClan.Download && cachedClan.IsWarLogPublic == true) || !cachedClan.Download))
tasks.Add(MonitorClanWarAsync(clansApi, cachedClan, realTime, cancellationToken));

Expand Down Expand Up @@ -147,14 +152,28 @@ await ClanUpdated

private async Task MonitorClanWarAsync(IClansApi clansApi, CachedClan cachedClan, Option<bool> realtime, CancellationToken cancellationToken)
{
if (cachedClan.Tag.Equals("#2PJJPGJ9U"))
Logger.LogWarning("Checking for war update #2PJJPGJ9U");

CachedClanWar fetched = await CachedClanWar.FromCurrentWarResponseAsync(cachedClan.Tag, realtime, Ttl, clansApi, cancellationToken).ConfigureAwait(false);

if (cachedClan.Tag.Equals("#2PJJPGJ9U"))
Logger.LogWarning("Here is the war\npreparation:{prep}\n{war}", fetched.PreparationStartTime, fetched.Content);

if (fetched.Content != null && CachedClanWar.IsNewWar(cachedClan.CurrentWar, fetched))
{
if (cachedClan.Tag.Equals("#2PJJPGJ9U"))
Logger.LogWarning("it is new");

cachedClan.CurrentWar.Type = fetched.Content.GetWarType();

cachedClan.CurrentWar.Added = false; // flags this war to be added by NewWarMonitor
}
else
{
if (cachedClan.Tag.Equals("#2PJJPGJ9U"))
Logger.LogWarning("it is not new");
}

cachedClan.CurrentWar.UpdateFrom(fetched);
}
Expand Down

0 comments on commit af28c59

Please sign in to comment.