// <summary>
        /// Helper function to convert service simple schedule policy from ps schedule policy.
        /// </summary>
        public static ServiceClientModel.SimpleSchedulePolicy GetServiceClientSimpleSchedulePolicy(
            SimpleSchedulePolicy psPolicy)
        {
            if (psPolicy == null)
            {
                return(null);
            }

            ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy = new ServiceClientModel.SimpleSchedulePolicy();
            serviceClientPolicy.ScheduleRunFrequency =
                ServiceClientHelpers.GetServiceClientScheduleRunType(
                    psPolicy.ScheduleRunFrequency);

            if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
            {
                serviceClientPolicy.ScheduleRunDays =
                    HelperUtils.EnumListConverter <DayOfWeek, ServiceClientModel.DayOfWeek>(
                        psPolicy.ScheduleRunDays).Cast <ServiceClientModel.DayOfWeek?>().ToList();
            }

            if (psPolicy.ScheduleRunFrequency != ScheduleRunType.Hourly)
            {
                serviceClientPolicy.ScheduleRunTimes = psPolicy.ScheduleRunTimes.ConvertAll(dateTime => (DateTime?)dateTime);
            }
            else
            {
                serviceClientPolicy.HourlySchedule          = new ServiceClientModel.HourlySchedule();
                serviceClientPolicy.HourlySchedule.Interval = psPolicy.ScheduleInterval;
                serviceClientPolicy.HourlySchedule.ScheduleWindowDuration  = psPolicy.ScheduleWindowDuration;
                serviceClientPolicy.HourlySchedule.ScheduleWindowStartTime = psPolicy.ScheduleWindowStartTime;
            }
            return(serviceClientPolicy);
        }
        private static ServiceClientModel.YearlyRetentionSchedule GetServiceClientLTRYearlySchedule(YearlyRetentionSchedule psYearly)
        {
            if (psYearly == null)
            {
                return(null);
            }

            ServiceClientModel.YearlyRetentionSchedule serviceClientYearly = new ServiceClientModel.YearlyRetentionSchedule();

            serviceClientYearly.RetentionDuration = new ServiceClientModel.RetentionDuration()
            {
                Count        = psYearly.DurationCountInYears,
                DurationType = ServiceClientModel.RetentionDurationType.Years
            };
            serviceClientYearly.RetentionTimes = GetNullableDateTimeListFromDateTimeList(
                psYearly.RetentionTimes);

            serviceClientYearly.RetentionScheduleFormatType =
                ServiceClientHelpers.GetServiceClientRetentionScheduleFormat(
                    psYearly.RetentionScheduleFormatType);

            if (psYearly.RetentionScheduleFormatType == RetentionScheduleFormat.Daily)
            {
                serviceClientYearly.RetentionScheduleDaily = GetServiceClientLTRDailyRetentionFormat(psYearly.RetentionScheduleDaily);
            }
            else if (psYearly.RetentionScheduleFormatType == RetentionScheduleFormat.Weekly)
            {
                serviceClientYearly.RetentionScheduleWeekly = GetServiceClientLTRWeeklyRetentionFormat(psYearly.RetentionScheduleWeekly);
            }
            serviceClientYearly.MonthsOfYear =
                HelperUtils.EnumListConverter <Month, ServiceClientModel.MonthOfYear>(
                    psYearly.MonthsOfYear).Cast <ServiceClientModel.MonthOfYear?>().ToList();

            return(serviceClientYearly);
        }
        private static WeeklyRetentionFormat GetPSLTRWeeklyRetentionFormat(
            ServiceClientModel.WeeklyRetentionFormat serviceClientFormat)
        {
            if (serviceClientFormat == null)
            {
                return(null);
            }

            WeeklyRetentionFormat psFormat = new WeeklyRetentionFormat();

            if (serviceClientFormat.DaysOfTheWeek != null)
            {
                psFormat.DaysOfTheWeek =
                    HelperUtils.EnumListConverter <ServiceClientModel.DayOfWeek?, DayOfWeek>(
                        serviceClientFormat.DaysOfTheWeek);
            }
            if (serviceClientFormat.WeeksOfTheMonth != null)
            {
                psFormat.WeeksOfTheMonth =
                    HelperUtils.EnumListConverter <ServiceClientModel.WeekOfMonth?, WeekOfMonth>(
                        serviceClientFormat.WeeksOfTheMonth);
            }

            return(psFormat);
        }
        // <summary>
        /// Helper function to convert ps simple schedule policy from service response.
        /// </summary>
        public static SimpleSchedulePolicy GetPSSimpleSchedulePolicy(
            ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy, string timeZone)
        {
            if (serviceClientPolicy == null)
            {
                return(null);
            }

            SimpleSchedulePolicy psPolicy = new SimpleSchedulePolicy();

            psPolicy.ScheduleRunDays =
                HelperUtils.EnumListConverter <ServiceClientModel.DayOfWeek?, DayOfWeek>(
                    serviceClientPolicy.ScheduleRunDays);
            psPolicy.ScheduleRunFrequency =
                (ScheduleRunType)Enum.Parse(
                    typeof(ScheduleRunType), serviceClientPolicy.ScheduleRunFrequency.ToString());
            psPolicy.ScheduleRunTimes = ParseDateTimesToUTC(serviceClientPolicy.ScheduleRunTimes, timeZone);

            if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
            {
                int offset = psPolicy.ScheduleRunTimes[0].DayOfWeek.GetHashCode() -
                             serviceClientPolicy.ScheduleRunTimes[0].Value.DayOfWeek.GetHashCode();

                for (int index = 0; index < psPolicy.ScheduleRunDays.Count(); index++)
                {
                    if (offset == -1)
                    {
                        int value = psPolicy.ScheduleRunDays[index].GetHashCode() - 1;
                        if (value == -1)
                        {
                            value = 6;
                        }
                        psPolicy.ScheduleRunDays[index] = (DayOfWeek)value;
                    }
                    else if (offset == 1)
                    {
                        int value = psPolicy.ScheduleRunDays[index].GetHashCode() + 1;
                        if (value == 7)
                        {
                            value = 0;
                        }
                        psPolicy.ScheduleRunDays[index] = (DayOfWeek)value;
                    }
                }
            }
            // safe side validation
            psPolicy.Validate();

            return(psPolicy);
        }
Example #5
0
        private static WeeklyRetentionSchedule GetPSLTRWeeklySchedule(ServiceClientModel.WeeklyRetentionSchedule serviceClientWeekly)
        {
            if (serviceClientWeekly == null)
            {
                return(null);
            }

            WeeklyRetentionSchedule psWeekly = new WeeklyRetentionSchedule();

            psWeekly.DurationCountInWeeks = GetRetentionDurationInWeeks(serviceClientWeekly.RetentionDuration);
            psWeekly.RetentionTimes       = ParseDateTimesToUTC(serviceClientWeekly.RetentionTimes);
            psWeekly.DaysOfTheWeek        =
                HelperUtils.EnumListConverter <ServiceClientModel.DayOfWeek?, DayOfWeek>(
                    serviceClientWeekly.DaysOfTheWeek);

            return(psWeekly);
        }
Example #6
0
        private static YearlyRetentionSchedule GetPSLTRYearlySchedule(ServiceClientModel.YearlyRetentionSchedule serviceClientYearly)
        {
            if (serviceClientYearly == null)
            {
                return(null);
            }

            YearlyRetentionSchedule psYearly = new YearlyRetentionSchedule();

            psYearly.DurationCountInYears        = GetRetentionDurationInYears(serviceClientYearly.RetentionDuration);
            psYearly.RetentionTimes              = ParseDateTimesToUTC(serviceClientYearly.RetentionTimes);
            psYearly.RetentionScheduleFormatType =
                serviceClientYearly.RetentionScheduleFormatType.ToEnum <RetentionScheduleFormat>();
            psYearly.RetentionScheduleDaily  = GetPSLTRDailyRetentionFormat(serviceClientYearly.RetentionScheduleDaily);
            psYearly.RetentionScheduleWeekly = GetPSLTRWeeklyRetentionFormat(serviceClientYearly.RetentionScheduleWeekly);
            psYearly.MonthsOfYear            =
                HelperUtils.EnumListConverter <ServiceClientModel.MonthOfYear?, Month>(
                    serviceClientYearly.MonthsOfYear);

            return(psYearly);
        }
        private static ServiceClientModel.WeeklyRetentionSchedule GetServiceClientLTRWeeklySchedule(WeeklyRetentionSchedule psWeekly)
        {
            if (psWeekly == null)
            {
                return(null);
            }

            ServiceClientModel.WeeklyRetentionSchedule serviceClientWeekly = new ServiceClientModel.WeeklyRetentionSchedule();

            serviceClientWeekly.RetentionDuration = new ServiceClientModel.RetentionDuration()
            {
                Count        = psWeekly.DurationCountInWeeks,
                DurationType = ServiceClientModel.RetentionDurationType.Weeks
            };
            serviceClientWeekly.RetentionTimes =
                GetNullableDateTimeListFromDateTimeList(psWeekly.RetentionTimes);
            serviceClientWeekly.DaysOfTheWeek =
                HelperUtils.EnumListConverter <DayOfWeek, ServiceClientModel.DayOfWeek>(
                    psWeekly.DaysOfTheWeek).Cast <ServiceClientModel.DayOfWeek?>().ToList();

            return(serviceClientWeekly);
        }
        // <summary>
        /// Helper function to convert service simple schedule policy from ps schedule policy.
        /// </summary>
        public static ServiceClientModel.SimpleSchedulePolicy GetServiceClientSimpleSchedulePolicy(
            SimpleSchedulePolicy psPolicy)
        {
            if (psPolicy == null)
            {
                return(null);
            }

            ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy = new ServiceClientModel.SimpleSchedulePolicy();
            serviceClientPolicy.ScheduleRunFrequency =
                psPolicy.ScheduleRunFrequency.ToEnum <ServiceClientModel.ScheduleRunType>();

            if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
            {
                serviceClientPolicy.ScheduleRunDays =
                    HelperUtils.EnumListConverter <DayOfWeek, ServiceClientModel.DayOfWeek>(
                        psPolicy.ScheduleRunDays).Cast <ServiceClientModel.DayOfWeek?>().ToList();
            }
            serviceClientPolicy.ScheduleRunTimes =
                psPolicy.ScheduleRunTimes.ConvertAll(dateTime => (DateTime?)dateTime);
            return(serviceClientPolicy);
        }
        // <summary>
        /// Helper function to convert ps simple schedule policy from service response.
        /// </summary>
        public static SimpleSchedulePolicy GetPSSimpleSchedulePolicy(
            ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy)
        {
            if (serviceClientPolicy == null)
            {
                return(null);
            }

            SimpleSchedulePolicy psPolicy = new SimpleSchedulePolicy();

            psPolicy.ScheduleRunDays =
                HelperUtils.EnumListConverter <ServiceClientModel.DayOfWeek?, DayOfWeek>(
                    serviceClientPolicy.ScheduleRunDays);
            psPolicy.ScheduleRunFrequency =
                (ScheduleRunType)Enum.Parse(
                    typeof(ScheduleRunType), serviceClientPolicy.ScheduleRunFrequency.ToString());
            psPolicy.ScheduleRunTimes = ParseDateTimesToUTC(serviceClientPolicy.ScheduleRunTimes);

            // safe side validation
            psPolicy.Validate();

            return(psPolicy);
        }
        private static ServiceClientModel.WeeklyRetentionFormat GetServiceClientLTRWeeklyRetentionFormat(
            WeeklyRetentionFormat psFormat)
        {
            if (psFormat == null)
            {
                return(null);
            }

            ServiceClientModel.WeeklyRetentionFormat serviceClientFormat = new ServiceClientModel.WeeklyRetentionFormat();
            if (psFormat.DaysOfTheWeek != null)
            {
                serviceClientFormat.DaysOfTheWeek =
                    HelperUtils.EnumListConverter <DayOfWeek, ServiceClientModel.DayOfWeek>(
                        psFormat.DaysOfTheWeek).Cast <ServiceClientModel.DayOfWeek?>().ToList();
            }
            if (psFormat.WeeksOfTheMonth != null)
            {
                serviceClientFormat.WeeksOfTheMonth =
                    HelperUtils.EnumListConverter <WeekOfMonth, ServiceClientModel.WeekOfMonth>(
                        psFormat.WeeksOfTheMonth).Cast <ServiceClientModel.WeekOfMonth?>().ToList();
            }

            return(serviceClientFormat);
        }
        // <summary>
        /// Helper function to convert ps simple schedule policy from service response.
        /// </summary>
        public static SimpleSchedulePolicyV2 GetPSSimpleSchedulePolicyV2(
            ServiceClientModel.SimpleSchedulePolicyV2 serviceClientPolicy, string timeZone)
        {
            if (serviceClientPolicy == null)
            {
                return(null);
            }

            SimpleSchedulePolicyV2 psPolicy = new SimpleSchedulePolicyV2();

            psPolicy.ScheduleRunFrequency = (ScheduleRunType)Enum.Parse(typeof(ScheduleRunType), serviceClientPolicy.ScheduleRunFrequency.ToString());

            if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
            {
                psPolicy.WeeklySchedule = new WeeklySchedule();

                int offset = 0;
                if (serviceClientPolicy.WeeklySchedule != null)
                {
                    psPolicy.WeeklySchedule.ScheduleRunDays  = HelperUtils.EnumListConverter <ServiceClientModel.DayOfWeek?, DayOfWeek>(serviceClientPolicy.WeeklySchedule.ScheduleRunDays);
                    psPolicy.WeeklySchedule.ScheduleRunTimes = ParseDateTimesToUTC(serviceClientPolicy.WeeklySchedule.ScheduleRunTimes, timeZone);

                    offset = psPolicy.WeeklySchedule.ScheduleRunTimes[0].DayOfWeek.GetHashCode() - serviceClientPolicy.WeeklySchedule.ScheduleRunTimes[0].Value.DayOfWeek.GetHashCode();
                }

                for (int index = 0; index < psPolicy.WeeklySchedule.ScheduleRunDays.Count(); index++)
                {
                    if (offset == -1)
                    {
                        int value = psPolicy.WeeklySchedule.ScheduleRunDays[index].GetHashCode() - 1;
                        if (value == -1)
                        {
                            value = 6;
                        }

                        psPolicy.WeeklySchedule.ScheduleRunDays[index] = (DayOfWeek)value;
                    }
                    else if (offset == 1)
                    {
                        int value = psPolicy.WeeklySchedule.ScheduleRunDays[index].GetHashCode() + 1;
                        if (value == 7)
                        {
                            value = 0;
                        }
                        psPolicy.WeeklySchedule.ScheduleRunDays[index] = (DayOfWeek)value;
                    }
                }
            }
            else if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Hourly)
            {
                psPolicy.HourlySchedule = new HourlySchedule();

                // multiple backups per day
                psPolicy.HourlySchedule.Interval        = serviceClientPolicy.HourlySchedule.Interval;
                psPolicy.HourlySchedule.WindowStartTime = serviceClientPolicy.HourlySchedule.ScheduleWindowStartTime;
                psPolicy.HourlySchedule.WindowDuration  = serviceClientPolicy.HourlySchedule.ScheduleWindowDuration;
            }
            else
            {
                psPolicy.DailySchedule = new DailySchedule();
                psPolicy.DailySchedule.ScheduleRunTimes = (serviceClientPolicy.DailySchedule != null) ? ParseDateTimesToUTC(serviceClientPolicy.DailySchedule.ScheduleRunTimes, timeZone) : null;
            }

            psPolicy.ScheduleRunTimeZone = timeZone;

            // safe side validation
            psPolicy.Validate();

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