internal static BackupPolicy DeserializeBackupPolicy(JsonElement element)
        {
            if (element.TryGetProperty("type", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Continuous": return(ContinuousModeBackupPolicy.DeserializeContinuousModeBackupPolicy(element));

                case "Periodic": return(PeriodicModeBackupPolicy.DeserializePeriodicModeBackupPolicy(element));
                }
            }
            BackupPolicyType type = default;
            Optional <BackupPolicyMigrationState> migrationState = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    type = new BackupPolicyType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("migrationState"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    migrationState = BackupPolicyMigrationState.DeserializeBackupPolicyMigrationState(property.Value);
                    continue;
                }
            }
            return(new BackupPolicy(type, migrationState.Value));
        }
        internal static ContinuousModeBackupPolicy DeserializeContinuousModeBackupPolicy(JsonElement element)
        {
            BackupPolicyType type = default;
            Optional <BackupPolicyMigrationState> migrationState = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("type"))
                {
                    type = new BackupPolicyType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("migrationState"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    migrationState = BackupPolicyMigrationState.DeserializeBackupPolicyMigrationState(property.Value);
                    continue;
                }
            }
            return(new ContinuousModeBackupPolicy(type, migrationState.Value));
        }
Ejemplo n.º 3
0
 void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("type");
     writer.WriteStringValue(BackupPolicyType.ToString());
     if (Optional.IsDefined(MigrationState))
     {
         writer.WritePropertyName("migrationState");
         writer.WriteObjectValue(MigrationState);
     }
     writer.WriteEndObject();
 }
Ejemplo n.º 4
0
        internal static BackupPolicyMigrationState DeserializeBackupPolicyMigrationState(JsonElement element)
        {
            Optional <BackupPolicyMigrationStatus> status     = default;
            Optional <BackupPolicyType>            targetType = default;
            Optional <DateTimeOffset> startTime = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("status"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    status = new BackupPolicyMigrationStatus(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("targetType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    targetType = new BackupPolicyType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("startTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    startTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
            }
            return(new BackupPolicyMigrationState(Optional.ToNullable(status), Optional.ToNullable(targetType), Optional.ToNullable(startTime)));
        }