Exemple #1
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 <IEnumerable <ITraktAccountSettings> > ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(IEnumerable <ITraktAccountSettings>)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
            {
                var accountSettingsReader             = new AccountSettingsObjectJsonReader();
                var accountSettingss                  = new List <ITraktAccountSettings>();
                ITraktAccountSettings accountSettings = await accountSettingsReader.ReadObjectAsync(jsonReader, cancellationToken);

                while (accountSettings != null)
                {
                    accountSettingss.Add(accountSettings);
                    accountSettings = await accountSettingsReader.ReadObjectAsync(jsonReader, cancellationToken);
                }

                return(accountSettingss);
            }

            return(await Task.FromResult(default(IEnumerable <ITraktAccountSettings>)));
        }