Skip to content

Commit

Permalink
Fix or suppress some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahStolk committed Mar 29, 2024
1 parent 5aecc65 commit 2a02e5a
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/DevilDaggersInfo.DevUtil.FetchLeaderboard/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
for (int i = 0; i < totalPages; i++)
{
stopwatch.Restart();
entries.AddRange(await Fetch(i * 100 + 1));
entries.AddRange(await FetchAsync(i * 100 + 1));
Console.WriteLine($"Fetching page {i + 1}/{totalPages} took {stopwatch.ElapsedMilliseconds / 1000f} seconds.");

// Write the file after every fetch in case it crashes and all progress is lost.
Expand All @@ -35,15 +35,15 @@ static byte[] GetBytes(List<CompressedEntry> entries)
return ms.ToArray();
}

static async Task<List<CompressedEntry>> Fetch(int rank)
static async Task<List<CompressedEntry>> FetchAsync(int rank)
{
byte[] data = await ExecuteRequest(rank);

int entryCount = BitConverter.ToInt16(data, 59);
int rankIterator = 0;
int bytePos = 83;

List<CompressedEntry> compressedEntries = new();
List<CompressedEntry> compressedEntries = [];
while (rankIterator < entryCount)
{
short usernameLength = BitConverter.ToInt16(data, bytePos);
Expand Down
2 changes: 2 additions & 0 deletions src/DevilDaggersInfo.Web.ApiSpec.Main/Mods/AssetType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace DevilDaggersInfo.Web.ApiSpec.Main.Mods;

#pragma warning disable CA1027 // Not a flag enum.
public enum AssetType : byte

Check warning on line 4 in src/DevilDaggersInfo.Web.ApiSpec.Main/Mods/AssetType.cs

View workflow job for this annotation

GitHub Actions / build

Add a member to AssetType that has a value of zero with a suggested name of 'None' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1008)
#pragma warning restore CA1027
{
Mesh = 0x01,
Texture = 0x02,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace DevilDaggersInfo.Web.ApiSpec.Main.Spawnsets;

#pragma warning disable CA1027 // Not a flag enum.
public enum SpawnsetSorting
#pragma warning restore CA1027
{
Name = 0,
AuthorName = 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public record GetSpawnsetByHashCustomLeaderboard
{
public required int CustomLeaderboardId { get; init; }

public required List<GetSpawnsetByHashCustomEntry> CustomEntries { get; init; } = new();
public required List<GetSpawnsetByHashCustomEntry> CustomEntries { get; init; } = [];
}
4 changes: 2 additions & 2 deletions src/DevilDaggersInfo.Web.Client/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ public static class Constants
public const string DiscordUrl = "https://discord.gg/NF32j8S";
#pragma warning restore S1075 // URIs should not be hardcoded

public static DateTime TrackingCustomLeaderboardSubmitCounts { get; } = new(2020, 8, 25);

// TODO: Move to main and admin API projects?
public const int PageSizeDefault = 25;
public const int PageSizeMin = 15;
public const int PageSizeMax = 35;

public static DateTime TrackingCustomLeaderboardSubmitCounts { get; } = new(2020, 8, 25, 0, 0, 0, DateTimeKind.Utc);

public static IEnumerable<int> PageSizeOptions { get; } = Enumerable.Range(3, 5).Select(i => i * 5);
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public static string GetColor(this CustomLeaderboardCriteriaType criteriaType)
{
return criteriaType switch
{
CustomLeaderboardCriteriaType.GemsCollected => "#f00",// TODO: Use same color as graph
CustomLeaderboardCriteriaType.GemsDespawned => "#888",// TODO: Use same color as graph
CustomLeaderboardCriteriaType.GemsEaten => "#0f0",// TODO: Use same color as graph
CustomLeaderboardCriteriaType.EnemiesKilled => "#f80",// TODO: Use same color as graph
CustomLeaderboardCriteriaType.DaggersFired => "#f80",// TODO: Use same color as graph
CustomLeaderboardCriteriaType.DaggersHit => "#f80",// TODO: Use same color as graph
CustomLeaderboardCriteriaType.GemsCollected => "#f00", // TODO: Use same color as graph
CustomLeaderboardCriteriaType.GemsDespawned => "#888", // TODO: Use same color as graph
CustomLeaderboardCriteriaType.GemsEaten => "#0f0", // TODO: Use same color as graph
CustomLeaderboardCriteriaType.EnemiesKilled => "#f80", // TODO: Use same color as graph
CustomLeaderboardCriteriaType.DaggersFired => "#f80", // TODO: Use same color as graph
CustomLeaderboardCriteriaType.DaggersHit => "#f80", // TODO: Use same color as graph
CustomLeaderboardCriteriaType.HomingStored => UpgradesV3_2.Level4.Color.HexCode,
CustomLeaderboardCriteriaType.HomingEaten => EnemiesV3_2.Ghostpede.Color.HexCode,
CustomLeaderboardCriteriaType.Skull1Kills => EnemiesV3_2.Skull1.Color.HexCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AddModState : IStateObject<AddMod>
public List<int>? PlayerIds { get; set; }

[MaxLength(ModConstants.BinaryMaxFiles, ErrorMessage = ModConstants.BinaryMaxFilesErrorMessage)]
public List<BinaryDataState> Binaries { get; set; } = new();
public List<BinaryDataState> Binaries { get; set; } = [];

[MaxLength(ModConstants.ScreenshotMaxFiles, ErrorMessage = ModConstants.ScreenshotMaxFilesErrorMessage)]
public Dictionary<string, byte[]> Screenshots { get; set; } = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<List<GetPlayerCustomLeaderboardStatistics>> GetCustomLeaderboa
.ToListAsync();

if (customEntries.Count == 0)
return new();
return [];

// ! Navigation property.
Dictionary<(SpawnsetGameMode GameMode, CustomLeaderboardRankSorting RankSorting), int> totalCustomLeaderboards = await _dbContext.CustomLeaderboards
Expand All @@ -57,7 +57,7 @@ public async Task<List<GetPlayerCustomLeaderboardStatistics>> GetCustomLeaderboa
.Select(g => new { g.Key, Count = g.Count() })
.ToDictionaryAsync(a => (a.Key.GameMode, a.Key.RankSorting), a => a.Count);

List<GetPlayerCustomLeaderboardStatistics> stats = new();
List<GetPlayerCustomLeaderboardStatistics> stats = [];
foreach (SpawnsetGameMode gameMode in Enum.GetValues<SpawnsetGameMode>())
{
foreach (CustomLeaderboardRankSorting rankSorting in Enum.GetValues<CustomLeaderboardRankSorting>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace DevilDaggersInfo.Web.Server.Domain.Models.CustomLeaderboards;
// TODO: Immutable.
public record GlobalCustomLeaderboardEntryData
{
public List<CustomLeaderboardRanking> Rankings { get; } = new();
public List<CustomLeaderboardRanking> Rankings { get; } = [];

public int LeviathanCount { get; set; } // TODO: init

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static byte[] CompressData(ushort[] data)
/// </summary>
public static byte[] CompressData(int[] data)
{
if (data.Length == 0 || data.All(i => i <= 0))
if (data.Length == 0 || Array.TrueForAll(data, i => i <= 0))
return Array.Empty<byte>();

byte bitCount = GetBitCount(data.Max());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class DiscordUserIdFetchBackgroundService : AbstractBackgroundService
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly ClubberClient _clubberClient;

public DiscordUserIdFetchBackgroundService(IServiceScopeFactory serviceScopeFactory, ClubberClient clubberClient, BackgroundServiceMonitor backgroundServiceMonitor, ILogger<LeaderboardHistoryBackgroundService> logger)
public DiscordUserIdFetchBackgroundService(IServiceScopeFactory serviceScopeFactory, ClubberClient clubberClient, BackgroundServiceMonitor backgroundServiceMonitor, ILogger<DiscordUserIdFetchBackgroundService> logger)
: base(backgroundServiceMonitor, logger)
{
_serviceScopeFactory = serviceScopeFactory;
Expand Down Expand Up @@ -47,7 +47,7 @@ protected override async Task ExecuteTaskAsync(CancellationToken stoppingToken)
List<int> ids = users.ConvertAll(u => u.LeaderboardId);
List<PlayerEntity> players = dbContext.Players.Where(p => ids.Contains(p.Id) && p.DiscordUserId == null).ToList();

List<(int PlayerId, ulong? OldId, ulong NewId)> logs = new();
List<(int PlayerId, ulong? OldId, ulong NewId)> logs = [];
foreach (PlayerEntity player in players)
{
DdUser? user = users.Where(u => u.LeaderboardId == player.Id).MinBy(u => u.DiscordId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override async Task ExecuteTaskAsync(CancellationToken stoppingToken)
return;

IDdLeaderboardService.LeaderboardResponse? leaderboard = null;
List<IDdLeaderboardService.EntryResponse> entries = new();
List<IDdLeaderboardService.EntryResponse> entries = [];

const int leaderboardPageCount = 5;
const int playerPerPage = 100;
Expand All @@ -39,10 +39,10 @@ protected override async Task ExecuteTaskAsync(CancellationToken stoppingToken)
{
response = await _leaderboardClient.GetLeaderboard(playerPerPage * i + 1, 100);
}
catch (DdLeaderboardException)
catch (DdLeaderboardException ex)
{
const int interval = 5;
Logger.LogWarning("Couldn't get DD leaderboard (page {Page} of {Total}). Waiting {Interval} seconds...", i, leaderboardPageCount, interval);
Logger.LogWarning(ex, "Couldn't get DD leaderboard (page {Page} of {Total}). Waiting {Interval} seconds...", i, leaderboardPageCount, interval);

await Task.Delay(TimeSpan.FromSeconds(interval), stoppingToken);
continue; // Continue without increasing i, so the request is retried.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PlayerNameFetchBackgroundService : AbstractBackgroundService
private readonly IServiceScopeFactory _serviceScopeFactory;
private readonly IDdLeaderboardService _leaderboardClient;

public PlayerNameFetchBackgroundService(IServiceScopeFactory serviceScopeFactory, IDdLeaderboardService leaderboardClient, BackgroundServiceMonitor backgroundServiceMonitor, ILogger<LeaderboardHistoryBackgroundService> logger)
public PlayerNameFetchBackgroundService(IServiceScopeFactory serviceScopeFactory, IDdLeaderboardService leaderboardClient, BackgroundServiceMonitor backgroundServiceMonitor, ILogger<PlayerNameFetchBackgroundService> logger)
: base(backgroundServiceMonitor, logger)
{
_serviceScopeFactory = serviceScopeFactory;
Expand Down Expand Up @@ -39,10 +39,10 @@ protected override async Task ExecuteTaskAsync(CancellationToken stoppingToken)
{
entries = await _leaderboardClient.GetEntriesByIds(playerIds);
}
catch (DdLeaderboardException)
catch (DdLeaderboardException ex)
{
const int interval = 5;
Logger.LogWarning("Couldn't get entries from DD leaderboards. Waiting {Interval} seconds...", interval);
Logger.LogWarning(ex, "Couldn't get entries from DD leaderboards. Waiting {Interval} seconds...", interval);

await Task.Delay(TimeSpan.FromSeconds(interval), stoppingToken);
}
Expand All @@ -51,7 +51,7 @@ protected override async Task ExecuteTaskAsync(CancellationToken stoppingToken)
if (entries == null)
return;

List<(int PlayerId, string OldName, string NewName)> logs = new();
List<(int PlayerId, string OldName, string NewName)> logs = [];
foreach (IDdLeaderboardService.EntryResponse entry in entries)
{
PlayerEntity? player = await dbContext.Players.FirstOrDefaultAsync(p => p.Id == entry.Id, stoppingToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task InvokeAsync(HttpContext context)
{
if (context.Response.HasStarted)
{
_logger.LogWarning("The response has already started, the exception middleware will not be executed.");
_logger.LogWarning(ex, "The response has already started, the exception middleware will not be executed.");
throw;
}

Expand Down

0 comments on commit 2a02e5a

Please sign in to comment.