コード例 #1
0
ファイル: Service.cs プロジェクト: asolfre/TVShow
        /// <summary>
        /// Get the data from a movie (Torrent file url, images url, ...)
        /// </summary>
        /// <param name="movieId">The unique identifier of a movie</param>
        /// <param name="cancellationToken">cancellationToken</param>
        public async Task <Tuple <MovieFullDetails, IEnumerable <Exception> > > GetMovieAsync(int movieId,
                                                                                              CancellationTokenSource cancellationToken)
        {
            var restClient = new RestClient(Constants.YtsApiEndpoint);
            var request    = new RestRequest("/{segment}", Method.GET);

            request.AddUrlSegment("segment", "movie_details.json");

            request.AddParameter("movie_id", movieId);
            request.AddParameter("with_images", true);
            request.AddParameter("with_cast", true);

            List <Exception>        ex = new List <Exception>();
            WrapperMovieFullDetails responseWrapper = new WrapperMovieFullDetails();

            try
            {
                IRestResponse response = await restClient.ExecuteTaskAsync(request, cancellationToken.Token);

                if (response != null)
                {
                    responseWrapper =
                        JsonConvert.DeserializeObject <WrapperMovieFullDetails>(response.Content);
                }
            }
            catch (WebException webException)
            {
                ex.Add(webException);
            }
            catch (TaskCanceledException e)
            {
                ex.Add(e);
            }

            if (responseWrapper != null && responseWrapper.Movie != null)
            {
                return(new Tuple <MovieFullDetails, IEnumerable <Exception> >(responseWrapper.Movie, ex));
            }
            return(new Tuple <MovieFullDetails, IEnumerable <Exception> >(null, ex));
        }
コード例 #2
0
ファイル: Service.cs プロジェクト: garycarlyle/TVShow
        /// <summary>
        /// Get the data from a movie (Torrent file url, images url, ...)
        /// </summary>
        /// <param name="movieId">The unique identifier of a movie</param>
        /// <param name="cancellationToken">cancellationToken</param>
        public async Task<Tuple<MovieFullDetails, IEnumerable<Exception>>> GetMovieAsync(int movieId,
            CancellationTokenSource cancellationToken)
        {
            var restClient = new RestClient(Constants.YtsApiEndpoint);
            var request = new RestRequest("/{segment}", Method.GET);
            request.AddUrlSegment("segment", "movie_details.json");

            request.AddParameter("movie_id", movieId);
            request.AddParameter("with_images", true);
            request.AddParameter("with_cast", true);

            List<Exception> ex = new List<Exception>();
            WrapperMovieFullDetails responseWrapper = new WrapperMovieFullDetails();
            try
            {
                IRestResponse response = await restClient.ExecuteTaskAsync(request, cancellationToken.Token);
                if (response != null)
                {
                    responseWrapper =
                        JsonConvert.DeserializeObject<WrapperMovieFullDetails>(response.Content);
                }

            }
            catch (WebException webException)
            {
                ex.Add(webException);
            }
            catch (TaskCanceledException e)
            {
                ex.Add(e);
            }

            if (responseWrapper != null && responseWrapper.Movie != null)
            {
                return new Tuple<MovieFullDetails, IEnumerable<Exception>>(responseWrapper.Movie, ex);
            }
            return new Tuple<MovieFullDetails, IEnumerable<Exception>>(null, ex);
        }