protected override void ProcessRecord() { ExecutionBlock(() => { base.ProcessRecord(); WriteDebug("Making client call"); ProtectionPolicyHelpers.ValidateProtectionPolicyName(Name); AzureBackupClient.CheckProtectionPolicyNameAvailability(Vault.ResourceGroupName, Vault.Name, this.Name); var ScheduleType = ProtectionPolicyHelpers.GetScheduleType(DaysOfWeek, this.ParameterSetName, DailyScheduleParamSet, WeeklyScheduleParamSet); var backupSchedule = ProtectionPolicyHelpers.FillCSMBackupSchedule(ScheduleType, BackupTime, DaysOfWeek); ProtectionPolicyHelpers.ValidateRetentionPolicy(RetentionPolicy, backupSchedule); var addCSMProtectionPolicyRequest = new CSMAddProtectionPolicyRequest(); addCSMProtectionPolicyRequest.PolicyName = this.Name; addCSMProtectionPolicyRequest.Properties = new CSMAddProtectionPolicyRequestProperties(); addCSMProtectionPolicyRequest.Properties.PolicyName = this.Name; addCSMProtectionPolicyRequest.Properties.BackupSchedule = backupSchedule; addCSMProtectionPolicyRequest.Properties.WorkloadType = ProtectionPolicyHelpers.ConvertToCSMWorkLoadType(this.Type); addCSMProtectionPolicyRequest.Properties.LtrRetentionPolicy = ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(RetentionPolicy, backupSchedule); AzureBackupClient.AddProtectionPolicy(Vault.ResourceGroupName, Vault.Name, this.Name, addCSMProtectionPolicyRequest); WriteDebug(Resources.ProtectionPolicyCreated); var policyInfo = AzureBackupClient.GetProtectionPolicyByName(Vault.ResourceGroupName, Vault.Name, Name); WriteObject(ProtectionPolicyHelpers.GetCmdletPolicy(Vault, policyInfo)); }); }
private void FillRemainingValuesForSetPolicyRequest(AzureRMBackupProtectionPolicy policy, string newName) { if (newName != null && NewName != policy.Name) { ProtectionPolicyHelpers.ValidateProtectionPolicyName(this.NewName); AzureBackupClient.CheckProtectionPolicyNameAvailability(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, this.NewName); } BackupTime = (BackupTime == DateTime.MinValue) ? policy.BackupTime : BackupTime; WriteDebug(String.Format(Resources.PolicyParameterSet, this.ParameterSetName.ToString())); if (this.ParameterSetName != NoScheduleParamSet) { if (DaysOfWeek != null && DaysOfWeek.Length > 0 && this.ParameterSetName == WeeklyScheduleParamSet) { policy.ScheduleType = ScheduleType.Weekly.ToString(); policy.DaysOfWeek = DaysOfWeek.ToList <string>(); } else if (this.ParameterSetName == DailyScheduleParamSet && (DaysOfWeek == null || DaysOfWeek.Length <= 0)) { policy.ScheduleType = ScheduleType.Daily.ToString(); policy.DaysOfWeek = new List <string>(); } else { policy.ScheduleType = ProtectionPolicyHelpers.GetScheduleType(DaysOfWeek, this.ParameterSetName, DailyScheduleParamSet, WeeklyScheduleParamSet); } } else if (DaysOfWeek != null && DaysOfWeek.Length > 0) { throw new ArgumentException(Resources.PolicyArgumentException); } }