コード例 #1
0
        public override async Task <IEnumerable <ITraktUserEpisodesStatistics> > ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(IEnumerable <ITraktUserEpisodesStatistics>)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
            {
                var userEpisodesStatisticsReader = new UserEpisodesStatisticsObjectJsonReader();
                var userEpisodesStatisticss      = new List <ITraktUserEpisodesStatistics>();
                ITraktUserEpisodesStatistics userEpisodesStatistics = await userEpisodesStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);

                while (userEpisodesStatistics != null)
                {
                    userEpisodesStatisticss.Add(userEpisodesStatistics);
                    userEpisodesStatistics = await userEpisodesStatisticsReader.ReadObjectAsync(jsonReader, cancellationToken);
                }

                return(userEpisodesStatisticss);
            }

            return(await Task.FromResult(default(IEnumerable <ITraktUserEpisodesStatistics>)));
        }
コード例 #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)));
        }