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

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
            {
                var userMoviesStatisticsReader = new UserMoviesStatisticsObjectJsonReader();
                var userMoviesStatisticss      = new List <ITraktUserMoviesStatistics>();
                ITraktUserMoviesStatistics userMoviesStatistics = await userMoviesStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                while (userMoviesStatistics != null)
                {
                    userMoviesStatisticss.Add(userMoviesStatistics);
                    userMoviesStatistics = await userMoviesStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);
                }

                return(userMoviesStatisticss);
            }

            return(await Task.FromResult(default(IEnumerable <ITraktUserMoviesStatistics>)));
        }
예제 #2
0
        public override async Task <ITraktUserStatistics> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var moviesStatisticsReader   = new UserMoviesStatisticsObjectJsonReader();
                var showsStatisticsReader    = new UserShowsStatisticsObjectJsonReader();
                var seasonsStatisticsReader  = new UserSeasonsStatisticsObjectJsonReader();
                var episodesStatisticsReader = new UserEpisodesStatisticsObjectJsonReader();
                var networkStatisticsReader  = new UserNetworkStatisticsObjectJsonReader();
                var ratingsStatisticsReader  = new UserRatingsStatisticsObjectJsonReader();

                ITraktUserStatistics userStatistics = new TraktUserStatistics();

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

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_MOVIES:
                        userStatistics.Movies = await moviesStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SHOWS:
                        userStatistics.Shows = await showsStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SEASONS:
                        userStatistics.Seasons = await seasonsStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_EPISODES:
                        userStatistics.Episodes = await episodesStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_NETWORK:
                        userStatistics.Network = await networkStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_RATINGS:
                        userStatistics.Ratings = await ratingsStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(userStatistics);
            }

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