コード例 #1
0
        public async Task <PersonsMovieCreditsModel> LoadPersonsMovieCredits(int personId, int retryCount, int delayMilliseconds, bool fromCahe = true)
        {
            var response = await _tmdbApiService.TryGetPersonsMovieCredits(personId, _settings.SearchLanguage, retryCount, delayMilliseconds, fromCache : fromCahe);

            if (response.HttpStatusCode.IsSuccessCode())
            {
                var result = response.PersonsMovieCreditsModel;

                // Task.Run() decouples this time consuming operation from the calling UI thread
                await Task.Run(() =>
                {
                    _movieDetailModelConfigurator.SetImageSrc(result.MoviesAsActor);
                    _movieDetailModelConfigurator.SetImageSrc(result.MoviesAsCrewMember);
                    _movieDetailModelConfigurator.SetGenreNamesFromGenreIds(result.MoviesAsActor);
                    _movieDetailModelConfigurator.SetGenreNamesFromGenreIds(result.MoviesAsCrewMember);
                    result.SortMoviesByYearDesc();
                });

                return(result);
            }
            else
            {
                throw new Exception($"Could not load persons movie participations,  {nameof(LoadPersonsMovieCredits)} responded :{response.HttpStatusCode}");
            }
        }
コード例 #2
0
        public async Task <SearchResult> LoadSimilarMoviesPage(int movieId, int page, int retryCount, int delayMilliseconds)
        {
            var response = await _tmdbApiService.TryGetSimilarMovies(movieId, _settings.SearchLanguage, page, retryCount, delayMilliseconds);

            if (response.HttpStatusCode.IsSuccessCode())
            {
                var result = response.SimilarMovies;
                result.MovieDetailModels = new ObservableCollection <MovieDetailModel>(_searchResultFilter.FilterBySearchSettings(result.MovieDetailModels));

                _movieDetailModelConfigurator.SetImageSrc(result.MovieDetailModels);
                _movieDetailModelConfigurator.SetGenreNamesFromGenreIds(result.MovieDetailModels);

                return(result);
            }
            else
            {
                throw new Exception($"Could not update the similar movies list, service responded with: {response.HttpStatusCode}");
            }
        }
コード例 #3
0
        /// <summary>
        /// Not allowed to throw if targetList != NULL
        /// Appends the movie collection in the "MovieDetailModels" property of the server response
        /// to the target's same named property. Updates the targets page and result counters from the serverResponse
        /// </summary>
        /// <param name="targetList">this is the public observered collection wich is updated with data from the server's response</param>
        /// <param name="serverResponse">contains the server's response, containing movies to append to the observed collection and page/result counter</param>
        public static void AppendResult(this SearchResult targetList, SearchResult serverResponse, IMovieDetailModelConfigurator movieDetailConfigurator)
        {
            if (serverResponse.MovieDetailModels.Count > 0)
            {
                movieDetailConfigurator.SetImageSrc(serverResponse.MovieDetailModels);
                movieDetailConfigurator.SetGenreNamesFromGenreIds(serverResponse.MovieDetailModels);

                foreach (MovieDetailModel movie in serverResponse.MovieDetailModels)
                {
                    targetList.MovieDetailModels.Add(movie);
                }

                targetList.Page         = serverResponse.Page;
                targetList.TotalPages   = serverResponse.TotalPages;
                targetList.TotalResults = serverResponse.TotalResults;
            }
        }
コード例 #4
0
        /// <summary>
        /// Tries to fetch the requested page of the search results from the server.
        /// </summary>
        public async Task <SearchResult> LoadResultPage(string searchString, int pageToLoad, int retryCount, int delayMilliseconds, bool fromCache)
        {
            var pageResponse = await _tmdbApiService.TrySearchByMovie(searchString : searchString, _settings.SearchLanguage, !_settings.SafeSearch, pageToLoad, year : null, retryCount, delayMilliseconds, fromCache : fromCache);

            if (pageResponse.HttpStatusCode.IsSuccessCode())
            {
                var searchResult = pageResponse.SearchResult;

                var filteredResults = _settings.SafeSearch ? _resultFilter.FilterBySearchSettings(searchResult.MovieDetailModels) : _resultFilter.FilterBySearchSettingsIncludeAdult(searchResult.MovieDetailModels);
                searchResult.MovieDetailModels = new ObservableCollection <MovieDetailModel>(filteredResults);
                _movieDetailModelConfigurator.SetImageSrc(searchResult.MovieDetailModels);
                _movieDetailModelConfigurator.SetGenreNamesFromGenreIds(searchResult.MovieDetailModels);

                return(searchResult);
            }
            else
            {
                throw new Exception($"Could not load search results, service responded with: {pageResponse.HttpStatusCode}");
            }
        }
コード例 #5
0
        /// <summary>
        /// Tries to fetch the requested page of the trending movie list from the server.
        /// </summary>
        public async Task <SearchResult> LoadTrendingPage(bool week, int page, int retryCount, int delayMilliseconds)
        {
            var pageResponse = await _tmdbApiService.TryGetTrendingMovies(week : week, _settings.SearchLanguage, !_settings.SafeSearch, page, retryCount, delayMilliseconds);

            if (pageResponse.HttpStatusCode.IsSuccessCode())
            {
                var result = pageResponse.TrendingMovies;

                result.MovieDetailModels = new ObservableCollection <MovieDetailModel>(_resultFilter.FilterBySearchSettings(result.MovieDetailModels));

                _movieDetailConfigurator.SetImageSrc(result.MovieDetailModels);
                _movieDetailConfigurator.SetGenreNamesFromGenreIds(result.MovieDetailModels);

                return(result);
            }
            else
            {
                var timeSpan = week ? "weeks" : "days";
                throw new Exception($"Could not load the {timeSpan} trending list, service responded with: {pageResponse.HttpStatusCode}");
            }
        }