Misc Rider enhancements

This commit is contained in:
Łukasz Domeradzki
2024-12-14 17:51:03 +01:00
parent 0db414d608
commit acd081775d
5 changed files with 12 additions and 11 deletions

View File

@@ -39,7 +39,7 @@ namespace ArchiSteamFarm.CustomPlugins.PeriodicGC;
internal sealed class PeriodicGCPlugin : IPlugin { internal sealed class PeriodicGCPlugin : IPlugin {
private const byte GCPeriod = 60; // In seconds 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); private static readonly Timer PeriodicGCTimer = new(PerformGC);
[JsonInclude] [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."); 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); PeriodicGCTimer.Change(timeSpan, timeSpan);
} }
@@ -65,7 +65,7 @@ internal sealed class PeriodicGCPlugin : IPlugin {
private static void PerformGC(object? state = null) { private static void PerformGC(object? state = null) {
ASF.ArchiLogger.LogGenericWarning($"Performing GC, current memory: {GC.GetTotalMemory(false) / 1024} KB."); ASF.ArchiLogger.LogGenericWarning($"Performing GC, current memory: {GC.GetTotalMemory(false) / 1024} KB.");
lock (LockObject) { lock (Lock) {
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
} }

View File

@@ -22,12 +22,13 @@
// limitations under the License. // limitations under the License.
using System; using System;
using System.Threading;
using ArchiSteamFarm.Steam.Exchange; using ArchiSteamFarm.Steam.Exchange;
namespace ArchiSteamFarm.OfficialPlugins.Monitoring; namespace ArchiSteamFarm.OfficialPlugins.Monitoring;
internal sealed class TradeStatistics { internal sealed class TradeStatistics {
private readonly object Lock = new(); private readonly Lock Lock = new();
internal int AcceptedOffers { get; private set; } internal int AcceptedOffers { get; private set; }
internal int BlacklistedOffers { get; private set; } internal int BlacklistedOffers { get; private set; }

View File

@@ -28,7 +28,7 @@ using System.Threading;
namespace ArchiSteamFarm.Core; namespace ArchiSteamFarm.Core;
internal static class AprilFools { 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 // 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; private static readonly CultureInfo OriginalCulture = CultureInfo.CurrentCulture;
@@ -49,7 +49,7 @@ internal static class AprilFools {
TimeSpan aprilFoolsEnd = TimeSpan.FromDays(1) - now.TimeOfDay; TimeSpan aprilFoolsEnd = TimeSpan.FromDays(1) - now.TimeOfDay;
lock (LockObject) { lock (Lock) {
Timer.Change(aprilFoolsEnd + TimeSpan.FromMilliseconds(100), Timeout.InfiniteTimeSpan); 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 // Timer can accept only dueTimes up to 2^32 - 2
uint dueTime = (uint) Math.Min(uint.MaxValue - 1, (ulong) aprilFoolsStart.TotalMilliseconds + 100); uint dueTime = (uint) Math.Min(uint.MaxValue - 1, (ulong) aprilFoolsStart.TotalMilliseconds + 100);
lock (LockObject) { lock (Lock) {
Timer.Change(dueTime, Timeout.Infinite); Timer.Change(dueTime, Timeout.Infinite);
} }
} }

View File

@@ -30,12 +30,12 @@ namespace ArchiSteamFarm.IPC.Integration;
[PublicAPI] [PublicAPI]
public sealed class SwaggerItemsMinMaxAttribute : CustomSwaggerAttribute { public sealed class SwaggerItemsMinMaxAttribute : CustomSwaggerAttribute {
public uint MaximumUint { public uint MaximumUint {
get => BackingMaximum.HasValue ? decimal.ToUInt32(BackingMaximum.Value) : default(uint); get => BackingMaximum.HasValue ? decimal.ToUInt32(BackingMaximum.Value) : 0;
set => BackingMaximum = value; set => BackingMaximum = value;
} }
public uint MinimumUint { public uint MinimumUint {
get => BackingMinimum.HasValue ? decimal.ToUInt32(BackingMinimum.Value) : default(uint); get => BackingMinimum.HasValue ? decimal.ToUInt32(BackingMinimum.Value) : 0;
set => BackingMinimum = value; set => BackingMinimum = value;
} }

View File

@@ -749,7 +749,7 @@ public sealed class ArchiWebHandler : IDisposable {
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed); Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
Bot.ArchiLogger.LogGenericDebug(Strings.FormatErrorFailingRequest(request)); Bot.ArchiLogger.LogGenericDebug(Strings.FormatErrorFailingRequest(request));
return default(ObjectResponse<T>?); return null;
} }
} }
@@ -759,7 +759,7 @@ public sealed class ArchiWebHandler : IDisposable {
ObjectResponse<T>? response = await WebLimitRequest(host, async () => await WebBrowser.UrlGetToJsonObject<T>(request, headers, referer, requestOptions, maxTries, rateLimitingDelay, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false); ObjectResponse<T>? response = await WebLimitRequest(host, async () => await WebBrowser.UrlGetToJsonObject<T>(request, headers, referer, requestOptions, maxTries, rateLimitingDelay, cancellationToken).ConfigureAwait(false), cancellationToken).ConfigureAwait(false);
if (response == null) { if (response == null) {
return default(ObjectResponse<T>?); return null;
} }
if (IsSessionExpiredUri(response.FinalUri)) { if (IsSessionExpiredUri(response.FinalUri)) {