public override async Task <ITraktEpisodeScrobblePost> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var episodeReader = new EpisodeObjectJsonReader();
                var showReader    = new ShowObjectJsonReader();
                ITraktEpisodeScrobblePost episodeScrobblePost = new TraktEpisodeScrobblePost();

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

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_PROGRESS:
                    {
                        Pair <bool, float> value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            episodeScrobblePost.Progress = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_APP_VERSION:
                        episodeScrobblePost.AppVersion = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_APP_DATE:
                        episodeScrobblePost.AppDate = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SHOW:
                        episodeScrobblePost.Show = await showReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_EPISODE:
                        episodeScrobblePost.Episode = await episodeReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(episodeScrobblePost);
            }

            return(await Task.FromResult(default(ITraktEpisodeScrobblePost)));
        }
Пример #2
0
        public override async Task <ITraktMovieScrobblePost> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktMovieScrobblePost)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieReader = new MovieObjectJsonReader();
                ITraktMovieScrobblePost movieScrobblePost = new TraktMovieScrobblePost();

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

                    switch (propertyName)
                    {
                    case JsonProperties.SCROBBLE_POST_PROPERTY_NAME_PROGRESS:
                    {
                        Pair <bool, float> value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            movieScrobblePost.Progress = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.SCROBBLE_POST_PROPERTY_NAME_APP_VERSION:
                        movieScrobblePost.AppVersion = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.SCROBBLE_POST_PROPERTY_NAME_APP_DATE:
                        movieScrobblePost.AppDate = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.MOVIE_SCROBBLE_POST_PROPERTY_NAME_MOVIE:
                        movieScrobblePost.Movie = await movieReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(movieScrobblePost);
            }

            return(await Task.FromResult(default(ITraktMovieScrobblePost)));
        }
Пример #3
0
        public override async Task <ITraktRating> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktRating)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktRating traktRating = new TraktRating();

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

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

                        if (value.First)
                        {
                            traktRating.Rating = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.RATING_PROPERTY_NAME_VOTES:
                        traktRating.Votes = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.RATING_PROPERTY_NAME_DISTRIBUTION:
                        traktRating.Distribution = await JsonReaderHelper.ReadDistributionAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktRating);
            }

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

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieObjectReader   = new MovieObjectJsonReader();
                var showObjectReader    = new ShowObjectJsonReader();
                var episodeObjectReader = new EpisodeObjectJsonReader();
                var personObjectReader  = new PersonObjectJsonReader();
                var listObjectReader    = new ListObjectJsonReader();
                ITraktSearchResult traktSearchResult = new TraktSearchResult();

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

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_TYPE:
                        traktSearchResult.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktSearchResultType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SCORE:
                    {
                        var value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktSearchResult.Score = value.Second;
                        }

                        break;
                    }

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

                        break;

                    case JsonProperties.PROPERTY_NAME_SHOW:
                        traktSearchResult.Show = await showObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_EPISODE:
                        traktSearchResult.Episode = await episodeObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_PERSON:
                        traktSearchResult.Person = await personObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_LIST:
                        traktSearchResult.List = await listObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktSearchResult);
            }

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

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var userReader = new UserObjectJsonReader();
                ITraktComment traktComment = new TraktComment();

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

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

                                if (value.First)
                                    traktComment.Id = value.Second;

                                break;
                            }
                        case JsonProperties.PROPERTY_NAME_PARENT_ID:
                            {
                                var value = await JsonReaderHelper.ReadUnsignedIntegerValueAsync(jsonReader, cancellationToken);

                                if (value.First)
                                    traktComment.ParentId = value.Second;

                                break;
                            }
                        case JsonProperties.PROPERTY_NAME_CREATED_AT:
                            {
                                var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken);

                                if (value.First)
                                    traktComment.CreatedAt = value.Second;

                                break;
                            }
                        case JsonProperties.PROPERTY_NAME_UPDATED_AT:
                            {
                                var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken);

                                if (value.First)
                                    traktComment.UpdatedAt = value.Second;

                                break;
                            }
                        case JsonProperties.PROPERTY_NAME_COMMENT:
                            traktComment.Comment = await jsonReader.ReadAsStringAsync(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_SPOILER:
                            traktComment.Spoiler = (bool)await jsonReader.ReadAsBooleanAsync(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_REVIEW:
                            traktComment.Review = (bool)await jsonReader.ReadAsBooleanAsync(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_REPLIES:
                            traktComment.Replies = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_LIKES:
                            traktComment.Likes = await jsonReader.ReadAsInt32Async(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_USER_RATING:
                            {
                                var value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                                if (value.First)
                                    traktComment.UserRating = value.Second;

                                break;
                            }
                        case JsonProperties.PROPERTY_NAME_USER:
                            traktComment.User = await userReader.ReadObjectAsync(jsonReader, cancellationToken);
                            break;
                        default:
                            await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);
                            break;
                    }
                }

                return traktComment;
            }

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

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieObjectReader   = new MovieObjectJsonReader();
                var showObjectReader    = new ShowObjectJsonReader();
                var episodeObjectReader = new EpisodeObjectJsonReader();

                ITraktSyncPlaybackProgressItem traktPlaybackProgressItem = new TraktSyncPlaybackProgressItem();

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

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

                        if (value.First)
                        {
                            traktPlaybackProgressItem.Id = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_PROGRESS:
                    {
                        var value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktPlaybackProgressItem.Progress = value.Second;
                        }

                        break;
                    }

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

                        if (value.First)
                        {
                            traktPlaybackProgressItem.PausedAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_TYPE:
                        traktPlaybackProgressItem.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktSyncType>(jsonReader, cancellationToken);

                        break;

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

                        break;

                    case JsonProperties.PROPERTY_NAME_SHOW:
                        traktPlaybackProgressItem.Show = await showObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_EPISODE:
                        traktPlaybackProgressItem.Episode = await episodeObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktPlaybackProgressItem);
            }

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

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var sharingReader = new SharingObjectJsonReader();
                var episodeReader = new EpisodeObjectJsonReader();
                var showReader    = new ShowObjectJsonReader();
                ITraktEpisodeScrobblePostResponse episodeScrobbleResponse = new TraktEpisodeScrobblePostResponse();

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

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

                        if (value.First)
                        {
                            episodeScrobbleResponse.Id = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_ACTION:
                        episodeScrobbleResponse.Action = await JsonReaderHelper.ReadEnumerationValueAsync <TraktScrobbleActionType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_PROGRESS:
                    {
                        var value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            episodeScrobbleResponse.Progress = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_SHARING:
                        episodeScrobbleResponse.Sharing = await sharingReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_EPISODE:
                        episodeScrobbleResponse.Episode = await episodeReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SHOW:
                        episodeScrobbleResponse.Show = await showReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(episodeScrobbleResponse);
            }

            return(await Task.FromResult(default(ITraktEpisodeScrobblePostResponse)));
        }
Пример #8
0
        public override async Task <ITraktMovieScrobblePostResponse> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktMovieScrobblePostResponse)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var sharingReader = new SharingObjectJsonReader();
                var movieReader   = new MovieObjectJsonReader();
                ITraktMovieScrobblePostResponse movieScrobbleResponse = new TraktMovieScrobblePostResponse();

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

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

                        if (value.First)
                        {
                            movieScrobbleResponse.Id = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.SCROBBLE_POST_RESPONSE_PROPERTY_NAME_ACTION:
                        movieScrobbleResponse.Action = await JsonReaderHelper.ReadEnumerationValueAsync <TraktScrobbleActionType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.SCROBBLE_POST_RESPONSE_PROPERTY_NAME_PROGRESS:
                    {
                        var value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            movieScrobbleResponse.Progress = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.SCROBBLE_POST_RESPONSE_PROPERTY_NAME_SHARING:
                        movieScrobbleResponse.Sharing = await sharingReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.MOVIE_SCROBBLE_POST_RESPONSE_PROPERTY_NAME_MOVIE:
                        movieScrobbleResponse.Movie = await movieReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(movieScrobbleResponse);
            }

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