Esempio n. 1
0
        public override async Task <IEnumerable <ITraktMovie> > ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(IEnumerable <ITraktMovie>)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
            {
                var movieReader = new MovieObjectJsonReader();
                //var traktMovieReadingTasks = new List<Task<ITraktMovie>>();
                var traktMovies = new List <ITraktMovie>();

                //traktMovieReadingTasks.Add(movieReader.ReadObjectAsync(jsonReader, cancellationToken));
                ITraktMovie traktMovie = await movieReader.ReadObjectAsync(jsonReader, cancellationToken);

                while (traktMovie != null)
                {
                    traktMovies.Add(traktMovie);
                    //traktMovieReadingTasks.Add(movieReader.ReadObjectAsync(jsonReader, cancellationToken));
                    traktMovie = await movieReader.ReadObjectAsync(jsonReader, cancellationToken);
                }

                //var readMovies = await Task.WhenAll(traktMovieReadingTasks);
                //return (IEnumerable<ITraktMovie>)readMovies.GetEnumerator();
                return(traktMovies);
            }

            return(await Task.FromResult(default(IEnumerable <ITraktMovie>)));
        }
        public override async Task <ITraktMostPWCMovie> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktMostPWCMovie)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieObjectReader = new MovieObjectJsonReader();
                ITraktMostPWCMovie traktMostPWCMovie = new TraktMostPWCMovie();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.MOST_PWC_MOVIE_PROPERTY_NAME_WATCHER_COUNT:
                        traktMostPWCMovie.WatcherCount = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.MOST_PWC_MOVIE_PROPERTY_NAME_PLAY_COUNT:
                        traktMostPWCMovie.PlayCount = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.MOST_PWC_MOVIE_PROPERTY_NAME_COLLECTED_COUNT:
                        traktMostPWCMovie.CollectedCount = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.MOST_PWC_MOVIE_PROPERTY_NAME_MOVIE:
                        traktMostPWCMovie.Movie = await movieObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktMostPWCMovie);
            }

            return(await Task.FromResult(default(ITraktMostPWCMovie)));
        }
        public override async Task <ITraktRecentlyUpdatedMovie> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktRecentlyUpdatedMovie)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieObjectReader = new MovieObjectJsonReader();
                ITraktRecentlyUpdatedMovie traktRecentlyUpdatedMovie = new TraktRecentlyUpdatedMovie();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.RECENTLY_UPDATED_MOVIE_PROPERTY_NAME_UPDATED_AT:
                    {
                        var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktRecentlyUpdatedMovie.RecentlyUpdatedAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.RECENTLY_UPDATED_MOVIE_PROPERTY_NAME_MOVIE:
                        traktRecentlyUpdatedMovie.Movie = await movieObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktRecentlyUpdatedMovie);
            }

            return(await Task.FromResult(default(ITraktRecentlyUpdatedMovie)));
        }
Esempio n. 4
0
        public override async Task <ITraktBoxOfficeMovie> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktBoxOfficeMovie)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieObjectReader = new MovieObjectJsonReader();
                ITraktBoxOfficeMovie traktBoxOfficeMovie = new TraktBoxOfficeMovie();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.BOX_OFFICE_MOVIE_PROPERTY_NAME_REVENUE:
                        traktBoxOfficeMovie.Revenue = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.BOX_OFFICE_MOVIE_PROPERTY_NAME_MOVIE:
                        traktBoxOfficeMovie.Movie = await movieObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktBoxOfficeMovie);
            }

            return(await Task.FromResult(default(ITraktBoxOfficeMovie)));
        }
        public override async Task <ITraktTrendingMovie> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieObjectReader = new MovieObjectJsonReader();
                ITraktTrendingMovie traktTrendingMovie = new TraktTrendingMovie();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_WATCHERS:
                        traktTrendingMovie.Watchers = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_MOVIE:
                        traktTrendingMovie.Movie = await movieObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktTrendingMovie);
            }

            return(await Task.FromResult(default(ITraktTrendingMovie)));
        }