Example #1
0
        // ReSharper disable once MethodTooLong
        // ReSharper disable once ExcessiveIndentation
        private async Task FillAppContextCache(UserInventoryApp inventoryApp, UserInventoryAppContext appContext)
        {
            await _lockObject.WaitAsync().ConfigureAwait(false);

            try
            {
                bool doesContainsContext;

                lock (_inventoryCache)
                {
                    doesContainsContext = _inventoryCache[inventoryApp.AppId].ContainsKey(appContext.ContextId);
                }

                if (!doesContainsContext)
                {
                    try
                    {
                        var contextInventory =
                            await _getInventoryDelegate(_steamWebAccess, SteamId, inventoryApp.AppId,
                                                        appContext.ContextId)
                            .ConfigureAwait(false);

                        if (contextInventory != null)
                        {
                            lock (_inventoryCache)
                            {
                                _inventoryCache[inventoryApp.AppId].Add(appContext.ContextId, contextInventory);
                            }

                            foreach (var userInventoryApp in contextInventory.ExtraAppInformation)
                            {
                                lock (_inventoryApps)
                                {
                                    var oldInventoryApp =
                                        _inventoryApps.FirstOrDefault(app => app.AppId == userInventoryApp.AppId);

                                    if (oldInventoryApp != null)
                                    {
                                        oldInventoryApp.Update(userInventoryApp);
                                    }
                                    else
                                    {
                                        _inventoryApps.Add(userInventoryApp);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        throw new UserInventoryFetchAssetsException(inventoryApp.AppId, appContext.ContextId, SteamId,
                                                                    e);
                    }
                }
            }
            finally
            {
                _lockObject.Release();
            }
        }
Example #2
0
        internal void Update(UserInventoryAppContext sameContext)
        {
            if (ContextId != sameContext.ContextId)
            {
                return;
            }

            ContextName = sameContext.ContextName ?? ContextName;
        }
Example #3
0
        public async Task <UserInventoryAssetDescription> GetAssetDescription(UserInventoryAsset asset)
        {
            UserInventoryApp        inventoryApp;
            UserInventoryAppContext appContext;

            lock (_inventoryApps)
            {
                inventoryApp = _inventoryApps.FirstOrDefault(app => app.AppId == asset.AppId);

                if (inventoryApp == null)
                {
                    inventoryApp = new UserInventoryApp(asset.AppId);
                    _inventoryApps.Add(inventoryApp);
                }

                appContext = inventoryApp.Contexts.FirstOrDefault(context => context.ContextId == asset.ContextId);

                if (appContext == null)
                {
                    appContext = new UserInventoryAppContext(asset.ContextId);
                    inventoryApp.Update(
                        new UserInventoryApp(inventoryApp.AppId, null, null, new[] { appContext }, null, null, null)
                        );
                }
            }

            lock (_inventoryCache)
            {
                if (!_inventoryCache.ContainsKey(inventoryApp.AppId))
                {
                    _inventoryCache.Add(inventoryApp.AppId, new Dictionary <long, UserAppInventory>());
                }
            }

            await FillAppContextCache(inventoryApp, appContext).ConfigureAwait(false);

            lock (_inventoryCache)
            {
                return(_inventoryCache[inventoryApp.AppId]
                       .Where(pair => pair.Key == appContext.ContextId)
                       .SelectMany(pair => pair.Value.AssetDescriptions)
                       .FirstOrDefault(description => description.DoesDescribe(asset)));
            }
        }