/// <summary> /// Creates policy given the provider data /// </summary> /// <returns>Created policy object as returned by the service</returns> public ProtectionPolicyResponse CreatePolicy() { string policyName = (string)ProviderData[PolicyParams.PolicyName]; Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType workloadType = (Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.WorkloadType)ProviderData[PolicyParams.WorkloadType]; RetentionPolicyBase retentionPolicy = ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ? (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] : null; SchedulePolicyBase schedulePolicy = ProviderData.ContainsKey(PolicyParams.SchedulePolicy) ? (SchedulePolicyBase)ProviderData[PolicyParams.SchedulePolicy] : null; // do validations ValidateAzureVMWorkloadType(workloadType); ValidateAzureVMSchedulePolicy(schedulePolicy); Logger.Instance.WriteDebug("Validation of Schedule policy is successful"); // validate RetentionPolicy ValidateAzureVMRetentionPolicy(retentionPolicy); Logger.Instance.WriteDebug("Validation of Retention policy is successful"); // update the retention times from backupSchedule to retentionPolicy after converting to UTC CopyScheduleTimeToRetentionTimes((CmdletModel.LongTermRetentionPolicy)retentionPolicy, (CmdletModel.SimpleSchedulePolicy)schedulePolicy); Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful"); // Now validate both RetentionPolicy and SchedulePolicy together PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)retentionPolicy, (CmdletModel.SimpleSchedulePolicy)schedulePolicy); Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful"); // construct Service Client policy request ProtectionPolicyRequest serviceClientRequest = new ProtectionPolicyRequest() { Item = new ProtectionPolicyResource() { Properties = new AzureIaaSVMProtectionPolicy() { RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)retentionPolicy), SchedulePolicy = PolicyHelpers.GetServiceClientSimpleSchedulePolicy( (CmdletModel.SimpleSchedulePolicy)schedulePolicy) } } }; return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy( policyName, serviceClientRequest)); }
private void ValidateAzureVMSchedulePolicy(SchedulePolicyBase policy) { if (policy == null || policy.GetType() != typeof(CmdletModel.SimpleSchedulePolicy)) { throw new ArgumentException(string.Format(Resources.InvalidSchedulePolicyException, typeof(CmdletModel.SimpleSchedulePolicy).ToString())); } // call validation policy.Validate(); }
private static void ValidateDurationCountsForHourlyPolicy(LongTermRetentionPolicy ltrPolicy, SchedulePolicyBase schPolicyBase) { if (schPolicyBase.GetType() == typeof(SimpleSchedulePolicy)) { SimpleSchedulePolicy schPolicy = (SimpleSchedulePolicy)schPolicyBase; if (ltrPolicy.DailySchedule != null && ltrPolicy.IsDailyScheduleEnabled == true && string.Compare(ltrPolicy.BackupManagementType, "AzureStorage") == 0) { if (schPolicy != null && schPolicy.ScheduleRunFrequency == ScheduleRunType.Hourly) { int numberOfPointsPerDay = (int)((schPolicy.ScheduleWindowDuration / schPolicy.ScheduleInterval) + 1); int totalNumberOfScheduledPoints = numberOfPointsPerDay * (ltrPolicy.DailySchedule.DurationCountInDays + 1); //Incorporating GC delays for Hourly schedules if (totalNumberOfScheduledPoints > PolicyConstants.AfsDailyRetentionDaysMax) { throw new ArgumentException(String.Format(Resources.DailyRetentionPointsLimitExceeded, PolicyConstants.AfsDailyRetentionDaysMax)); } } } } }
/// <summary> /// Modifies policy using the provider data /// </summary> /// <returns>Modified policy object as returned by the service</returns> public ProtectionPolicyResponse ModifyPolicy() { RetentionPolicyBase retentionPolicy = ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ? (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] : null; SchedulePolicyBase schedulePolicy = ProviderData.ContainsKey(PolicyParams.SchedulePolicy) ? (SchedulePolicyBase)ProviderData[PolicyParams.SchedulePolicy] : null; PolicyBase policy = ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ? (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] : null; // do validations ValidateAzureVMProtectionPolicy(policy); Logger.Instance.WriteDebug("Validation of Protection Policy is successful"); // RetentionPolicy and SchedulePolicy both should not be empty if (retentionPolicy == null && schedulePolicy == null) { throw new ArgumentException(Resources.BothRetentionAndSchedulePoliciesEmpty); } // validate RetentionPolicy and SchedulePolicy if (schedulePolicy != null) { ValidateAzureVMSchedulePolicy(schedulePolicy); ((AzureVmPolicy)policy).SchedulePolicy = schedulePolicy; Logger.Instance.WriteDebug("Validation of Schedule policy is successful"); } if (retentionPolicy != null) { ValidateAzureVMRetentionPolicy(retentionPolicy); ((AzureVmPolicy)policy).RetentionPolicy = retentionPolicy; Logger.Instance.WriteDebug("Validation of Retention policy is successful"); } // copy the backupSchedule time to retentionPolicy after converting to UTC CopyScheduleTimeToRetentionTimes( (CmdletModel.LongTermRetentionPolicy)((AzureVmPolicy)policy).RetentionPolicy, (CmdletModel.SimpleSchedulePolicy)((AzureVmPolicy)policy).SchedulePolicy); Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful"); // Now validate both RetentionPolicy and SchedulePolicy matches or not PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)((AzureVmPolicy)policy).RetentionPolicy, (CmdletModel.SimpleSchedulePolicy)((AzureVmPolicy)policy).SchedulePolicy); Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful"); // construct Service Client policy request ProtectionPolicyRequest serviceClientRequest = new ProtectionPolicyRequest() { Item = new ProtectionPolicyResource() { Properties = new AzureIaaSVMProtectionPolicy() { RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)((AzureVmPolicy)policy).RetentionPolicy), SchedulePolicy = PolicyHelpers.GetServiceClientSimpleSchedulePolicy( (CmdletModel.SimpleSchedulePolicy)((AzureVmPolicy)policy).SchedulePolicy) } } }; return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy(policy.Name, serviceClientRequest)); }
private RestAzureNS.AzureOperationResponse <ProtectionPolicyResource> CreateorModifyPolicy() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string policyName = ProviderData.ContainsKey(PolicyParams.PolicyName) ? (string)ProviderData[PolicyParams.PolicyName] : null; RetentionPolicyBase retentionPolicy = ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ? (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] : null; SchedulePolicyBase schedulePolicy = ProviderData.ContainsKey(PolicyParams.SchedulePolicy) ? (SchedulePolicyBase)ProviderData[PolicyParams.SchedulePolicy] : null; PolicyBase policy = ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ? (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] : null; bool fixForInconsistentItems = ProviderData.ContainsKey(PolicyParams.FixForInconsistentItems) ? (bool)ProviderData[PolicyParams.FixForInconsistentItems] : false; ProtectionPolicyResource serviceClientRequest = new ProtectionPolicyResource(); if (policy != null) { // do validations ValidateAzureWorkloadProtectionPolicy(policy); Logger.Instance.WriteDebug("Validation of Protection Policy is successful"); // RetentionPolicy and SchedulePolicy both should not be empty if (retentionPolicy == null && schedulePolicy == null) { if (fixForInconsistentItems == false) { throw new ArgumentException(Resources.BothRetentionAndSchedulePoliciesEmpty); } AzureVmWorkloadProtectionPolicy azureVmWorkloadModifyPolicy = new AzureVmWorkloadProtectionPolicy(); azureVmWorkloadModifyPolicy.Settings = new Settings("UTC", ((AzureVmWorkloadPolicy)policy).IsCompression, ((AzureVmWorkloadPolicy)policy).IsCompression); azureVmWorkloadModifyPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString()); azureVmWorkloadModifyPolicy.SubProtectionPolicy = new List <SubProtectionPolicy>(); azureVmWorkloadModifyPolicy.SubProtectionPolicy = PolicyHelpers.GetServiceClientSubProtectionPolicy((AzureVmWorkloadPolicy)policy); azureVmWorkloadModifyPolicy.MakePolicyConsistent = true; serviceClientRequest.Properties = azureVmWorkloadModifyPolicy; } else { // validate RetentionPolicy and SchedulePolicy if (schedulePolicy != null) { AzureWorkloadProviderHelper.ValidateSQLSchedulePolicy(schedulePolicy); AzureWorkloadProviderHelper.GetUpdatedSchedulePolicy(policy, (SQLSchedulePolicy)schedulePolicy); Logger.Instance.WriteDebug("Validation of Schedule policy is successful"); } if (retentionPolicy != null) { AzureWorkloadProviderHelper.ValidateSQLRetentionPolicy(retentionPolicy); AzureWorkloadProviderHelper.GetUpdatedRetentionPolicy(policy, (SQLRetentionPolicy)retentionPolicy); Logger.Instance.WriteDebug("Validation of Retention policy is successful"); } // copy the backupSchedule time to retentionPolicy after converting to UTC AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes( (CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy, (CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy); Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful"); // Now validate both RetentionPolicy and SchedulePolicy matches or not PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)((AzureVmWorkloadPolicy)policy).FullBackupRetentionPolicy, (CmdletModel.SimpleSchedulePolicy)((AzureVmWorkloadPolicy)policy).FullBackupSchedulePolicy); Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful"); // construct Service Client policy request AzureVmWorkloadProtectionPolicy azureVmWorkloadProtectionPolicy = new AzureVmWorkloadProtectionPolicy(); azureVmWorkloadProtectionPolicy.Settings = new Settings("UTC", ((AzureVmWorkloadPolicy)policy).IsCompression, ((AzureVmWorkloadPolicy)policy).IsCompression); azureVmWorkloadProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString()); azureVmWorkloadProtectionPolicy.SubProtectionPolicy = new List <SubProtectionPolicy>(); azureVmWorkloadProtectionPolicy.SubProtectionPolicy = PolicyHelpers.GetServiceClientSubProtectionPolicy((AzureVmWorkloadPolicy)policy); serviceClientRequest.Properties = azureVmWorkloadProtectionPolicy; } } else { CmdletModel.WorkloadType workloadType = (CmdletModel.WorkloadType)ProviderData[PolicyParams.WorkloadType]; // do validations ValidateAzureWorkloadWorkloadType(workloadType); AzureWorkloadProviderHelper.ValidateSQLSchedulePolicy(schedulePolicy); Logger.Instance.WriteDebug("Validation of Schedule policy is successful"); // validate RetentionPolicy AzureWorkloadProviderHelper.ValidateSQLRetentionPolicy(retentionPolicy); Logger.Instance.WriteDebug("Validation of Retention policy is successful"); // update the retention times from backupSchedule to retentionPolicy after converting to UTC AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes(((SQLRetentionPolicy)retentionPolicy).FullBackupRetentionPolicy, ((SQLSchedulePolicy)schedulePolicy).FullBackupSchedulePolicy); Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful"); // Now validate both RetentionPolicy and SchedulePolicy together PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy( (SQLRetentionPolicy)retentionPolicy, (SQLSchedulePolicy)schedulePolicy); Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful"); // construct Service Client policy request AzureVmWorkloadProtectionPolicy azureVmWorkloadProtectionPolicy = new AzureVmWorkloadProtectionPolicy(); azureVmWorkloadProtectionPolicy.Settings = new Settings("UTC", ((SQLSchedulePolicy)schedulePolicy).IsCompression, ((SQLSchedulePolicy)schedulePolicy).IsCompression); azureVmWorkloadProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(workloadType.ToString()); azureVmWorkloadProtectionPolicy.SubProtectionPolicy = new List <SubProtectionPolicy>(); azureVmWorkloadProtectionPolicy.SubProtectionPolicy = PolicyHelpers.GetServiceClientSubProtectionPolicy( (SQLRetentionPolicy)retentionPolicy, (SQLSchedulePolicy)schedulePolicy); serviceClientRequest.Properties = azureVmWorkloadProtectionPolicy; } return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy( policyName = policyName ?? policy.Name, serviceClientRequest, vaultName: vaultName, resourceGroupName: resourceGroupName)); }
private RestAzureNS.AzureOperationResponse <ProtectionPolicyResource> CreateorModifyPolicy() { string vaultName = (string)ProviderData[VaultParams.VaultName]; string resourceGroupName = (string)ProviderData[VaultParams.ResourceGroupName]; string policyName = ProviderData.ContainsKey(PolicyParams.PolicyName) ? (string)ProviderData[PolicyParams.PolicyName] : null; RetentionPolicyBase retentionPolicy = ProviderData.ContainsKey(PolicyParams.RetentionPolicy) ? (RetentionPolicyBase)ProviderData[PolicyParams.RetentionPolicy] : null; SchedulePolicyBase schedulePolicy = ProviderData.ContainsKey(PolicyParams.SchedulePolicy) ? (SchedulePolicyBase)ProviderData[PolicyParams.SchedulePolicy] : null; PolicyBase policy = ProviderData.ContainsKey(PolicyParams.ProtectionPolicy) ? (PolicyBase)ProviderData[PolicyParams.ProtectionPolicy] : null; ProtectionPolicyResource serviceClientRequest = new ProtectionPolicyResource(); if (policy != null) { // do validations ValidateAzureFileProtectionPolicy(policy); Logger.Instance.WriteDebug("Validation of Protection Policy is successful"); // RetentionPolicy and SchedulePolicy both should not be empty if (retentionPolicy == null && schedulePolicy == null) { throw new ArgumentException(Resources.BothRetentionAndSchedulePoliciesEmpty); } // validate RetentionPolicy and SchedulePolicy if (schedulePolicy != null) { AzureWorkloadProviderHelper.ValidateSimpleSchedulePolicy(schedulePolicy); ((AzureFileSharePolicy)policy).SchedulePolicy = schedulePolicy; Logger.Instance.WriteDebug("Validation of Schedule policy is successful"); } if (retentionPolicy != null) { AzureWorkloadProviderHelper.ValidateLongTermRetentionPolicy(retentionPolicy); ((AzureFileSharePolicy)policy).RetentionPolicy = retentionPolicy; Logger.Instance.WriteDebug("Validation of Retention policy is successful"); } // copy the backupSchedule time to retentionPolicy after converting to UTC AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes( (CmdletModel.LongTermRetentionPolicy)((AzureFileSharePolicy)policy).RetentionPolicy, (CmdletModel.SimpleSchedulePolicy)((AzureFileSharePolicy)policy).SchedulePolicy); Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful"); // Now validate both RetentionPolicy and SchedulePolicy matches or not PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)((AzureFileSharePolicy)policy).RetentionPolicy, (CmdletModel.SimpleSchedulePolicy)((AzureFileSharePolicy)policy).SchedulePolicy); Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful"); // construct Service Client policy request AzureFileShareProtectionPolicy azureFileShareProtectionPolicy = new AzureFileShareProtectionPolicy(); azureFileShareProtectionPolicy.RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)((AzureFileSharePolicy)policy).RetentionPolicy); azureFileShareProtectionPolicy.SchedulePolicy = PolicyHelpers.GetServiceClientSimpleSchedulePolicy( (CmdletModel.SimpleSchedulePolicy)((AzureFileSharePolicy)policy).SchedulePolicy); azureFileShareProtectionPolicy.TimeZone = DateTimeKind.Utc.ToString().ToUpper(); azureFileShareProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(policy.WorkloadType.ToString()); serviceClientRequest.Properties = azureFileShareProtectionPolicy; } else { CmdletModel.WorkloadType workloadType = (CmdletModel.WorkloadType)ProviderData[PolicyParams.WorkloadType]; // do validations ValidateAzureFilesWorkloadType(workloadType); AzureWorkloadProviderHelper.ValidateSimpleSchedulePolicy(schedulePolicy); Logger.Instance.WriteDebug("Validation of Schedule policy is successful"); // validate RetentionPolicy AzureWorkloadProviderHelper.ValidateLongTermRetentionPolicy(retentionPolicy); Logger.Instance.WriteDebug("Validation of Retention policy is successful"); // update the retention times from backupSchedule to retentionPolicy after converting to UTC AzureWorkloadProviderHelper.CopyScheduleTimeToRetentionTimes((CmdletModel.LongTermRetentionPolicy)retentionPolicy, (CmdletModel.SimpleSchedulePolicy)schedulePolicy); Logger.Instance.WriteDebug("Copy of RetentionTime from with SchedulePolicy to RetentionPolicy is successful"); // Now validate both RetentionPolicy and SchedulePolicy together PolicyHelpers.ValidateLongTermRetentionPolicyWithSimpleRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)retentionPolicy, (CmdletModel.SimpleSchedulePolicy)schedulePolicy); Logger.Instance.WriteDebug("Validation of Retention policy with Schedule policy is successful"); // construct Service Client policy request AzureFileShareProtectionPolicy azureFileShareProtectionPolicy = new AzureFileShareProtectionPolicy(); azureFileShareProtectionPolicy.RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)retentionPolicy); azureFileShareProtectionPolicy.RetentionPolicy = PolicyHelpers.GetServiceClientLongTermRetentionPolicy( (CmdletModel.LongTermRetentionPolicy)retentionPolicy); azureFileShareProtectionPolicy.SchedulePolicy = PolicyHelpers.GetServiceClientSimpleSchedulePolicy( (CmdletModel.SimpleSchedulePolicy)schedulePolicy); azureFileShareProtectionPolicy.TimeZone = DateTimeKind.Utc.ToString().ToUpper(); azureFileShareProtectionPolicy.WorkLoadType = ConversionUtils.GetServiceClientWorkloadType(workloadType.ToString()); serviceClientRequest.Properties = azureFileShareProtectionPolicy; } return(ServiceClientAdapter.CreateOrUpdateProtectionPolicy( policyName = policyName ?? policy.Name, serviceClientRequest, vaultName: vaultName, resourceGroupName: resourceGroupName)); }
// <summary> /// Helper function to convert service simple schedule policy from ps schedule policy. /// </summary> public static ServiceClientModel.SchedulePolicy GetServiceClientSimpleSchedulePolicy( SchedulePolicyBase psPolicy) { if (psPolicy == null) { return(null); } if (psPolicy.GetType() == typeof(SimpleSchedulePolicy)) { SimpleSchedulePolicy schPolicy = (SimpleSchedulePolicy)psPolicy; ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy = new ServiceClientModel.SimpleSchedulePolicy(); serviceClientPolicy.ScheduleRunFrequency = ServiceClientHelpers.GetServiceClientScheduleRunType(schPolicy.ScheduleRunFrequency); if (schPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly) { serviceClientPolicy.ScheduleRunDays = HelperUtils.EnumListConverter <DayOfWeek, ServiceClientModel.DayOfWeek>( schPolicy.ScheduleRunDays).Cast <ServiceClientModel.DayOfWeek?>().ToList(); } if (schPolicy.ScheduleRunFrequency != ScheduleRunType.Hourly) { serviceClientPolicy.ScheduleRunTimes = schPolicy.ScheduleRunTimes.ConvertAll(dateTime => (DateTime?)dateTime); } else { serviceClientPolicy.HourlySchedule = new ServiceClientModel.HourlySchedule(); serviceClientPolicy.HourlySchedule.Interval = schPolicy.ScheduleInterval; serviceClientPolicy.HourlySchedule.ScheduleWindowDuration = schPolicy.ScheduleWindowDuration; serviceClientPolicy.HourlySchedule.ScheduleWindowStartTime = schPolicy.ScheduleWindowStartTime; } return(serviceClientPolicy); } else if (psPolicy.GetType() == typeof(SimpleSchedulePolicyV2)) { SimpleSchedulePolicyV2 schPolicyV2 = (SimpleSchedulePolicyV2)psPolicy; ServiceClientModel.SimpleSchedulePolicyV2 serviceClientPolicyV2 = new ServiceClientModel.SimpleSchedulePolicyV2(); serviceClientPolicyV2.ScheduleRunFrequency = ServiceClientHelpers.GetServiceClientScheduleRunType(schPolicyV2.ScheduleRunFrequency); if (schPolicyV2.ScheduleRunFrequency == ScheduleRunType.Weekly) { serviceClientPolicyV2.WeeklySchedule = new ServiceClientModel.WeeklySchedule(); serviceClientPolicyV2.WeeklySchedule.ScheduleRunDays = HelperUtils.EnumListConverter <DayOfWeek, ServiceClientModel.DayOfWeek>( schPolicyV2.WeeklySchedule.ScheduleRunDays).Cast <ServiceClientModel.DayOfWeek?>().ToList(); serviceClientPolicyV2.WeeklySchedule.ScheduleRunTimes = schPolicyV2.WeeklySchedule.ScheduleRunTimes.ConvertAll(dateTime => (DateTime?)dateTime); } else if (schPolicyV2.ScheduleRunFrequency == ScheduleRunType.Daily) { serviceClientPolicyV2.DailySchedule = new ServiceClientModel.DailySchedule(); serviceClientPolicyV2.DailySchedule.ScheduleRunTimes = schPolicyV2.DailySchedule.ScheduleRunTimes.ConvertAll(dateTime => (DateTime?)dateTime); } else if (schPolicyV2.ScheduleRunFrequency == ScheduleRunType.Hourly) { serviceClientPolicyV2.HourlySchedule = new ServiceClientModel.HourlySchedule(); serviceClientPolicyV2.HourlySchedule.Interval = schPolicyV2.HourlySchedule.Interval; serviceClientPolicyV2.HourlySchedule.ScheduleWindowDuration = schPolicyV2.HourlySchedule.WindowDuration; serviceClientPolicyV2.HourlySchedule.ScheduleWindowStartTime = schPolicyV2.HourlySchedule.WindowStartTime; } return(serviceClientPolicyV2); } return(null); }