mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 15:14:41 +00:00
Code review according to Jeffrey Richter
> The pattern is to take the basest class or interface possible for your arguments and return the most specific class or interface possible for your return types. This gives your callers the most flexibility in passing in types to your methods and the most opportunities to cast/reuse the return values.
This commit is contained in:
parent
216bf4b486
commit
8019cdcbb4
14 changed files with 93 additions and 56 deletions
|
@ -195,7 +195,7 @@ namespace ArchiSteamFarm.Tests {
|
|||
Assert.IsTrue(AcceptsTrade(inventory, itemsToGive, itemsToReceive));
|
||||
}
|
||||
|
||||
private static bool AcceptsTrade(HashSet<Steam.Asset> inventory, HashSet<Steam.Asset> itemsToGive, HashSet<Steam.Asset> itemsToReceive) {
|
||||
private static bool AcceptsTrade(IReadOnlyCollection<Steam.Asset> inventory, IReadOnlyCollection<Steam.Asset> itemsToGive, IReadOnlyCollection<Steam.Asset> itemsToReceive) {
|
||||
Type trading = typeof(ArchiSteamFarm.Trading);
|
||||
MethodInfo method = trading.GetMethod("IsTradeNeutralOrBetter", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
|
||||
return (bool) method.Invoke(null, new object[] { inventory, itemsToGive, itemsToReceive });
|
||||
|
|
|
@ -481,7 +481,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "FunctionComplexityOverflow")]
|
||||
internal async Task<HashSet<Steam.Asset>> GetMySteamInventory(bool tradableOnly = false, HashSet<Steam.Asset.EType> wantedTypes = null, HashSet<uint> wantedRealAppIDs = null) {
|
||||
internal async Task<HashSet<Steam.Asset>> GetMySteamInventory(bool tradableOnly = false, IReadOnlyCollection<Steam.Asset.EType> wantedTypes = null, IReadOnlyCollection<uint> wantedRealAppIDs = null) {
|
||||
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ namespace ArchiSteamFarm {
|
|||
return response?.Success;
|
||||
}
|
||||
|
||||
internal async Task<bool?> HandleConfirmations(string deviceID, string confirmationHash, uint time, HashSet<MobileAuthenticator.Confirmation> confirmations, bool accept) {
|
||||
internal async Task<bool?> HandleConfirmations(string deviceID, string confirmationHash, uint time, IReadOnlyCollection<MobileAuthenticator.Confirmation> confirmations, bool accept) {
|
||||
if (string.IsNullOrEmpty(deviceID) || string.IsNullOrEmpty(confirmationHash) || (time == 0) || (confirmations == null) || (confirmations.Count == 0)) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time) + " || " + nameof(confirmations));
|
||||
return null;
|
||||
|
@ -1006,7 +1006,7 @@ namespace ArchiSteamFarm {
|
|||
return (response.Result, response.PurchaseResultDetail);
|
||||
}
|
||||
|
||||
internal async Task<bool> SendTradeOffer(HashSet<Steam.Asset> inventory, ulong partnerID, string token = null) {
|
||||
internal async Task<bool> SendTradeOffer(IReadOnlyCollection<Steam.Asset> inventory, ulong partnerID, string token = null) {
|
||||
if ((inventory == null) || (inventory.Count == 0) || (partnerID == 0)) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(inventory) + " || " + nameof(inventory.Count) + " || " + nameof(partnerID));
|
||||
return false;
|
||||
|
@ -1292,7 +1292,7 @@ namespace ArchiSteamFarm {
|
|||
return !uri?.AbsolutePath.StartsWith("/login", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static bool ParseItems(Dictionary<ulong, (uint AppID, Steam.Asset.EType Type)> descriptions, List<KeyValue> input, HashSet<Steam.Asset> output) {
|
||||
private static bool ParseItems(Dictionary<ulong, (uint AppID, Steam.Asset.EType Type)> descriptions, IReadOnlyCollection<KeyValue> input, ICollection<Steam.Asset> output) {
|
||||
if ((descriptions == null) || (input == null) || (input.Count == 0) || (output == null)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output));
|
||||
return false;
|
||||
|
|
|
@ -255,7 +255,7 @@ namespace ArchiSteamFarm {
|
|||
Trading?.Dispose();
|
||||
}
|
||||
|
||||
internal async Task<bool> AcceptConfirmations(bool accept, Steam.ConfirmationDetails.EType acceptedType = Steam.ConfirmationDetails.EType.Unknown, ulong acceptedSteamID = 0, HashSet<ulong> acceptedTradeIDs = null) {
|
||||
internal async Task<bool> AcceptConfirmations(bool accept, Steam.ConfirmationDetails.EType acceptedType = Steam.ConfirmationDetails.EType.Unknown, ulong acceptedSteamID = 0, IReadOnlyCollection<ulong> acceptedTradeIDs = null) {
|
||||
if (!HasMobileAuthenticator) {
|
||||
return false;
|
||||
}
|
||||
|
@ -460,7 +460,12 @@ namespace ArchiSteamFarm {
|
|||
return (appID, DateTime.MinValue);
|
||||
}
|
||||
|
||||
internal async Task<Dictionary<uint, HashSet<uint>>> GetAppIDsToPackageIDs(IEnumerable<uint> packageIDs) {
|
||||
internal async Task<Dictionary<uint, HashSet<uint>>> GetAppIDsToPackageIDs(IReadOnlyCollection<uint> packageIDs) {
|
||||
if ((packageIDs == null) || (packageIDs.Count == 0)) {
|
||||
ArchiLogger.LogNullError(nameof(packageIDs));
|
||||
return null;
|
||||
}
|
||||
|
||||
AsyncJobMultiple<SteamApps.PICSProductInfoCallback>.ResultSet productInfoResultSet;
|
||||
|
||||
await PICSSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
|
@ -525,16 +530,25 @@ namespace ArchiSteamFarm {
|
|||
return result;
|
||||
}
|
||||
|
||||
internal async Task IdleGames(IEnumerable<uint> gameIDs) {
|
||||
if (gameIDs == null) {
|
||||
ArchiLogger.LogNullError(nameof(gameIDs));
|
||||
internal async Task IdleGame(CardsFarmer.Game game) {
|
||||
if (game == null) {
|
||||
ArchiLogger.LogNullError(nameof(game));
|
||||
return;
|
||||
}
|
||||
|
||||
await ArchiHandler.PlayGames(gameIDs, BotConfig.CustomGamePlayedWhileFarming).ConfigureAwait(false);
|
||||
await ArchiHandler.PlayGames(game.PlayableAppID.ToEnumerable(), BotConfig.CustomGamePlayedWhileFarming).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static async Task InitializeSteamConfiguration(ProtocolTypes protocolTypes, uint cellID, InMemoryServerListProvider serverListProvider) {
|
||||
internal async Task IdleGames(IReadOnlyCollection<CardsFarmer.Game> games) {
|
||||
if ((games == null) || (games.Count == 0)) {
|
||||
ArchiLogger.LogNullError(nameof(games));
|
||||
return;
|
||||
}
|
||||
|
||||
await ArchiHandler.PlayGames(games.Select(game => game.PlayableAppID), BotConfig.CustomGamePlayedWhileFarming).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal static async Task InitializeSteamConfiguration(ProtocolTypes protocolTypes, uint cellID, IServerListProvider serverListProvider) {
|
||||
if (serverListProvider == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(serverListProvider));
|
||||
return;
|
||||
|
@ -1068,7 +1082,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static string GetAPIStatus(IDictionary<string, Bot> bots) {
|
||||
private static string GetAPIStatus(IReadOnlyDictionary<string, Bot> bots) {
|
||||
if (bots == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(bots));
|
||||
return null;
|
||||
|
@ -1792,7 +1806,7 @@ namespace ArchiSteamFarm {
|
|||
|
||||
if (OwnedPackageIDs.Count > 0) {
|
||||
if (!BotConfig.IdleRefundableGames || (BotConfig.FarmingOrder == BotConfig.EFarmingOrder.RedeemDateTimesAscending) || (BotConfig.FarmingOrder == BotConfig.EFarmingOrder.RedeemDateTimesDescending)) {
|
||||
Program.GlobalDatabase.RefreshPackageIDs(this, OwnedPackageIDs.Keys).Forget();
|
||||
Program.GlobalDatabase.RefreshPackageIDs(this, OwnedPackageIDs.Keys.AsReadOnlyCollection()).Forget();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2247,7 +2261,7 @@ namespace ArchiSteamFarm {
|
|||
return responses.Count > 0 ? string.Join("", responses) : null;
|
||||
}
|
||||
|
||||
private async Task<string> ResponseAddLicense(ulong steamID, ICollection<uint> gameIDs) {
|
||||
private async Task<string> ResponseAddLicense(ulong steamID, IReadOnlyCollection<uint> gameIDs) {
|
||||
if ((steamID == 0) || (gameIDs == null) || (gameIDs.Count == 0)) {
|
||||
ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count));
|
||||
return null;
|
||||
|
@ -2468,7 +2482,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
IReadOnlyCollection<ulong> blacklist = BotDatabase.GetBlacklistedFromTradesSteamIDs();
|
||||
ConcurrentHashSet<ulong> blacklist = BotDatabase.GetBlacklistedFromTradesSteamIDs();
|
||||
return FormatBotResponse(blacklist.Count > 0 ? string.Join(", ", blacklist) : string.Format(Strings.ErrorIsEmpty, nameof(blacklist)));
|
||||
}
|
||||
|
||||
|
@ -2715,7 +2729,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
IReadOnlyCollection<uint> idleBlacklist = BotDatabase.GetIdlingBlacklistedAppIDs();
|
||||
ConcurrentHashSet<uint> idleBlacklist = BotDatabase.GetIdlingBlacklistedAppIDs();
|
||||
return FormatBotResponse(idleBlacklist.Count > 0 ? string.Join(", ", idleBlacklist) : string.Format(Strings.ErrorIsEmpty, nameof(idleBlacklist)));
|
||||
}
|
||||
|
||||
|
@ -2880,7 +2894,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
IReadOnlyCollection<uint> idleQueue = BotDatabase.GetIdlingPriorityAppIDs();
|
||||
ConcurrentHashSet<uint> idleQueue = BotDatabase.GetIdlingPriorityAppIDs();
|
||||
return FormatBotResponse(idleQueue.Count > 0 ? string.Join(", ", idleQueue) : string.Format(Strings.ErrorIsEmpty, nameof(idleQueue)));
|
||||
}
|
||||
|
||||
|
@ -3591,7 +3605,7 @@ namespace ArchiSteamFarm {
|
|||
return responses.Count > 0 ? string.Join("", responses) : null;
|
||||
}
|
||||
|
||||
private async Task<string> ResponsePlay(ulong steamID, HashSet<uint> gameIDs) {
|
||||
private async Task<string> ResponsePlay(ulong steamID, IReadOnlyCollection<uint> gameIDs) {
|
||||
if ((steamID == 0) || (gameIDs == null) || (gameIDs.Count == 0)) {
|
||||
ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count));
|
||||
return null;
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace ArchiSteamFarm {
|
|||
MobileAuthenticator?.Dispose();
|
||||
}
|
||||
|
||||
internal async Task AddBlacklistedFromTradesSteamIDs(HashSet<ulong> steamIDs) {
|
||||
internal async Task AddBlacklistedFromTradesSteamIDs(IReadOnlyCollection<ulong> steamIDs) {
|
||||
if ((steamIDs == null) || (steamIDs.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(steamIDs));
|
||||
return;
|
||||
|
@ -82,7 +82,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
internal async Task AddIdlingBlacklistedAppIDs(HashSet<uint> appIDs) {
|
||||
internal async Task AddIdlingBlacklistedAppIDs(IReadOnlyCollection<uint> appIDs) {
|
||||
if ((appIDs == null) || (appIDs.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(appIDs));
|
||||
return;
|
||||
|
@ -93,7 +93,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
internal async Task AddIdlingPriorityAppIDs(HashSet<uint> appIDs) {
|
||||
internal async Task AddIdlingPriorityAppIDs(IReadOnlyCollection<uint> appIDs) {
|
||||
if ((appIDs == null) || (appIDs.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(appIDs));
|
||||
return;
|
||||
|
@ -115,9 +115,9 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
internal IReadOnlyCollection<ulong> GetBlacklistedFromTradesSteamIDs() => BlacklistedFromTradesSteamIDs;
|
||||
internal IReadOnlyCollection<uint> GetIdlingBlacklistedAppIDs() => IdlingBlacklistedAppIDs;
|
||||
internal IReadOnlyCollection<uint> GetIdlingPriorityAppIDs() => IdlingPriorityAppIDs;
|
||||
internal ConcurrentHashSet<ulong> GetBlacklistedFromTradesSteamIDs() => BlacklistedFromTradesSteamIDs;
|
||||
internal ConcurrentHashSet<uint> GetIdlingBlacklistedAppIDs() => IdlingBlacklistedAppIDs;
|
||||
internal ConcurrentHashSet<uint> GetIdlingPriorityAppIDs() => IdlingPriorityAppIDs;
|
||||
|
||||
internal bool IsBlacklistedFromIdling(uint appID) {
|
||||
if (appID == 0) {
|
||||
|
@ -177,7 +177,7 @@ namespace ArchiSteamFarm {
|
|||
return botDatabase;
|
||||
}
|
||||
|
||||
internal async Task RemoveBlacklistedFromTradesSteamIDs(HashSet<ulong> steamIDs) {
|
||||
internal async Task RemoveBlacklistedFromTradesSteamIDs(IReadOnlyCollection<ulong> steamIDs) {
|
||||
if ((steamIDs == null) || (steamIDs.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(steamIDs));
|
||||
return;
|
||||
|
@ -188,7 +188,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
internal async Task RemoveIdlingBlacklistedAppIDs(HashSet<uint> appIDs) {
|
||||
internal async Task RemoveIdlingBlacklistedAppIDs(IReadOnlyCollection<uint> appIDs) {
|
||||
if ((appIDs == null) || (appIDs.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(appIDs));
|
||||
return;
|
||||
|
@ -199,7 +199,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
internal async Task RemoveIdlingPriorityAppIDs(HashSet<uint> appIDs) {
|
||||
internal async Task RemoveIdlingPriorityAppIDs(IReadOnlyCollection<uint> appIDs) {
|
||||
if ((appIDs == null) || (appIDs.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(appIDs));
|
||||
return;
|
||||
|
|
|
@ -681,7 +681,7 @@ namespace ArchiSteamFarm {
|
|||
Bot.ArchiLogger.LogGenericWarning(string.Format(Strings.WarningIdlingGameMismatch, game.AppID, game.GameName, game.PlayableAppID));
|
||||
}
|
||||
|
||||
await Bot.IdleGames(game.PlayableAppID.ToEnumerable()).ConfigureAwait(false);
|
||||
await Bot.IdleGame(game).ConfigureAwait(false);
|
||||
|
||||
bool success = true;
|
||||
DateTime endFarmingDate = DateTime.UtcNow.AddHours(Program.GlobalConfig.MaxFarmingTime);
|
||||
|
@ -706,7 +706,7 @@ namespace ArchiSteamFarm {
|
|||
return success;
|
||||
}
|
||||
|
||||
private async Task<bool> FarmHours(ConcurrentHashSet<Game> games) {
|
||||
private async Task<bool> FarmHours(IReadOnlyCollection<Game> games) {
|
||||
if ((games == null) || (games.Count == 0)) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(games));
|
||||
return false;
|
||||
|
@ -723,7 +723,7 @@ namespace ArchiSteamFarm {
|
|||
return true;
|
||||
}
|
||||
|
||||
await Bot.IdleGames(games.Select(game => game.PlayableAppID)).ConfigureAwait(false);
|
||||
await Bot.IdleGames(games).ConfigureAwait(false);
|
||||
|
||||
bool success = true;
|
||||
while (maxHour < Bot.BotConfig.HoursUntilCardDrops) {
|
||||
|
@ -751,8 +751,8 @@ namespace ArchiSteamFarm {
|
|||
return success;
|
||||
}
|
||||
|
||||
private async Task<bool> FarmMultiple(IEnumerable<Game> games) {
|
||||
if (games == null) {
|
||||
private async Task<bool> FarmMultiple(IReadOnlyCollection<Game> games) {
|
||||
if ((games == null) || (games.Count == 0)) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(games));
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace ArchiSteamFarm {
|
|||
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
internal ConcurrentEnumerator(ICollection<T> collection, SemaphoreSlim semaphoreSlim) {
|
||||
internal ConcurrentEnumerator(IReadOnlyCollection<T> collection, SemaphoreSlim semaphoreSlim) {
|
||||
if ((collection == null) || (semaphoreSlim == null)) {
|
||||
throw new ArgumentNullException(nameof(collection) + " || " + nameof(semaphoreSlim));
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace ArchiSteamFarm {
|
|||
// We use Count() and not Any() because we must ensure full loop pass
|
||||
internal bool RemoveRange(IEnumerable<T> items) => items.Count(Remove) > 0;
|
||||
|
||||
internal bool ReplaceIfNeededWith(ICollection<T> other) {
|
||||
internal bool ReplaceIfNeededWith(IReadOnlyCollection<T> other) {
|
||||
if (SetEquals(other)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace ArchiSteamFarm {
|
|||
return globalDatabase;
|
||||
}
|
||||
|
||||
internal async Task RefreshPackageIDs(Bot bot, ICollection<uint> packageIDs) {
|
||||
internal async Task RefreshPackageIDs(Bot bot, IReadOnlyCollection<uint> packageIDs) {
|
||||
if ((bot == null) || (packageIDs == null) || (packageIDs.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(bot) + " || " + nameof(packageIDs));
|
||||
return;
|
||||
|
|
|
@ -560,7 +560,7 @@ namespace ArchiSteamFarm.JSON {
|
|||
return true;
|
||||
}
|
||||
|
||||
internal bool IsValidSteamItemsRequest(HashSet<Asset.EType> acceptedTypes) {
|
||||
internal bool IsValidSteamItemsRequest(IReadOnlyCollection<Asset.EType> acceptedTypes) {
|
||||
if ((acceptedTypes == null) || (acceptedTypes.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(acceptedTypes));
|
||||
return false;
|
||||
|
|
|
@ -192,7 +192,7 @@ namespace ArchiSteamFarm {
|
|||
return result;
|
||||
}
|
||||
|
||||
internal async Task<bool> HandleConfirmations(HashSet<Confirmation> confirmations, bool accept) {
|
||||
internal async Task<bool> HandleConfirmations(IReadOnlyCollection<Confirmation> confirmations, bool accept) {
|
||||
if ((confirmations == null) || (confirmations.Count == 0)) {
|
||||
Bot.ArchiLogger.LogNullError(nameof(confirmations));
|
||||
return false;
|
||||
|
|
|
@ -175,7 +175,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task Init(string[] args) {
|
||||
private static async Task Init(IReadOnlyCollection<string> args) {
|
||||
AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
TaskScheduler.UnobservedTaskException += OnUnobservedTaskException;
|
||||
|
@ -187,7 +187,7 @@ namespace ArchiSteamFarm {
|
|||
await InitASF(args).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task InitASF(string[] args) {
|
||||
private static async Task InitASF(IReadOnlyCollection<string> args) {
|
||||
ASF.ArchiLogger.LogGenericInfo("ASF V" + SharedInfo.Version + " (" + SharedInfo.ModuleVersion + ")");
|
||||
|
||||
await InitGlobalConfigAndLanguage().ConfigureAwait(false);
|
||||
|
@ -223,7 +223,7 @@ namespace ArchiSteamFarm {
|
|||
ASF.InitEvents();
|
||||
}
|
||||
|
||||
private static void InitCore(string[] args) {
|
||||
private static void InitCore(IReadOnlyCollection<string> args) {
|
||||
string homeDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
if (!string.IsNullOrEmpty(homeDirectory)) {
|
||||
Directory.SetCurrentDirectory(homeDirectory);
|
||||
|
@ -405,7 +405,7 @@ namespace ArchiSteamFarm {
|
|||
e.SetObserved();
|
||||
}
|
||||
|
||||
private static void ParsePostInitArgs(IEnumerable<string> args) {
|
||||
private static void ParsePostInitArgs(IReadOnlyCollection<string> args) {
|
||||
if (args == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(args));
|
||||
return;
|
||||
|
@ -461,7 +461,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
private static void ParsePreInitArgs(IEnumerable<string> args) {
|
||||
private static void ParsePreInitArgs(IReadOnlyCollection<string> args) {
|
||||
if (args == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(args));
|
||||
return;
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
private static bool IsTradeNeutralOrBetter(HashSet<Steam.Asset> inventory, HashSet<Steam.Asset> itemsToGive, HashSet<Steam.Asset> itemsToReceive) {
|
||||
private static bool IsTradeNeutralOrBetter(IReadOnlyCollection<Steam.Asset> inventory, IReadOnlyCollection<Steam.Asset> itemsToGive, IReadOnlyCollection<Steam.Asset> itemsToReceive) {
|
||||
if ((inventory == null) || (inventory.Count == 0) || (itemsToGive == null) || (itemsToGive.Count == 0) || (itemsToReceive == null) || (itemsToReceive.Count == 0)) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(inventory) + " || " + nameof(itemsToGive) + " || " + nameof(itemsToReceive));
|
||||
return false;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
|
@ -38,6 +39,16 @@ namespace ArchiSteamFarm {
|
|||
internal static class Utilities {
|
||||
private static readonly Random Random = new Random();
|
||||
|
||||
internal static IReadOnlyCollection<T> AsReadOnlyCollection<T>(this ICollection<T> source) {
|
||||
if (source == null) {
|
||||
ASF.ArchiLogger.LogNullError(nameof(source));
|
||||
return null;
|
||||
}
|
||||
|
||||
IReadOnlyCollection<T> result = source as IReadOnlyCollection<T> ?? new ReadOnlyCollectionAdapter<T>(source);
|
||||
return result;
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static void Forget(this object obj) { }
|
||||
|
@ -152,10 +163,6 @@ namespace ArchiSteamFarm {
|
|||
Task.Factory.StartNew(function, options).Forget();
|
||||
}
|
||||
|
||||
internal static IEnumerable<T> ToEnumerable<T>(this T item) where T : struct {
|
||||
yield return item;
|
||||
}
|
||||
|
||||
internal static string ToHumanReadable(this TimeSpan timeSpan) => timeSpan.Humanize(3, maxUnit: TimeUnit.Year);
|
||||
|
||||
private static string[] GetArgs(string[] args, byte argsToSkip = 1) {
|
||||
|
@ -173,5 +180,21 @@ namespace ArchiSteamFarm {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static IEnumerable<T> ToEnumerable<T>(this T item) {
|
||||
yield return item;
|
||||
}
|
||||
|
||||
private sealed class ReadOnlyCollectionAdapter<T> : IReadOnlyCollection<T> {
|
||||
public int Count => Source.Count;
|
||||
|
||||
private readonly ICollection<T> Source;
|
||||
|
||||
internal ReadOnlyCollectionAdapter(ICollection<T> source) => Source = source ?? throw new ArgumentNullException(nameof(source));
|
||||
|
||||
public IEnumerator<T> GetEnumerator() => Source.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -216,7 +216,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
internal async Task<bool> UrlPost(string request, ICollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
internal async Task<bool> UrlPost(string request, IReadOnlyCollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
ArchiLogger.LogNullError(nameof(request));
|
||||
return false;
|
||||
|
@ -227,7 +227,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
internal async Task<bool> UrlPostRetry(string request, ICollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
internal async Task<bool> UrlPostRetry(string request, IReadOnlyCollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
ArchiLogger.LogNullError(nameof(request));
|
||||
return false;
|
||||
|
@ -247,7 +247,7 @@ namespace ArchiSteamFarm {
|
|||
return false;
|
||||
}
|
||||
|
||||
internal async Task<HtmlDocument> UrlPostToHtmlDocumentRetry(string request, ICollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
internal async Task<HtmlDocument> UrlPostToHtmlDocumentRetry(string request, IReadOnlyCollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
ArchiLogger.LogNullError(nameof(request));
|
||||
return null;
|
||||
|
@ -257,7 +257,7 @@ namespace ArchiSteamFarm {
|
|||
return !string.IsNullOrEmpty(content) ? StringToHtmlDocument(content) : null;
|
||||
}
|
||||
|
||||
internal async Task<T> UrlPostToJsonResultRetry<T>(string request, ICollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
internal async Task<T> UrlPostToJsonResultRetry<T>(string request, IReadOnlyCollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
ArchiLogger.LogNullError(nameof(request));
|
||||
return default;
|
||||
|
@ -405,7 +405,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<string> UrlPostToContent(string request, ICollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
private async Task<string> UrlPostToContent(string request, IReadOnlyCollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
ArchiLogger.LogNullError(nameof(request));
|
||||
return null;
|
||||
|
@ -420,7 +420,7 @@ namespace ArchiSteamFarm {
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<string> UrlPostToContentRetry(string request, ICollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
private async Task<string> UrlPostToContentRetry(string request, IReadOnlyCollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
if (string.IsNullOrEmpty(request)) {
|
||||
ArchiLogger.LogNullError(nameof(request));
|
||||
return null;
|
||||
|
@ -440,7 +440,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage> UrlPostToResponse(string request, ICollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
private async Task<HttpResponseMessage> UrlPostToResponse(string request, IReadOnlyCollection<KeyValuePair<string, string>> data = null, string referer = null) {
|
||||
if (!string.IsNullOrEmpty(request)) {
|
||||
return await UrlRequest(new Uri(request), HttpMethod.Post, data, referer).ConfigureAwait(false);
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ namespace ArchiSteamFarm {
|
|||
return null;
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage> UrlRequest(Uri requestUri, HttpMethod httpMethod, ICollection<KeyValuePair<string, string>> data = null, string referer = null, byte maxRedirections = MaxTries) {
|
||||
private async Task<HttpResponseMessage> UrlRequest(Uri requestUri, HttpMethod httpMethod, IReadOnlyCollection<KeyValuePair<string, string>> data = null, string referer = null, byte maxRedirections = MaxTries) {
|
||||
if ((requestUri == null) || (httpMethod == null)) {
|
||||
ArchiLogger.LogNullError(nameof(requestUri) + " || " + nameof(httpMethod));
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue