Final Rider inspections

This commit is contained in:
Archi
2022-12-15 19:23:46 +01:00
parent c9cae6e258
commit fc20b6cfc4
12 changed files with 35 additions and 22 deletions

View File

@@ -21,7 +21,6 @@
using System;
using System.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
using System.Threading;
using System.Threading.Tasks;

View File

@@ -36,7 +36,7 @@ internal static class AprilFools {
internal static void Init(object? state = null) {
DateTime now = DateTime.Now;
if ((now.Month == 4) && (now.Day == 1)) {
if (now is { Month: 4, Day: 1 }) {
try {
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CreateSpecificCulture(SharedInfo.LolcatCultureName);
} catch (Exception e) {

View File

@@ -75,7 +75,7 @@ public sealed class TypeController : ArchiController {
}
}
foreach (PropertyInfo property in targetType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(static property => property.CanRead && (property.GetMethod?.IsPrivate == false))) {
foreach (PropertyInfo property in targetType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Where(static property => property is { CanRead: true, GetMethod.IsPrivate: false })) {
JsonPropertyAttribute? jsonProperty = property.GetCustomAttribute<JsonPropertyAttribute>();
if (jsonProperty != null) {

View File

@@ -101,7 +101,7 @@ internal sealed class Startup {
app.UseStaticFiles(
new StaticFileOptions {
OnPrepareResponse = static context => {
if (context.File.Exists && !context.File.IsDirectory && !string.IsNullOrEmpty(context.File.Name)) {
if (context.File is { Exists: true, IsDirectory: false } && !string.IsNullOrEmpty(context.File.Name)) {
string extension = Path.GetExtension(context.File.Name);
CacheControlHeaderValue cacheControl = new();

View File

@@ -93,11 +93,15 @@ internal static class WebUtilities {
StreamWriter streamWriter = new(response.Body, Encoding.UTF8);
await using (streamWriter.ConfigureAwait(false)) {
using JsonTextWriter jsonWriter = new(streamWriter) {
#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
JsonTextWriter jsonWriter = new(streamWriter) {
CloseOutput = false
};
#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
serializer.Serialize(jsonWriter, value);
await using (jsonWriter.ConfigureAwait(false)) {
serializer.Serialize(jsonWriter, value);
}
}
}
}

View File

@@ -1159,7 +1159,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
return (appID, DateTime.MinValue, true);
}
return ((productInfoResultSet.Complete && !productInfoResultSet.Failed) || optimisticDiscovery ? appID : 0, DateTime.MinValue, true);
return (productInfoResultSet is { Complete: true, Failed: false } || optimisticDiscovery ? appID : 0, DateTime.MinValue, true);
}
internal Task<HashSet<uint>?> GetMarketableAppIDs() => ArchiWebHandler.GetAppList();
@@ -1422,7 +1422,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
internal async Task OnFarmingFinished(bool farmedSomething) {
await OnFarmingStopped().ConfigureAwait(false);
if (BotConfig.SendOnFarmingFinished && (BotConfig.LootableTypes.Count > 0) && (farmedSomething || !FirstTradeSent)) {
if (BotConfig is { SendOnFarmingFinished: true, LootableTypes.Count: > 0 } && (farmedSomething || !FirstTradeSent)) {
FirstTradeSent = true;
await Actions.SendInventory(filterFunction: item => BotConfig.LootableTypes.Contains(item.Type)).ConfigureAwait(false);
@@ -2068,7 +2068,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
SendItemsTimer = null;
}
if ((BotConfig.SendTradePeriod > 0) && (BotConfig.LootableTypes.Count > 0) && BotConfig.SteamUserPermissions.Values.Any(static permission => permission >= BotConfig.EAccess.Master)) {
if (BotConfig is { SendTradePeriod: > 0, LootableTypes.Count: > 0 } && BotConfig.SteamUserPermissions.Values.Any(static permission => permission >= BotConfig.EAccess.Master)) {
SendItemsTimer = new Timer(
OnSendItemsTimer,
null,
@@ -2563,7 +2563,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable {
}
// Under normal circumstances, timestamp must always be greater than 0, but Steam already proved that it's capable of going against the logic
if (!notification.local_echo && (notification.rtime32_server_timestamp > 0)) {
if (notification is { local_echo: false, rtime32_server_timestamp: > 0 }) {
if (ShouldAckChatMessage(notification.steamid_friend)) {
Utilities.InBackground(() => ArchiHandler.AckMessage(notification.steamid_friend, notification.rtime32_server_timestamp));
}

View File

@@ -251,7 +251,7 @@ public sealed class CardsFarmer : IAsyncDisposable, IDisposable {
// If we're not farming, and we got new items, it's likely to be a booster pack or likewise
// In this case, perform a loot if user wants to do so
if (Bot.BotConfig.SendOnFarmingFinished && (Bot.BotConfig.LootableTypes.Count > 0)) {
if (Bot.BotConfig is { SendOnFarmingFinished: true, LootableTypes.Count: > 0 }) {
await Bot.Actions.SendInventory(filterFunction: item => Bot.BotConfig.LootableTypes.Contains(item.Type)).ConfigureAwait(false);
}
}
@@ -352,7 +352,7 @@ public sealed class CardsFarmer : IAsyncDisposable, IDisposable {
if (minFarmingDelayAfterBlock > 0) {
Bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.BotExtraIdlingCooldown, TimeSpan.FromSeconds(minFarmingDelayAfterBlock).ToHumanReadable()));
for (byte i = 0; (i < minFarmingDelayAfterBlock) && Bot.IsConnectedAndLoggedOn && Bot.IsPlayingPossible && Bot.PlayingWasBlocked; i++) {
for (byte i = 0; (i < minFarmingDelayAfterBlock) && Bot is { IsConnectedAndLoggedOn: true, IsPlayingPossible: true, PlayingWasBlocked: true }; i++) {
await Task.Delay(1000).ConfigureAwait(false);
}

View File

@@ -73,6 +73,6 @@ public sealed class TradeOffer {
throw new ArgumentNullException(nameof(acceptedTypes));
}
return ItemsToGive.All(item => (item.AppID == Asset.SteamAppID) && (item.ContextID == Asset.SteamCommunityContextID) && acceptedTypes.Contains(item.Type));
return ItemsToGive.All(item => item is { AppID: Asset.SteamAppID, ContextID: Asset.SteamCommunityContextID } && acceptedTypes.Contains(item.Type));
}
}

View File

@@ -382,7 +382,7 @@ public sealed class Trading : IDisposable {
lootableTypesReceived = await ParseActiveTrades().ConfigureAwait(false);
}
if (lootableTypesReceived && Bot.BotConfig.SendOnFarmingFinished && (Bot.BotConfig.LootableTypes.Count > 0)) {
if (lootableTypesReceived && Bot.BotConfig is { SendOnFarmingFinished: true, LootableTypes.Count: > 0 }) {
await Bot.Actions.SendInventory(filterFunction: item => Bot.BotConfig.LootableTypes.Contains(item.Type)).ConfigureAwait(false);
}
} finally {

View File

@@ -33,7 +33,7 @@ internal sealed class InMemoryServerListProvider : IServerListProvider {
[JsonProperty(Required = Required.DisallowNull)]
private readonly ConcurrentHashSet<ServerRecordEndPoint> ServerRecords = new();
public Task<IEnumerable<ServerRecord>> FetchServerListAsync() => Task.FromResult(ServerRecords.Where(static server => !string.IsNullOrEmpty(server.Host) && (server.Port > 0) && (server.ProtocolTypes > 0)).Select(static server => ServerRecord.CreateServer(server.Host, server.Port, server.ProtocolTypes)));
public Task<IEnumerable<ServerRecord>> FetchServerListAsync() => Task.FromResult(ServerRecords.Where(static server => !string.IsNullOrEmpty(server.Host) && server is { Port: > 0, ProtocolTypes: > 0 }).Select(static server => ServerRecord.CreateServer(server.Host, server.Port, server.ProtocolTypes)));
public Task UpdateServerListAsync(IEnumerable<ServerRecord> endpoints) {
ArgumentNullException.ThrowIfNull(endpoints);

View File

@@ -345,11 +345,16 @@ public sealed class WebBrowser : IDisposable {
try {
using StreamReader streamReader = new(response.Content);
using JsonTextReader jsonReader = new(streamReader);
JsonSerializer serializer = new();
#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
JsonTextReader jsonReader = new(streamReader);
#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
obj = serializer.Deserialize<T>(jsonReader);
await using (jsonReader.ConfigureAwait(false)) {
JsonSerializer serializer = new();
obj = serializer.Deserialize<T>(jsonReader);
}
} catch (Exception e) {
if ((requestOptions.HasFlag(ERequestOptions.AllowInvalidBodyOnSuccess) && response.StatusCode.IsSuccessCode()) || (requestOptions.HasFlag(ERequestOptions.AllowInvalidBodyOnErrors) && !response.StatusCode.IsSuccessCode())) {
return new ObjectResponse<T>(response);
@@ -649,11 +654,16 @@ public sealed class WebBrowser : IDisposable {
try {
using StreamReader streamReader = new(response.Content);
using JsonReader jsonReader = new JsonTextReader(streamReader);
JsonSerializer serializer = new();
#pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
JsonReader jsonReader = new JsonTextReader(streamReader);
#pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose
obj = serializer.Deserialize<TResult>(jsonReader);
await using (jsonReader.ConfigureAwait(false)) {
JsonSerializer serializer = new();
obj = serializer.Deserialize<TResult>(jsonReader);
}
} catch (Exception e) {
if ((requestOptions.HasFlag(ERequestOptions.AllowInvalidBodyOnSuccess) && response.StatusCode.IsSuccessCode()) || (requestOptions.HasFlag(ERequestOptions.AllowInvalidBodyOnErrors) && !response.StatusCode.IsSuccessCode())) {
return new ObjectResponse<TResult>(response);

View File

@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>5.4.0.4</Version>
<Version>5.4.1.0</Version>
</PropertyGroup>
<PropertyGroup>