// ReSharper disable once ExcessiveIndentation // ReSharper disable once TooManyArguments private static async Task <UserAppInventory> GetUserInventoryAlternate( SteamWebAccess steamWebAccess, SteamID steamId, long appId, long contextId) { var startPosition = 0; var assets = new List <UserInventoryAsset>(); var assetDescriptions = new List <UserInventoryAssetDescription>(); var appInfos = new List <UserInventoryApp>(); do { var retrySuccess = false; for (var retry = 0; retry < 3; retry++) { try { var response = await steamWebAccess.FetchObject <InventoryResponseV1>( new SteamWebAccessRequest( string.Format(UserInventoryV1Url, steamId.ConvertToUInt64(), appId, contextId), SteamWebAccessRequestMethod.Get, startPosition > 0 ? QueryStringBuilder.FromDynamic(new { start = startPosition }) : null ) { Referer = TradeOfferManager.TradeOfferNewUrl } ).ConfigureAwait(false); if (response?.Success == true) { retrySuccess = true; foreach (var inventoryAsset in response.Assets) { var steamInventoryAsset = inventoryAsset.Value.ToSteamInventoryAsset(appId, contextId); if (!assets.Contains(steamInventoryAsset)) { assets.Add(steamInventoryAsset); } } foreach (var itemDescription in response.Descriptions) { var steamAssetDescription = itemDescription.Value.ToSteamAssetDescription(); if (!assetDescriptions.Contains(steamAssetDescription)) { assetDescriptions.Add(steamAssetDescription); } } foreach (var app in response.Apps ?? new InventoryAppInfoV1[0]) { appInfos.Add(app.ToSteamInventoryAsset()); } if (!response.More) { return(new UserAppInventory(assets.ToArray(), assetDescriptions.ToArray(), appInfos.ToArray())); } startPosition = response.MoreStart; break; } } catch (WebException) { // ignored } } if (!retrySuccess) { throw new UserInventoryFetchAssetsException(appId, contextId, steamId); } await Task.Delay(TimeSpan.FromMilliseconds(300)).ConfigureAwait(false); } while (true); }
// ReSharper disable once TooManyArguments // ReSharper disable once MethodTooLong // ReSharper disable once ExcessiveIndentation private static async Task <UserAppInventory> GetUserInventory( SteamWebAccess steamWebAccess, SteamID userSteamId, long appId, long contextId) { var startAssetId = 0L; var assets = new List <UserInventoryAsset>(); var assetDescriptions = new List <UserInventoryAssetDescription>(); do { var retrySuccess = false; Exception lastException = null; for (var retry = 0; retry < 3; retry++) { try { var response = await steamWebAccess.FetchObject <InventoryResponseV2>( new SteamWebAccessRequest( string.Format(UserInventoryV2Url, userSteamId.ConvertToUInt64(), appId, contextId), SteamWebAccessRequestMethod.Get, startAssetId > 0 ? QueryStringBuilder.FromDynamic(new { l = "english", count = 2000, start_assetid = startAssetId }) : QueryStringBuilder.FromDynamic(new { l = "english", count = 2000 }) ) { Referer = string.Format(UserInventoryUrl, userSteamId.ConvertToUInt64()) } ).ConfigureAwait(false); if (response?.Success == true) { retrySuccess = true; foreach (var inventoryAsset in response.Assets) { var steamInventoryAsset = inventoryAsset.ToSteamInventoryAsset(); if (!assets.Contains(steamInventoryAsset)) { assets.Add(steamInventoryAsset); } } foreach (var itemDescription in response.Descriptions) { var steamAssetDescription = itemDescription.ToSteamAssetDescription(); if (!assetDescriptions.Contains(steamAssetDescription)) { assetDescriptions.Add(steamAssetDescription); } } if (!response.MoreItems || response.LastAssetId == null) { return(new UserAppInventory(assets.ToArray(), assetDescriptions.ToArray(), null)); } startAssetId = response.LastAssetId.Value; break; } } catch (WebException e) { lastException = e; } } if (!retrySuccess) { throw new UserInventoryFetchAssetsException(appId, contextId, userSteamId, lastException); } await Task.Delay(TimeSpan.FromMilliseconds(300)).ConfigureAwait(false); } while (true); }