public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();
                WriteDebug(Resources.MakingClientCall);

                var response = AzureBackupClient.GetProtectionPolicyByName(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Name);
                var vault = new CmdletModel.AzureRMBackupVault(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, ProtectionPolicy.Location);

                var policyInfo = ProtectionPolicyHelpers.GetCmdletPolicy(vault, response);

                if (policyInfo == null)
                {
                    throw new ArgumentException(String.Format(Resources.PolicyNotFound, ProtectionPolicy.Name));
                }

                FillRemainingValuesForSetPolicyRequest(policyInfo, this.NewName);

                var backupSchedule = ProtectionPolicyHelpers.FillCSMBackupSchedule(policyInfo.ScheduleType, BackupTime,
                    policyInfo.DaysOfWeek.ToArray<string>());

                NewName = (string.IsNullOrEmpty(NewName) ? policyInfo.Name : NewName);
                var updateProtectionPolicyRequest = new CSMUpdateProtectionPolicyRequest();
                updateProtectionPolicyRequest.Properties = new CSMUpdateProtectionPolicyRequestProperties();
                updateProtectionPolicyRequest.Properties.PolicyName = this.NewName;
                updateProtectionPolicyRequest.Properties.BackupSchedule = backupSchedule;

                if (RetentionPolicy != null && RetentionPolicy.Length > 0)
                {
                    updateProtectionPolicyRequest.Properties.LtrRetentionPolicy =
                        ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(RetentionPolicy, backupSchedule);
                    ProtectionPolicyHelpers.ValidateRetentionPolicy(RetentionPolicy, backupSchedule);
                }
                else
                {
                    updateProtectionPolicyRequest.Properties.LtrRetentionPolicy =
                        ProtectionPolicyHelpers.ConvertToCSMRetentionPolicyObject(policyInfo.RetentionPolicy, backupSchedule);
                    ProtectionPolicyHelpers.ValidateRetentionPolicy(policyInfo.RetentionPolicy, backupSchedule);
                }

                var operationId = AzureBackupClient.UpdateProtectionPolicy(ProtectionPolicy.ResourceGroupName, ProtectionPolicy.ResourceName, policyInfo.Name, updateProtectionPolicyRequest);

                if (operationId != Guid.Empty)
                {
                    string resourceGroupName = ProtectionPolicy.ResourceGroupName;
                    string resourceName = ProtectionPolicy.ResourceName;
                    var operationStatus = GetOperationStatus(resourceGroupName, resourceName, operationId);
                    WriteDebug(Resources.PolicyUpdatedReconfigureProtectionDone);

                    WriteObject(GetCreatedJobs(resourceGroupName, resourceName, vault, operationStatus.JobList));
                }

                else
                {
                    WriteDebug(Resources.PolicyUpdated);
                }

            });
        }
        public void UpdateProtectionPolicyTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetServiceClient<BackupServicesManagementClient>();
                var backupSchedule = GetBackupSchedule();

                var updateProtectionPolicyRequest = new CSMUpdateProtectionPolicyRequest();
                updateProtectionPolicyRequest.Properties = new CSMUpdateProtectionPolicyRequestProperties();
                updateProtectionPolicyRequest.Properties.PolicyName = ConfigurationManager.AppSettings["ModifiedPolicyName"];
                string policyName = ConfigurationManager.AppSettings["PolicyName"];
                updateProtectionPolicyRequest.Properties.BackupSchedule = backupSchedule;
                updateProtectionPolicyRequest.Properties.LtrRetentionPolicy = GetRetentionPolicy(backupSchedule.ScheduleRunTimes);
                var response = client.CSMProtectionPolicy.Update(BackupServicesTestsBase.ResourceGroupName, BackupServicesTestsBase.ResourceName, policyName, updateProtectionPolicyRequest, GetCustomRequestHeaders());
                var isSuccess = (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted) ? true : false;
                Assert.Equal(true, isSuccess);
            }
        }
 /// <summary>
 /// Update specified protection policy
 /// </summary>
 /// <param name="policyName"></param>
 /// <param name="request"></param>
 public Guid UpdateProtectionPolicy(string resourceGroupName, string resourceName, string policyName, CSMUpdateProtectionPolicyRequest request)
 {
     var response = AzureBackupClient.CSMProtectionPolicy.UpdateAsync(resourceGroupName, resourceName, policyName, request, GetCustomRequestHeaders(), CmdletCancellationToken).Result;
     return response.OperationId;
 }
 /// <summary>
 /// Update Protection Policy.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.ICSMProtectionPolicyOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='policyName'>
 /// Required. The protection policy Name to be updated.
 /// </param>
 /// <param name='cSMUpdateProtectionPolicyRequest'>
 /// Required. The protection policy creation request.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The definition of a Operation Response.
 /// </returns>
 public static Task<OperationResponse> UpdateAsync(this ICSMProtectionPolicyOperations operations, string resourceGroupName, string resourceName, string policyName, CSMUpdateProtectionPolicyRequest cSMUpdateProtectionPolicyRequest, CustomRequestHeaders customRequestHeaders)
 {
     return operations.UpdateAsync(resourceGroupName, resourceName, policyName, cSMUpdateProtectionPolicyRequest, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// Update Protection Policy.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.BackupServices.ICSMProtectionPolicyOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required.
 /// </param>
 /// <param name='resourceName'>
 /// Required.
 /// </param>
 /// <param name='policyName'>
 /// Required. The protection policy Name to be updated.
 /// </param>
 /// <param name='cSMUpdateProtectionPolicyRequest'>
 /// Required. The protection policy creation request.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The definition of a Operation Response.
 /// </returns>
 public static OperationResponse Update(this ICSMProtectionPolicyOperations operations, string resourceGroupName, string resourceName, string policyName, CSMUpdateProtectionPolicyRequest cSMUpdateProtectionPolicyRequest, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((ICSMProtectionPolicyOperations)s).UpdateAsync(resourceGroupName, resourceName, policyName, cSMUpdateProtectionPolicyRequest, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }