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

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
            {
                var userRatingsStatisticsReader = new UserRatingsStatisticsObjectJsonReader();
                var userRatingsStatisticss      = new List <ITraktUserRatingsStatistics>();
                ITraktUserRatingsStatistics userRatingsStatistics = await userRatingsStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                while (userRatingsStatistics != null)
                {
                    userRatingsStatisticss.Add(userRatingsStatistics);
                    userRatingsStatistics = await userRatingsStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);
                }

                return(userRatingsStatisticss);
            }

            return(await Task.FromResult(default(IEnumerable <ITraktUserRatingsStatistics>)));
        }
示例#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)));
        }