From acd081775d799464827c18eda00aecf734c327ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Sat, 14 Dec 2024 17:51:03 +0100 Subject: [PATCH] Misc Rider enhancements --- ArchiSteamFarm.CustomPlugins.PeriodicGC/PeriodicGCPlugin.cs | 6 +++--- .../TradeStatistics.cs | 3 ++- ArchiSteamFarm/Core/AprilFools.cs | 6 +++--- .../IPC/Integration/SwaggerItemsMinMaxAttribute.cs | 4 ++-- ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ArchiSteamFarm.CustomPlugins.PeriodicGC/PeriodicGCPlugin.cs b/ArchiSteamFarm.CustomPlugins.PeriodicGC/PeriodicGCPlugin.cs index 863c0f7c3..48a071c0b 100644 --- a/ArchiSteamFarm.CustomPlugins.PeriodicGC/PeriodicGCPlugin.cs +++ b/ArchiSteamFarm.CustomPlugins.PeriodicGC/PeriodicGCPlugin.cs @@ -39,7 +39,7 @@ namespace ArchiSteamFarm.CustomPlugins.PeriodicGC; internal sealed class PeriodicGCPlugin : IPlugin { private const byte GCPeriod = 60; // In seconds - private static readonly object LockObject = new(); + private static readonly Lock Lock = new(); private static readonly Timer PeriodicGCTimer = new(PerformGC); [JsonInclude] @@ -55,7 +55,7 @@ internal sealed class PeriodicGCPlugin : IPlugin { ASF.ArchiLogger.LogGenericWarning($"Periodic GC will occur every {timeSpan.ToHumanReadable()}. Please keep in mind that this plugin should be used for debugging tests only."); - lock (LockObject) { + lock (Lock) { PeriodicGCTimer.Change(timeSpan, timeSpan); } @@ -65,7 +65,7 @@ internal sealed class PeriodicGCPlugin : IPlugin { private static void PerformGC(object? state = null) { ASF.ArchiLogger.LogGenericWarning($"Performing GC, current memory: {GC.GetTotalMemory(false) / 1024} KB."); - lock (LockObject) { + lock (Lock) { GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true); } diff --git a/ArchiSteamFarm.OfficialPlugins.Monitoring/TradeStatistics.cs b/ArchiSteamFarm.OfficialPlugins.Monitoring/TradeStatistics.cs index c735a29e2..da53fcce1 100644 --- a/ArchiSteamFarm.OfficialPlugins.Monitoring/TradeStatistics.cs +++ b/ArchiSteamFarm.OfficialPlugins.Monitoring/TradeStatistics.cs @@ -22,12 +22,13 @@ // limitations under the License. using System; +using System.Threading; using ArchiSteamFarm.Steam.Exchange; namespace ArchiSteamFarm.OfficialPlugins.Monitoring; internal sealed class TradeStatistics { - private readonly object Lock = new(); + private readonly Lock Lock = new(); internal int AcceptedOffers { get; private set; } internal int BlacklistedOffers { get; private set; } diff --git a/ArchiSteamFarm/Core/AprilFools.cs b/ArchiSteamFarm/Core/AprilFools.cs index 3579e73fa..f1ae561bc 100644 --- a/ArchiSteamFarm/Core/AprilFools.cs +++ b/ArchiSteamFarm/Core/AprilFools.cs @@ -28,7 +28,7 @@ using System.Threading; namespace ArchiSteamFarm.Core; internal static class AprilFools { - private static readonly object LockObject = new(); + private static readonly Lock Lock = new(); // We don't care about CurrentCulture global config property, because April Fools are never initialized in this case private static readonly CultureInfo OriginalCulture = CultureInfo.CurrentCulture; @@ -49,7 +49,7 @@ internal static class AprilFools { TimeSpan aprilFoolsEnd = TimeSpan.FromDays(1) - now.TimeOfDay; - lock (LockObject) { + lock (Lock) { Timer.Change(aprilFoolsEnd + TimeSpan.FromMilliseconds(100), Timeout.InfiniteTimeSpan); } @@ -72,7 +72,7 @@ internal static class AprilFools { // Timer can accept only dueTimes up to 2^32 - 2 uint dueTime = (uint) Math.Min(uint.MaxValue - 1, (ulong) aprilFoolsStart.TotalMilliseconds + 100); - lock (LockObject) { + lock (Lock) { Timer.Change(dueTime, Timeout.Infinite); } } diff --git a/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs b/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs index 1c10b9350..e8b0b8a6a 100644 --- a/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs +++ b/ArchiSteamFarm/IPC/Integration/SwaggerItemsMinMaxAttribute.cs @@ -30,12 +30,12 @@ namespace ArchiSteamFarm.IPC.Integration; [PublicAPI] public sealed class SwaggerItemsMinMaxAttribute : CustomSwaggerAttribute { public uint MaximumUint { - get => BackingMaximum.HasValue ? decimal.ToUInt32(BackingMaximum.Value) : default(uint); + get => BackingMaximum.HasValue ? decimal.ToUInt32(BackingMaximum.Value) : 0; set => BackingMaximum = value; } public uint MinimumUint { - get => BackingMinimum.HasValue ? decimal.ToUInt32(BackingMinimum.Value) : default(uint); + get => BackingMinimum.HasValue ? decimal.ToUInt32(BackingMinimum.Value) : 0; set => BackingMinimum = value; } diff --git a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs index 48ecc8bcd..4737335e9 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs @@ -749,7 +749,7 @@ public sealed class ArchiWebHandler : IDisposable { Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); Bot.ArchiLogger.LogGenericDebug(Strings.FormatErrorFailingRequest(request)); - return default(ObjectResponse?); + return null; } } @@ -759,7 +759,7 @@ public sealed class ArchiWebHandler : IDisposable { ObjectResponse? response = await WebLimitRequest(host, async () => await WebBrowser.UrlGetToJsonObject(request, headers, referer, requestOptions, maxTries, rateLimitingDelay, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); if (response == null) { - return default(ObjectResponse?); + return null; } if (IsSessionExpiredUri(response.FinalUri)) {