/// <inheritdoc />
        public override async Task <bool> GetResponse(BufferBlock <string> entitiesQueue,
                                                      BufferBlock <BasicInfo> responsesQueue, bool outputResults)
        {
            if (SteamAppsStorage.IsEmpty)
            {
                SteamAppBriefInfoList steamAppsList = await _steamApiClient.GetAppListAsync();

                SteamAppsStorage.FillStorage(steamAppsList);
            }

            // Use HashSet to avoid duplicated data which can produce errors in further work.
            var searchResults = new HashSet <BasicInfo>();

            while (await entitiesQueue.OutputAvailableAsync())
            {
                string game = await entitiesQueue.ReceiveAsync();

                SteamApp response;
                try
                {
                    int appId = SteamAppsStorage.GetAppIdByName(game);
                    response = await _steamApiClient.GetSteamAppAsync(
                        appId, CountryCode.Russia, Language.English
                        );
                }
                catch (Exception ex)
                {
                    _logger.Warn(ex, $"{game} wasn't processed.");
                    GlobalMessageHandler.OutputMessage($"{game} wasn't processed.");
                    continue;
                }

                if (outputResults)
                {
                    GlobalMessageHandler.OutputMessage($"Got {response} from {Tag}");
                }

                SteamGameInfo extractedInfo = _dataMapper.Transform(response);
                if (searchResults.Add(extractedInfo))
                {
                    await responsesQueue.SendAsync(extractedInfo);
                }
            }
            return(searchResults.Count != 0);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public override List <BasicInfo> GetResponse(List <string> entities, bool outputResults)
        {
            if (SteamAppsStorage.IsEmpty)
            {
                SteamAppBriefInfoList steamAppsList = _steamApiClient.GetAppListAsync().Result;
                SteamAppsStorage.FillStorage(steamAppsList);
            }

            // Use HashSet to avoid duplicated data which can produce errors in further work.
            var searchResults = new HashSet <BasicInfo>();

            foreach (string game in entities)
            {
                SteamApp response;
                try
                {
                    int appId = SteamAppsStorage.GetAppIdByName(game);
                    response = _steamApiClient.GetSteamAppAsync(
                        appId, CountryCode.Russia, Language.English
                        ).Result;
                }
                catch (Exception ex)
                {
                    _logger.Warn(ex, $"{game} wasn't processed.");
                    GlobalMessageHandler.OutputMessage($"{game} wasn't processed.");
                    continue;
                }

                if (outputResults)
                {
                    GlobalMessageHandler.OutputMessage($"Got {response} from {Tag}");
                }

                SteamGameInfo extractedInfo = _dataMapper.Transform(response);
                searchResults.Add(extractedInfo);
            }
            return(searchResults.ToList());
        }