Beispiel #1
0
        private async void ProcessingLoop(object objParam)
        {
            var cancellationToken = (CancellationToken)objParam;

            while (!cancellationToken.IsCancellationRequested)
            {
                var gamesPage      = new Dictionary <string, Game>();
                int itemsToProcess = Config.ProcessingPageSize;
                while (itemsToProcess > 0)
                {
                    var game = await Queue.Dequeue();

                    if (game == null)
                    {
                        break;
                    }

                    var key = GamesProcessingHelper.BuildGameKey(game);
                    if (gamesPage.TryAdd(key, game))
                    {
                        itemsToProcess--;
                    }
                }

                if (gamesPage.Count > 0)
                {
                    await Storage.AddGames(gamesPage.Values);
                }
                else
                {
                    await Task.Delay(Config.DelayMsOnIdle);
                }
            }
        }
        public Task AddGames(IEnumerable <Game> games)
        {
            lock (_tableOfGames)
            {
                foreach (var game in games)
                {
                    var key = GamesProcessingHelper.BuildGameKey(game);
                    _tableOfGames.TryAdd(key, game);
                }
            }

            return(Task.FromResult(1));
        }
        public Task <IEnumerable <Game> > FilterAlreadyPresent(IEnumerable <Game> games)
        {
            var retVal = new List <Game>();

            foreach (var game in games)
            {
                var key = GamesProcessingHelper.BuildGameKey(game);
                if (!_tableOfGames.ContainsKey(key))
                {
                    retVal.Add(game);
                }
            }

            return(Task.FromResult((IEnumerable <Game>)retVal));
        }