/// <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()); }
/// <inheritdoc /> public override List <BasicInfo> GetResponse(List <string> entities, bool outputResults) { if (!TmdbServiceConfiguration.HasValue) { TmdbServiceConfiguration.SetServiceConfigurationIfNeed( 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) { SearchContainer <SearchMovie> response = _tmdbClient.SearchMovieAsync(movie).Result; if (response.Results.IsNullOrEmpty()) { _logger.Warn($"{movie} wasn't processed."); GlobalMessageHandler.OutputMessage($"{movie} wasn't processed."); continue; } // Get first search result from response and ignore all the rest. SearchMovie searchResult = response.Results.First(); if (outputResults) { GlobalMessageHandler.OutputMessage($"Got {searchResult.Title} from {Tag}"); } TmdbMovieInfo extractedInfo = _dataMapper.Transform(searchResult); searchResults.Add(extractedInfo); } return(searchResults.ToList()); }
protected static double CalculateRating(TmdbMovieInfo entity, MinMaxDenominator voteCountMMD, MinMaxDenominator voteAverageMMD, MinMaxDenominator popularityMMD) { double baseValue = CalculateRating(entity, voteCountMMD, voteAverageMMD); double popValue = (entity.Popularity - popularityMMD.MinValue) / popularityMMD.Denominator; return(baseValue + popValue); }
private IImageSupplier DetermineImageSupplier(BasicInfo basicInfo) { basicInfo.ThrowIfNull(nameof(basicInfo)); return(basicInfo switch { OmdbMovieInfo _ => new OmdbImageSupplier(), TmdbMovieInfo _ => new TmdbImageSupplier(TmdbServiceConfiguration.Configuration), SteamGameInfo _ => new SteamImageSupplier(), _ => throw new ArgumentOutOfRangeException(nameof(basicInfo), basicInfo, "Got unknown type to process.") });
public override async Task <bool> GetResponse(BufferBlock <string> entitiesQueue, BufferBlock <BasicInfo> responsesQueue, bool outputResults) { if (!TmdbServiceConfiguration.HasValue) { TmdbServiceConfiguration.SetServiceConfigurationIfNeed( await GetServiceConfiguration(outputResults) ); } // Use HashSet to avoid duplicated data which can produce errors in further work. var searchResults = new HashSet <BasicInfo>(); while (await entitiesQueue.OutputAvailableAsync()) { string movie = await entitiesQueue.ReceiveAsync(); SearchContainer <SearchMovie> response = await _tmdbClient.SearchMovieAsync(movie); if (response.Results.IsNullOrEmpty()) { _logger.Warn($"{movie} wasn't processed."); GlobalMessageHandler.OutputMessage($"{movie} wasn't processed."); continue; } // Get first search result from response and ignore all the rest. SearchMovie searchResult = response.Results.First(); if (outputResults) { GlobalMessageHandler.OutputMessage($"Got {searchResult.Title} from {Tag}"); } TmdbMovieInfo extractedInfo = _dataMapper.Transform(searchResult); if (searchResults.Add(extractedInfo)) { await responsesQueue.SendAsync(extractedInfo); } } return(searchResults.Count != 0); }
private static void TestEntityFrameworkCore() { using (var context = new ThingAppraiserContext()) { var tmdbMovie = new TmdbMovieInfo( thingId: 1, title: "Test", voteCount: 100, voteAverage: 10.0, overview: "Overview", releaseDate: DateTime.UtcNow, popularity: 50.0, adult: true, genreIds: new List <int> { 1, 2, 4 }, posterPath: "None" ); context.Add(tmdbMovie); int count = context.SaveChanges(); Console.WriteLine($"{count.ToString()} records saved to database."); } using (var context = new ThingAppraiserContext()) { foreach (TmdbMovieInfo tmdbMovie in context.TmdbMovies) { Console.WriteLine( $"TMDB movie: {tmdbMovie.ThingId.ToString()}, {tmdbMovie.Title}, " + $"{tmdbMovie.Popularity.ToString()}" ); } } }