/// <inheritdoc /> public async IAsyncEnumerable <BasicInfo> GetResponse(string entityName, bool outputResults) { TmdbServiceConfiguration.SetServiceConfigurationOnce( await GetServiceConfiguration(outputResults) ); TmdbSearchContainer?response = await _tmdbClient.TrySearchMovieAsync(entityName); if (response is null || response.Results.IsNullOrEmpty()) { string message = $"{entityName} was not processed."; _logger.Warn(message); GlobalMessageHandler.OutputMessage(message); yield break; } // Get first search result from response and ignore all the rest. TmdbMovieInfo searchResult = response.Results.First(); if (outputResults) { GlobalMessageHandler.OutputMessage($"Got {searchResult.Title} from \"{Tag}\"."); } if (_searchResults.Add(searchResult)) { yield return(searchResult); } yield break; }
/// <inheritdoc /> public IReadOnlyList <BasicInfo> GetResponse(IReadOnlyList <string> entities, bool outputResults) { TmdbServiceConfiguration.SetServiceConfigurationOnce( GetServiceConfiguration(outputResults) ); // Use HashSet to avoid duplicated data which can produce errors in further work. var searchResults = new HashSet <BasicInfo>(); foreach (string movie in entities) { TmdbSearchContainer?response = _tmdbClient.TrySearchMovieAsync(movie).Result; if (response is null || response.Results.IsNullOrEmpty()) { string message = $"{movie} was not processed."; _logger.Warn(message); GlobalMessageHandler.OutputMessage(message); continue; } // Get first search result from response and ignore all the rest. TmdbMovieInfo searchResult = response.Results.First(); if (outputResults) { GlobalMessageHandler.OutputMessage($"Got {searchResult.Title} from \"{Tag}\"."); } searchResults.Add(searchResult); } return(searchResults.ToList()); }