Пример #1
0
        /// <inheritdoc />
        public IReadOnlyList <BasicInfo> GetResponse(IReadOnlyList <string> entities,
                                                     bool outputResults)
        {
            if (SteamAppsStorage.IsEmpty)
            {
                SteamBriefInfoContainer steamApps = _steamApiClient.GetAppListAsync().Result;
                SteamAppsStorage.FillStorage(steamApps);
            }

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

            foreach (string game in entities)
            {
                int?appId = SteamAppsStorage.TryGetAppIdByName(game);

                if (!appId.HasValue)
                {
                    string message = $"{game} was not find in Steam responses storage.";
                    _logger.Warn(message);
                    GlobalMessageHandler.OutputMessage(message);

                    continue;
                }

                var response = _steamApiClient.TryGetSteamAppAsync(
                    appId.Value, SteamCountryCode.Russia, SteamResponseLanguage.English
                    ).Result;

                if (response is null)
                {
                    string message = $"{game} was not processed.";
                    _logger.Warn(message);
                    GlobalMessageHandler.OutputMessage(message);

                    continue;
                }

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

                searchResults.Add(response);
            }
            return(searchResults.ToList());
        }
Пример #2
0
        /// <inheritdoc />
        public async IAsyncEnumerable <BasicInfo> GetResponse(string entityName, bool outputResults)
        {
            if (SteamAppsStorage.IsEmpty)
            {
                SteamBriefInfoContainer steamApps = await _steamApiClient.GetAppListAsync();

                SteamAppsStorage.FillStorage(steamApps);
            }

            int?appId = SteamAppsStorage.TryGetAppIdByName(entityName);

            if (!appId.HasValue)
            {
                string message = $"{entityName} was not find in Steam responses storage.";
                _logger.Warn(message);
                GlobalMessageHandler.OutputMessage(message);

                yield break;
            }

            var response = await _steamApiClient.TryGetSteamAppAsync(
                appId.Value, SteamCountryCode.Russia, SteamResponseLanguage.English
                );

            if (response is null)
            {
                string message = $"{entityName} was not processed.";
                _logger.Warn(message);
                GlobalMessageHandler.OutputMessage(message);

                yield break;
            }

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

            if (_searchResults.Add(response))
            {
                yield return(response);
            }

            yield break;
        }