Esempio n. 1
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, RetentionPolicyDescription obj)
        {
            var kind = obj.RetentionPolicyType;

            if (kind.Equals(RetentionPolicyType.Basic))
            {
                BasicRetentionPolicyDescriptionConverter.Serialize(writer, (BasicRetentionPolicyDescription)obj);
            }
            else
            {
                throw new InvalidOperationException("Unknown RetentionPolicyType.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the object from Json properties.
        /// </summary>
        /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <returns>The object Value.</returns>
        internal static RetentionPolicyDescription GetFromJsonProperties(JsonReader reader)
        {
            RetentionPolicyDescription obj = null;
            var propName = reader.ReadPropertyName();

            if (!propName.Equals("RetentionPolicyType", StringComparison.OrdinalIgnoreCase))
            {
                throw new JsonReaderException($"Incorrect discriminator property name {propName}, Expected discriminator property name is RetentionPolicyType.");
            }

            var propValue = reader.ReadValueAsString();

            if (propValue.Equals("Basic", StringComparison.OrdinalIgnoreCase))
            {
                obj = BasicRetentionPolicyDescriptionConverter.GetFromJsonProperties(reader);
            }
            else
            {
                throw new InvalidOperationException("Unknown RetentionPolicyType.");
            }

            return(obj);
        }
        /// <inheritdoc/>
        protected override void ProcessRecordInternal()
        {
            BackupScheduleDescription backupScheduleDescription = null;

            if (this.FrequencyBased.IsPresent)
            {
                backupScheduleDescription = new FrequencyBasedBackupScheduleDescription(
                    interval: this.Interval);
            }
            else if (this.TimeBased.IsPresent)
            {
                backupScheduleDescription = new TimeBasedBackupScheduleDescription(
                    scheduleFrequencyType: this.ScheduleFrequencyType,
                    runTimes: this.RunTimes,
                    runDays: this.RunDays);
            }

            BackupStorageDescription backupStorageDescription = null;

            if (this.AzureBlobStore.IsPresent)
            {
                backupStorageDescription = new AzureBlobBackupStorageDescription(
                    connectionString: this.ConnectionString,
                    containerName: this.ContainerName,
                    friendlyName: this.FriendlyName);
            }
            else if (this.FileShare.IsPresent)
            {
                backupStorageDescription = new FileShareBackupStorageDescription(
                    path: this.Path,
                    friendlyName: this.FriendlyName,
                    primaryUserName: this.PrimaryUserName,
                    primaryPassword: this.PrimaryPassword,
                    secondaryUserName: this.SecondaryUserName,
                    secondaryPassword: this.SecondaryPassword);
            }
            else if (this.DsmsAzureBlobStore.IsPresent)
            {
                backupStorageDescription = new DsmsAzureBlobBackupStorageDescription(
                    storageCredentialsSourceLocation: this.StorageCredentialsSourceLocation,
                    containerName: this.ContainerName,
                    friendlyName: this.FriendlyName);
            }

            RetentionPolicyDescription retentionPolicyDescription = null;

            if (this.Basic.IsPresent)
            {
                retentionPolicyDescription = new BasicRetentionPolicyDescription(
                    retentionDuration: this.RetentionDuration,
                    minimumNumberOfBackups: this.MinimumNumberOfBackups);
            }

            var backupPolicyDescription = new BackupPolicyDescription(
                name: this.Name,
                autoRestoreOnDataLoss: this.AutoRestoreOnDataLoss,
                maxIncrementalBackups: this.MaxIncrementalBackups,
                schedule: backupScheduleDescription,
                storage: backupStorageDescription,
                retentionPolicy: retentionPolicyDescription);

            this.ServiceFabricClient.BackupRestore.CreateBackupPolicyAsync(
                backupPolicyDescription: backupPolicyDescription,
                serverTimeout: this.ServerTimeout,
                cancellationToken: this.CancellationToken).GetAwaiter().GetResult();

            Console.WriteLine("Success!");
        }