Example #1
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 BackupScheduleDescription GetFromJsonProperties(JsonReader reader)
        {
            BackupScheduleDescription obj = null;
            var propName = reader.ReadPropertyName();

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

            var propValue = reader.ReadValueAsString();

            if (propValue.Equals("FrequencyBased", StringComparison.OrdinalIgnoreCase))
            {
                obj = FrequencyBasedBackupScheduleDescriptionConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("TimeBased", StringComparison.OrdinalIgnoreCase))
            {
                obj = TimeBasedBackupScheduleDescriptionConverter.GetFromJsonProperties(reader);
            }
            else
            {
                throw new InvalidOperationException("Unknown ScheduleKind.");
            }

            return(obj);
        }
Example #2
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, BackupScheduleDescription obj)
        {
            var kind = obj.ScheduleKind;

            if (kind.Equals(BackupScheduleKind.FrequencyBased))
            {
                FrequencyBasedBackupScheduleDescriptionConverter.Serialize(writer, (FrequencyBasedBackupScheduleDescription)obj);
            }
            else if (kind.Equals(BackupScheduleKind.TimeBased))
            {
                TimeBasedBackupScheduleDescriptionConverter.Serialize(writer, (TimeBasedBackupScheduleDescription)obj);
            }
            else
            {
                throw new InvalidOperationException("Unknown ScheduleKind.");
            }
        }
        /// <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!");
        }