diff --git a/Clients/CirrusCiClient/CirrusCi.cs b/Clients/CirrusCiClient/CirrusCi.cs index 5db19d60..8a6db0a9 100644 --- a/Clients/CirrusCiClient/CirrusCi.cs +++ b/Clients/CirrusCiClient/CirrusCi.cs @@ -37,27 +37,27 @@ public static class CirrusCi queryResult.EnsureNoErrors(); if (queryResult.Data?.OwnerRepository?.Builds?.Edges is {Count: > 0} edgeList) { - var node = edgeList.LastOrDefault(e => e?.Node?.ChangeIdInRepo == commit)?.Node; + var node = edgeList.LastOrDefault(e => e.Node.ChangeIdInRepo == commit)?.Node; if (node is null) return null; - var winTask = node.Tasks?.FirstOrDefault(t => t?.Name.Contains("Windows") ?? false); - var winArtifact = winTask?.Artifacts? - .Where(a => a?.Files is {Count: >0}) - .SelectMany(a => a!.Files!) - .FirstOrDefault(f => f?.Path.EndsWith(".7z") ?? false); + var winTask = node.Tasks.FirstOrDefault(t => t.Name.Contains("Windows")); + var winArtifact = winTask?.Artifacts + .Where(a => a.Files is {Count: >0}) + .SelectMany(a => a.Files) + .FirstOrDefault(f => f.Path.EndsWith(".7z")); - var linTask = node.Tasks?.FirstOrDefault(t => t is {} lt && lt.Name.Contains("Linux") && lt.Name.Contains("GCC")); - var linArtifact = linTask?.Artifacts? - .Where(a => a?.Files is {Count: >0}) - .SelectMany(a => a!.Files!) - .FirstOrDefault(a => a?.Path.EndsWith(".AppImage") ?? false); + var linTask = node.Tasks.FirstOrDefault(t => t is {} lt && lt.Name.Contains("Linux") && lt.Name.Contains("GCC")); + var linArtifact = linTask?.Artifacts + .Where(a => a.Files is {Count: >0}) + .SelectMany(a => a.Files) + .FirstOrDefault(a => a.Path.EndsWith(".AppImage")); - var macTask = node.Tasks?.FirstOrDefault(t => t?.Name.Contains("macOS") ?? false); - var macArtifact = macTask?.Artifacts? - .Where(a => a?.Files is { Count: > 0 }) - .SelectMany(a => a!.Files!) - .FirstOrDefault(a => a?.Path.EndsWith(".dmg") ?? false); + var macTask = node.Tasks.FirstOrDefault(t => t.Name.Contains("macOS")); + var macArtifact = macTask?.Artifacts + .Where(a => a.Files is { Count: > 0 }) + .SelectMany(a => a.Files) + .FirstOrDefault(a => a.Path.EndsWith(".dmg")); var startTime = FromTimestamp(node.BuildCreatedTimestamp); var finishTime = GetFinishTime(node); @@ -142,7 +142,7 @@ public static class CirrusCi ? FromTimestamp(finalTimes.Max()!.Value) : node.ClockDurationInSeconds > 0 ? FromTimestamp(node.BuildCreatedTimestamp).AddSeconds(node.ClockDurationInSeconds.Value) - : (DateTime?)null; + : null; [return: NotNullIfNotNull(nameof(DateTime))] private static string? ToTimestamp(this DateTime? dateTime) => dateTime.HasValue ? (dateTime.Value.ToUniversalTime() - DateTime.UnixEpoch).TotalMilliseconds.ToString("0") : null; diff --git a/Clients/CompatApiClient/ApiConfig.cs b/Clients/CompatApiClient/ApiConfig.cs index c26f10c5..ccb47d04 100644 --- a/Clients/CompatApiClient/ApiConfig.cs +++ b/Clients/CompatApiClient/ApiConfig.cs @@ -22,59 +22,57 @@ public static class ApiConfig public static readonly ReturnCodeType ReturnCodes = new() { - {0, (true, false, true, "Results successfully retrieved.")}, - {1, (false, false, true, "No results.") }, - {2, (true, false, true, "No match was found, displaying results for: ***{0}***.") }, - {-1, (false, true, false, "{0}: Internal error occurred, please contact Ani and Nicba1010") }, - {-2, (false, true, false, "{0}: API is undergoing maintenance, please try again later.") }, - {-3, (false, false, false, "Illegal characters found, please try again with a different search term.") }, + [0] = (true, false, true, "Results successfully retrieved."), + [1] = (false, false, true, "No results."), + [2] = (true, false, true, "No match was found, displaying results for: ***{0}***."), + [-1] = (false, true, false, "{0}: Internal error occurred, please contact Ani and Nicba1010"), + [-2] = (false, true, false, "{0}: API is undergoing maintenance, please try again later."), + [-3] = (false, false, false, "Illegal characters found, please try again with a different search term."), }; public static readonly List ResultAmount = [25, 50, 100, 200]; public static readonly Dictionary Directions = new() { - {'a', ["a", "asc", "ascending"] }, - {'d', ["d", "desc", "descending"] }, + ['a'] = ["a", "asc", "ascending"], + ['d'] = ["d", "desc", "descending"], }; public static readonly Dictionary Statuses = new() { - {"all", 0 }, - {"playable", 1 }, - {"ingame", 2 }, - {"intro", 3 }, - {"loadable", 4 }, - {"nothing", 5 }, + ["all"] = 0, + ["playable"] = 1, + ["ingame"] = 2, + ["intro"] = 3, + ["loadable"] = 4, + ["nothing"] = 5, }; public static readonly Dictionary SortTypes = new() { - {"id", 1 }, - {"title", 2 }, - {"status", 3 }, - {"date", 4 }, + ["id"] = 1, + ["title"] = 2, + ["status"] = 3, + ["date"] = 4, }; public static readonly Dictionary ReleaseTypes = new() { - {'b', ["b", "d", "disc", "disk", "bluray", "blu-ray"] }, - {'n', ["n", "p", "PSN"] }, + ['b'] = ["b", "d", "disc", "disk", "bluray", "blu-ray"], + ['n'] = ["n", "p", "PSN"], }; public static readonly Dictionary ReverseDirections; public static readonly Dictionary ReverseReleaseTypes; private static Dictionary Reverse(this Dictionary dic, IEqualityComparer comparer) - where TK: notnull - where TV: notnull - { - return ( + where TK : notnull + where TV : notnull + => ( from kvp in dic from val in kvp.Value select (val, kvp.Key) ).ToDictionary(rkvp => rkvp.val, rkvp => rkvp.Key, comparer); - } public static readonly ILogger Log; public static readonly RecyclableMemoryStreamManager MemoryStreamManager = new(); diff --git a/Clients/CompatApiClient/Client.cs b/Clients/CompatApiClient/Client.cs index 78dd24ac..820f98c3 100644 --- a/Clients/CompatApiClient/Client.cs +++ b/Clients/CompatApiClient/Client.cs @@ -22,7 +22,7 @@ public class Client: IDisposable public Client() { client = HttpClientFactory.Create(new CompressionMessageHandler()); - jsonOptions = new JsonSerializerOptions + jsonOptions = new() { PropertyNamingPolicy = SpecialJsonNamingPolicy.SnakeCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, @@ -46,7 +46,7 @@ public class Client: IDisposable using var response = await client.SendAsync(message, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false); try { - await response.Content.LoadIntoBufferAsync().ConfigureAwait(false); + await response.Content.LoadIntoBufferAsync(cancellationToken).ConfigureAwait(false); var result = await response.Content.ReadFromJsonAsync(jsonOptions, cancellationToken).ConfigureAwait(false); if (result != null) { @@ -84,7 +84,7 @@ public class Client: IDisposable using var response = await client.SendAsync(message, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false); try { - await response.Content.LoadIntoBufferAsync().ConfigureAwait(false); + await response.Content.LoadIntoBufferAsync(cancellationToken).ConfigureAwait(false); result = await response.Content.ReadFromJsonAsync(jsonOptions, cancellationToken).ConfigureAwait(false); if (result != null) ResponseCache.Set(url, result, TimeSpan.FromDays(1)); diff --git a/Clients/CompatApiClient/CompatApiClient.csproj b/Clients/CompatApiClient/CompatApiClient.csproj index 02186697..cfe44126 100644 --- a/Clients/CompatApiClient/CompatApiClient.csproj +++ b/Clients/CompatApiClient/CompatApiClient.csproj @@ -3,13 +3,6 @@ net9.0 enable - - - - latest - - - latest diff --git a/Clients/CompatApiClient/Compression/CompressionMessageHandler.cs b/Clients/CompatApiClient/Compression/CompressionMessageHandler.cs index ea8196b1..8a834c4c 100644 --- a/Clients/CompatApiClient/Compression/CompressionMessageHandler.cs +++ b/Clients/CompatApiClient/Compression/CompressionMessageHandler.cs @@ -21,11 +21,7 @@ public class CompressionMessageHandler : DelegatingHandler { this.isServer = isServer; isClient = !isServer; - Compressors = new ICompressor[] - { - new GZipCompressor(), - new DeflateCompressor(), - }; + Compressors = [new GZipCompressor(), new DeflateCompressor()]; } protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) diff --git a/Clients/CompatApiClient/Utils/UriExtensions.cs b/Clients/CompatApiClient/Utils/UriExtensions.cs index 54be0020..46e07aad 100644 --- a/Clients/CompatApiClient/Utils/UriExtensions.cs +++ b/Clients/CompatApiClient/Utils/UriExtensions.cs @@ -76,7 +76,7 @@ public static class UriExtensions if (value == null) continue; - result.AppendFormat("&{0}={1}", Uri.EscapeDataString(key), Uri.EscapeDataString(value)); + result.Append($"&{Uri.EscapeDataString(key)}={Uri.EscapeDataString(value)}"); } if (result.Length == 0) return ""; @@ -103,7 +103,7 @@ public static class UriExtensions } else { - var startWithSlash = uri.OriginalString.StartsWith("/"); + var startWithSlash = uri.OriginalString.StartsWith('/'); uri = new(FakeHost, uri); var builder = new UriBuilder(uri) { Query = value }; var additionalStrip = startWithSlash ? 0 : 1; diff --git a/Clients/IrdLibraryClient/IrdFormat/IrdParser.cs b/Clients/IrdLibraryClient/IrdFormat/IrdParser.cs index cf2d4e92..71ea47ca 100644 --- a/Clients/IrdLibraryClient/IrdFormat/IrdParser.cs +++ b/Clients/IrdLibraryClient/IrdFormat/IrdParser.cs @@ -47,11 +47,11 @@ public static class IrdParser result.FooterLength = reader.ReadInt32(); result.Footer = reader.ReadBytes(result.FooterLength); result.RegionCount = reader.ReadByte(); - result.RegionMd5Checksums = new List(result.RegionCount); + result.RegionMd5Checksums = new(result.RegionCount); for (var i = 0; i < result.RegionCount; i++) result.RegionMd5Checksums.Add(reader.ReadBytes(16)); result.FileCount = reader.ReadInt32(); - result.Files = new List(result.FileCount); + result.Files = new(result.FileCount); for (var i = 0; i < result.FileCount; i++) { // ReSharper disable once UseObjectOrCollectionInitializer