diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index 22800ddc2..b70271f6b 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -136,6 +136,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { TimeSpan startIn = TimeSpan.FromMinutes(Utilities.RandomNext(SharedInfo.MinimumMinutesBeforeFirstUpload, SharedInfo.MaximumMinutesBeforeFirstUpload)); + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (SubmissionSemaphore) { SubmissionTimer.Change(startIn, TimeSpan.FromHours(SharedInfo.MinimumHoursBetweenUploads)); } @@ -520,6 +521,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper { #endif TimeSpan startIn = TimeSpan.FromMinutes(Utilities.RandomNext(SharedInfo.MinimumMinutesBeforeFirstUpload, SharedInfo.MaximumMinutesBeforeFirstUpload)); + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (SubmissionSemaphore) { SubmissionTimer.Change(startIn, TimeSpan.FromHours(SharedInfo.MinimumHoursBetweenUploads)); } diff --git a/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs b/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs index 99a85dde7..17bc71fe0 100644 --- a/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs +++ b/ArchiSteamFarm/Helpers/CrossProcessFileBasedSemaphore.cs @@ -58,6 +58,7 @@ namespace ArchiSteamFarm.Helpers { } void ICrossProcessSemaphore.Release() { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (LocalSemaphore) { if (FileLock == null) { throw new InvalidOperationException(nameof(FileLock)); @@ -78,6 +79,7 @@ namespace ArchiSteamFarm.Helpers { try { while (true) { try { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (LocalSemaphore) { if (FileLock != null) { throw new InvalidOperationException(nameof(FileLock)); @@ -123,6 +125,7 @@ namespace ArchiSteamFarm.Helpers { while (true) { try { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (LocalSemaphore) { if (FileLock != null) { throw new InvalidOperationException(nameof(FileLock)); diff --git a/ArchiSteamFarm/Helpers/SerializableFile.cs b/ArchiSteamFarm/Helpers/SerializableFile.cs index 2e41f6bcb..717b621ba 100644 --- a/ArchiSteamFarm/Helpers/SerializableFile.cs +++ b/ArchiSteamFarm/Helpers/SerializableFile.cs @@ -61,6 +61,7 @@ namespace ArchiSteamFarm.Helpers { return; } + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (FileSemaphore) { if (SavingScheduled) { return; @@ -72,6 +73,7 @@ namespace ArchiSteamFarm.Helpers { await FileSemaphore.WaitAsync().ConfigureAwait(false); try { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (FileSemaphore) { SavingScheduled = false; } diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index b3bbdb5f5..f3da8355e 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -3285,6 +3285,7 @@ namespace ArchiSteamFarm.Steam { } private async Task SendCompletedSets() { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (SendCompleteTypesSemaphore) { if (SendCompleteTypesScheduled) { return; @@ -3297,6 +3298,7 @@ namespace ArchiSteamFarm.Steam { try { using (await Actions.GetTradingLock().ConfigureAwait(false)) { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (SendCompleteTypesSemaphore) { SendCompleteTypesScheduled = false; } diff --git a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs index 4aebb2b6e..596ed918a 100644 --- a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs +++ b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs @@ -147,10 +147,11 @@ namespace ArchiSteamFarm.Steam.Cards { // This update has a potential to modify local ignores, therefore we need to purge our cache LocallyIgnoredAppIDs.Clear(); - ShouldResumeFarming = true; - // We aim to have a maximum of 2 tasks, one already parsing, and one waiting in the queue // This way we can call this function as many times as needed e.g. because of Steam events + ShouldResumeFarming = true; + + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (EventSemaphore) { if (ParsingScheduled) { return; @@ -162,6 +163,7 @@ namespace ArchiSteamFarm.Steam.Cards { await EventSemaphore.WaitAsync().ConfigureAwait(false); try { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (EventSemaphore) { ParsingScheduled = false; } @@ -1155,20 +1157,11 @@ namespace ArchiSteamFarm.Steam.Cards { if (marketableAppIDs?.Count > 0) { ImmutableHashSet immutableMarketableAppIDs = marketableAppIDs.ToImmutableHashSet(); - switch (farmingOrder) { - case BotConfig.EFarmingOrder.MarketableAscending: - orderedGamesToFarm = orderedGamesToFarm.ThenBy(game => immutableMarketableAppIDs.Contains(game.AppID)); - - break; - case BotConfig.EFarmingOrder.MarketableDescending: - orderedGamesToFarm = orderedGamesToFarm.ThenByDescending(game => immutableMarketableAppIDs.Contains(game.AppID)); - - break; - default: - Bot.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(farmingOrder), farmingOrder)); - - return; - } + orderedGamesToFarm = farmingOrder switch { + BotConfig.EFarmingOrder.MarketableAscending => orderedGamesToFarm.ThenBy(game => immutableMarketableAppIDs.Contains(game.AppID)), + BotConfig.EFarmingOrder.MarketableDescending => orderedGamesToFarm.ThenByDescending(game => immutableMarketableAppIDs.Contains(game.AppID)), + _ => throw new InvalidOperationException(nameof(farmingOrder)) + }; } break; @@ -1219,22 +1212,15 @@ namespace ArchiSteamFarm.Steam.Cards { ImmutableDictionary immutableRedeemDates = redeemDates.ToImmutableDictionary(); - switch (farmingOrder) { - case BotConfig.EFarmingOrder.RedeemDateTimesAscending: - // ReSharper disable once AccessToModifiedClosure - you're wrong - orderedGamesToFarm = orderedGamesToFarm.ThenBy(game => immutableRedeemDates[game.AppID]); + orderedGamesToFarm = farmingOrder switch { + // ReSharper disable once AccessToModifiedClosure - you're wrong + BotConfig.EFarmingOrder.RedeemDateTimesAscending => orderedGamesToFarm.ThenBy(game => immutableRedeemDates[game.AppID]), - break; - case BotConfig.EFarmingOrder.RedeemDateTimesDescending: - // ReSharper disable once AccessToModifiedClosure - you're wrong - orderedGamesToFarm = orderedGamesToFarm.ThenByDescending(game => immutableRedeemDates[game.AppID]); + // ReSharper disable once AccessToModifiedClosure - you're wrong + BotConfig.EFarmingOrder.RedeemDateTimesDescending => orderedGamesToFarm.ThenByDescending(game => immutableRedeemDates[game.AppID]), - break; - default: - Bot.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(farmingOrder), farmingOrder)); - - return; - } + _ => throw new InvalidOperationException(nameof(farmingOrder)) + }; break; default: diff --git a/ArchiSteamFarm/Steam/Exchange/Trading.cs b/ArchiSteamFarm/Steam/Exchange/Trading.cs index 50b7b42fc..47e8e6619 100644 --- a/ArchiSteamFarm/Steam/Exchange/Trading.cs +++ b/ArchiSteamFarm/Steam/Exchange/Trading.cs @@ -332,7 +332,7 @@ namespace ArchiSteamFarm.Steam.Exchange { throw new InvalidOperationException(nameof(amount)); case 1: // Single tradable item, can be matchable or not depending on the rest of the inventory - if (!fullSet.TryGetValue(classID, out uint fullAmount) || (fullAmount == 0) || (fullAmount < amount)) { + if (!fullSet.TryGetValue(classID, out uint fullAmount) || (fullAmount == 0)) { throw new InvalidOperationException(nameof(fullAmount)); } @@ -358,6 +358,8 @@ namespace ArchiSteamFarm.Steam.Exchange { internal async Task OnNewTrade() { // We aim to have a maximum of 2 tasks, one already working, and one waiting in the queue // This way we can call this function as many times as needed e.g. because of Steam events + + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (TradesSemaphore) { if (ParsingScheduled) { return; @@ -372,6 +374,7 @@ namespace ArchiSteamFarm.Steam.Exchange { bool lootableTypesReceived; using (await Bot.Actions.GetTradingLock().ConfigureAwait(false)) { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (TradesSemaphore) { ParsingScheduled = false; } diff --git a/ArchiSteamFarm/Steam/Integration/SteamPICSChanges.cs b/ArchiSteamFarm/Steam/Integration/SteamPICSChanges.cs index 658625b35..7e8fcdee2 100644 --- a/ArchiSteamFarm/Steam/Integration/SteamPICSChanges.cs +++ b/ArchiSteamFarm/Steam/Integration/SteamPICSChanges.cs @@ -47,6 +47,7 @@ namespace ArchiSteamFarm.Steam.Integration { return; } + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (RefreshSemaphore) { if (TimerAlreadySet) { return; diff --git a/ArchiSteamFarm/Steam/Interaction/Actions.cs b/ArchiSteamFarm/Steam/Interaction/Actions.cs index d6ee476b3..f56868ac3 100644 --- a/ArchiSteamFarm/Steam/Interaction/Actions.cs +++ b/ArchiSteamFarm/Steam/Interaction/Actions.cs @@ -352,6 +352,7 @@ namespace ArchiSteamFarm.Steam.Interaction { HashSet inventory; + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (TradingSemaphore) { if (TradingScheduled) { return (false, Strings.ErrorAborted); @@ -363,6 +364,7 @@ namespace ArchiSteamFarm.Steam.Interaction { await TradingSemaphore.WaitAsync().ConfigureAwait(false); try { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (TradingSemaphore) { TradingScheduled = false; } @@ -431,6 +433,7 @@ namespace ArchiSteamFarm.Steam.Interaction { return; } + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (GiftCardsSemaphore) { if (ProcessingGiftsScheduled) { return; @@ -442,6 +445,7 @@ namespace ArchiSteamFarm.Steam.Interaction { await GiftCardsSemaphore.WaitAsync().ConfigureAwait(false); try { + // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that lock (GiftCardsSemaphore) { ProcessingGiftsScheduled = false; }