// <summary>
        /// Helper function to convert service long term retention policy from ps retention policy.
        /// </summary>
        public static ServiceClientModel.LongTermRetentionPolicy GetServiceClientLongTermRetentionPolicy(
            LongTermRetentionPolicy psRetPolicy)
        {
            if (psRetPolicy == null)
            {
                return(null);
            }

            ServiceClientModel.LongTermRetentionPolicy serviceClientRetPolicy = new ServiceClientModel.LongTermRetentionPolicy();

            if (psRetPolicy.IsDailyScheduleEnabled)
            {
                serviceClientRetPolicy.DailySchedule = GetServiceClientLTRDailySchedule(psRetPolicy.DailySchedule);
            }

            if (psRetPolicy.IsWeeklyScheduleEnabled)
            {
                serviceClientRetPolicy.WeeklySchedule = GetServiceClientLTRWeeklySchedule(psRetPolicy.WeeklySchedule);
            }

            if (psRetPolicy.IsMonthlyScheduleEnabled)
            {
                serviceClientRetPolicy.MonthlySchedule = GetServiceClientLTRMonthlySchedule(psRetPolicy.MonthlySchedule);
            }

            if (psRetPolicy.IsYearlyScheduleEnabled)
            {
                serviceClientRetPolicy.YearlySchedule = GetServiceClientLTRYearlySchedule(psRetPolicy.YearlySchedule);
            }

            return(serviceClientRetPolicy);
        }
        // <summary>
        /// Helper function to convert ps long term retention policy from service response.
        /// </summary>
        public static LongTermRetentionPolicy GetPSLongTermRetentionPolicy(
            ServiceClientModel.LongTermRetentionPolicy serviceClientRetPolicy, string timeZone, string backupManagementType = "")
        {
            if (serviceClientRetPolicy == null)
            {
                return(null);
            }

            LongTermRetentionPolicy ltrPolicy = new LongTermRetentionPolicy();

            if (serviceClientRetPolicy.DailySchedule != null)
            {
                ltrPolicy.IsDailyScheduleEnabled             = true;
                ltrPolicy.DailySchedule                      = GetPSLTRDailySchedule(serviceClientRetPolicy.DailySchedule, timeZone);
                ltrPolicy.DailySchedule.BackupManagementType = backupManagementType;
            }

            if (serviceClientRetPolicy.WeeklySchedule != null)
            {
                ltrPolicy.IsWeeklyScheduleEnabled             = true;
                ltrPolicy.WeeklySchedule                      = GetPSLTRWeeklySchedule(serviceClientRetPolicy.WeeklySchedule, timeZone);
                ltrPolicy.WeeklySchedule.BackupManagementType = backupManagementType;
            }

            if (serviceClientRetPolicy.MonthlySchedule != null)
            {
                ltrPolicy.IsMonthlyScheduleEnabled             = true;
                ltrPolicy.MonthlySchedule                      = GetPSLTRMonthlySchedule(serviceClientRetPolicy.MonthlySchedule, timeZone);
                ltrPolicy.MonthlySchedule.BackupManagementType = backupManagementType;
            }

            if (serviceClientRetPolicy.YearlySchedule != null)
            {
                ltrPolicy.IsYearlyScheduleEnabled             = true;
                ltrPolicy.YearlySchedule                      = GetPSLTRYearlySchedule(serviceClientRetPolicy.YearlySchedule, timeZone);
                ltrPolicy.YearlySchedule.BackupManagementType = backupManagementType;
            }

            ltrPolicy.BackupManagementType = backupManagementType;
            return(ltrPolicy);
        }
        // <summary>
        /// Helper function to convert ps long term retention policy from service response.
        /// </summary>
        public static LongTermRetentionPolicy GetPSLongTermRetentionPolicy(
            ServiceClientModel.LongTermRetentionPolicy serviceClientRetPolicy, string timeZone)
        {
            if (serviceClientRetPolicy == null)
            {
                return(null);
            }

            LongTermRetentionPolicy ltrPolicy = new LongTermRetentionPolicy();

            if (serviceClientRetPolicy.DailySchedule != null)
            {
                ltrPolicy.IsDailyScheduleEnabled = true;
                ltrPolicy.DailySchedule          = GetPSLTRDailySchedule(serviceClientRetPolicy.DailySchedule, timeZone);
            }

            if (serviceClientRetPolicy.WeeklySchedule != null)
            {
                ltrPolicy.IsWeeklyScheduleEnabled = true;
                ltrPolicy.WeeklySchedule          = GetPSLTRWeeklySchedule(serviceClientRetPolicy.WeeklySchedule, timeZone);
            }

            if (serviceClientRetPolicy.MonthlySchedule != null)
            {
                ltrPolicy.IsMonthlyScheduleEnabled = true;
                ltrPolicy.MonthlySchedule          = GetPSLTRMonthlySchedule(serviceClientRetPolicy.MonthlySchedule, timeZone);
            }

            if (serviceClientRetPolicy.YearlySchedule != null)
            {
                ltrPolicy.IsYearlyScheduleEnabled = true;
                ltrPolicy.YearlySchedule          = GetPSLTRYearlySchedule(serviceClientRetPolicy.YearlySchedule, timeZone);
            }

            // safe side validate
            ltrPolicy.Validate();

            return(ltrPolicy);
        }
        // <summary>
        /// Helper function to convert service long term retention policy from ps retention policy.
        /// </summary>
        public static ServiceClientModel.LongTermRetentionPolicy GetServiceClientLongTermRetentionPolicy(
            LongTermRetentionPolicy psRetPolicy)
        {
            if (psRetPolicy == null)
            {
                return null;
            }

            ServiceClientModel.LongTermRetentionPolicy serviceClientRetPolicy = new ServiceClientModel.LongTermRetentionPolicy();

            if (psRetPolicy.IsDailyScheduleEnabled)
            {
                serviceClientRetPolicy.DailySchedule = GetServiceClientLTRDailySchedule(psRetPolicy.DailySchedule);
            }

            if (psRetPolicy.IsWeeklyScheduleEnabled)
            {
                serviceClientRetPolicy.WeeklySchedule = GetServiceClientLTRWeeklySchedule(psRetPolicy.WeeklySchedule);
            }

            if (psRetPolicy.IsMonthlyScheduleEnabled)
            {
                serviceClientRetPolicy.MonthlySchedule = GetServiceClientLTRMonthlySchedule(psRetPolicy.MonthlySchedule);
            }

            if (psRetPolicy.IsYearlyScheduleEnabled)
            {
                serviceClientRetPolicy.YearlySchedule = GetServiceClientLTRYearlySchedule(psRetPolicy.YearlySchedule);
            }

            return serviceClientRetPolicy;
        }
Ejemplo n.º 5
0
        private LongTermRetentionPolicy GetRandomLTRRetentionPolicy()
        {
            List<DateTime> retTimes = new List<DateTime> { DateTime.UtcNow.AddDays(2) };

            DailyRetentionSchedule dailyRetention = new DailyRetentionSchedule()
            {
                RetentionDuration = new RetentionDuration()
                                    {
                                        Count = 10,
                                        DurationType = RetentionDurationType.Days
                                    },
                RetentionTimes = retTimes
            };

            WeeklyRetentionSchedule weeklyRetention = new WeeklyRetentionSchedule()
            {
                RetentionDuration = new RetentionDuration()
                                    {
                                        Count = 10,
                                        DurationType = RetentionDurationType.Weeks
                                    },
                RetentionTimes = retTimes,
                DaysOfTheWeek = new List<string> { ConfigurationManager.AppSettings["ScheduleRunDay"] }
            };

            YearlyRetentionSchedule yearlyRetention = new YearlyRetentionSchedule()
            {
                RetentionDuration = new RetentionDuration()
                {
                    Count = 10,
                    DurationType = RetentionDurationType.Weeks
                },
                RetentionTimes = retTimes,
                RetentionScheduleFormatType = RetentionScheduleFormat.Daily,
                RetentionScheduleDaily = new DailyRetentionFormat()
                {
                    DaysOfTheMonth = new List<Day>()
                    {
                        new Day()
                        {
                            Date = 1,
                            IsLast = false
                        },
                        new Day()
                        {
                            Date = 2,
                            IsLast = true
                        },
                    }
                }
            };

            LongTermRetentionPolicy retPolicy = new LongTermRetentionPolicy()
            {
                DailySchedule = dailyRetention,
                WeeklySchedule = weeklyRetention,
                YearlySchedule = yearlyRetention
            };

            return retPolicy;
        }