Ejemplo n.º 1
0
        public override async Task <IEnumerable <ITraktUserIds> > ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(IEnumerable <ITraktUserIds>)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
            {
                var           userIdsReader = new UserIdsObjectJsonReader();
                var           userIdss      = new List <ITraktUserIds>();
                ITraktUserIds userIds       = await userIdsReader.ReadObjectAsync(jsonReader, cancellationToken);

                while (userIds != null)
                {
                    userIdss.Add(userIds);
                    userIds = await userIdsReader.ReadObjectAsync(jsonReader, cancellationToken);
                }

                return(userIdss);
            }

            return(await Task.FromResult(default(IEnumerable <ITraktUserIds>)));
        }
Ejemplo n.º 2
0
        public override async Task <ITraktUser> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var idsReader    = new UserIdsObjectJsonReader();
                var imagesReader = new UserImagesObjectJsonReader();

                ITraktUser traktUser = new TraktUser();

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

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_USERNAME:
                        traktUser.Username = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_PRIVATE:
                        traktUser.IsPrivate = await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_IDS:
                        traktUser.Ids = await idsReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_NAME:
                        traktUser.Name = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_VIP:
                        traktUser.IsVIP = await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_VIP_EP:
                        traktUser.IsVIP_EP = await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        break;

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

                        if (value.First)
                        {
                            traktUser.JoinedAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_LOCATION:
                        traktUser.Location = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_ABOUT:
                        traktUser.About = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_GENDER:
                        traktUser.Gender = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_AGE:
                        traktUser.Age = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_IMAGES:
                        traktUser.Images = await imagesReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktUser);
            }

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