示例#1
0
        public override async Task <ITraktUserFollowRequest> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktUserFollowRequest)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var userReader = new UserObjectJsonReader();
                ITraktUserFollowRequest traktUserFollowRequest = new TraktUserFollowRequest();

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

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

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

                        break;
                    }

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

                        if (value.First)
                        {
                            traktUserFollowRequest.RequestedAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.USER_FOLLOW_REQUEST_PROPERTY_NAME_USER:
                        traktUserFollowRequest.User = await userReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktUserFollowRequest);
            }

            return(await Task.FromResult(default(ITraktUserFollowRequest)));
        }
示例#2
0
        public override async Task <ITraktUserSettings> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktUserSettings)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var userReader            = new UserObjectJsonReader();
                var accountSettingsReader = new AccountSettingsObjectJsonReader();
                var sharingReader         = new SharingObjectJsonReader();
                var sharingTextReader     = new SharingTextObjectJsonReader();

                ITraktUserSettings traktUserSettings = new TraktUserSettings();

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

                    switch (propertyName)
                    {
                    case JsonProperties.USER_SETTINGS_PROPERTY_NAME_USER:
                        traktUserSettings.User = await userReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_SETTINGS_PROPERTY_NAME_ACCOUNT:
                        traktUserSettings.Account = await accountSettingsReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_SETTINGS_PROPERTY_NAME_CONNECTIONS:
                        traktUserSettings.Connections = await sharingReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_SETTINGS_PROPERTY_NAME_SHARING_TEXT:
                        traktUserSettings.SharingText = await sharingTextReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktUserSettings);
            }

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

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var userReader = new UserObjectJsonReader();
                ITraktUserFriend traktUserFriend = new TraktUserFriend();

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

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

                        if (value.First)
                        {
                            traktUserFriend.FriendsAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.USER_FRIEND_PROPERTY_NAME_USER:
                        traktUserFriend.User = await userReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktUserFriend);
            }

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