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

            ServiceClientModel.SimpleSchedulePolicy serviceClientPolicy = new ServiceClientModel.SimpleSchedulePolicy();
            serviceClientPolicy.ScheduleRunFrequency = psPolicy.ScheduleRunFrequency.ToString();
            if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
            {
                serviceClientPolicy.ScheduleRunDays = HelperUtils.GetStringListFromEnumList <DayOfWeek>(psPolicy.ScheduleRunDays);
            }
            serviceClientPolicy.ScheduleRunTimes = psPolicy.ScheduleRunTimes;

            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.GetEnumListFromStringList <DayOfWeek>(serviceClientPolicy.ScheduleRunDays);
            psPolicy.ScheduleRunFrequency = (ScheduleRunType)Enum.Parse(typeof(ScheduleRunType),
                                                                        serviceClientPolicy.ScheduleRunFrequency);
            psPolicy.ScheduleRunTimes = ParseDateTimesToUTC(serviceClientPolicy.ScheduleRunTimes);

            // safe side validation
            psPolicy.Validate();

            return(psPolicy);
        }
        // <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);
        }
Example #6
0
        // <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);

            // safe side validation
            psPolicy.Validate();

            return(psPolicy);
        }
        // <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.ToString();
            if (psPolicy.ScheduleRunFrequency == ScheduleRunType.Weekly)
            {
                serviceClientPolicy.ScheduleRunDays = HelperUtils.GetStringListFromEnumList<DayOfWeek>(psPolicy.ScheduleRunDays);
            }
            serviceClientPolicy.ScheduleRunTimes = psPolicy.ScheduleRunTimes;

            return serviceClientPolicy;
        }
        // <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);
        }
        private SimpleSchedulePolicy GetRandomSimpleSchedulePolicy()
        {
            SimpleSchedulePolicy schPolicy = new SimpleSchedulePolicy()
            {
                ScheduleRunTimes = new List<DateTime> { DateTime.UtcNow.AddDays(2) },
                ScheduleRunFrequency = ConfigurationManager.AppSettings["ScheduleRunType"],
                ScheduleRunDays = new List<string> { ConfigurationManager.AppSettings["ScheduleRunDay"] }
            };

            return schPolicy;
        }