Address new Rider inspections (EAP) (#2418)

This commit is contained in:
Łukasz Domeradzki
2021-10-01 01:21:09 +02:00
committed by GitHub
parent 99205fa278
commit 965d3050a5
8 changed files with 34 additions and 31 deletions

View File

@@ -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));
}

View File

@@ -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));

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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<uint> 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<uint, DateTime> immutableRedeemDates = redeemDates.ToImmutableDictionary();
switch (farmingOrder) {
case BotConfig.EFarmingOrder.RedeemDateTimesAscending:
orderedGamesToFarm = farmingOrder switch {
// ReSharper disable once AccessToModifiedClosure - you're wrong
orderedGamesToFarm = orderedGamesToFarm.ThenBy(game => immutableRedeemDates[game.AppID]);
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]);
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:

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -352,6 +352,7 @@ namespace ArchiSteamFarm.Steam.Interaction {
HashSet<Asset> 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;
}