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));
                        }
                    }
                }
            }
        }
        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();
        }
        // <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);
        }