Beispiel #1
0
 private static DailyTimeIntervalScheduleBuilder OnDaysOfTheWeekIfAny(this DailyTimeIntervalScheduleBuilder builder,
                                                                      IEnumerable <DayOfWeek> onDaysOfWeek)
 {
     if (onDaysOfWeek != null && onDaysOfWeek.Any())
     {
         builder.OnDaysOfTheWeek(onDaysOfWeek.ToArray());
     }
     return(builder);
 }
        protected override TriggerPropertyBundle GetTriggerPropertyBundle(SimplePropertiesTriggerProperties props)
        {
            int    repeatCount     = (int)props.Long1;
            int    interval        = props.Int1;
            string intervalUnitStr = props.String1;
            string daysOfWeekStr   = props.String2;
            string timeOfDayStr    = props.String3;

            IntervalUnit intervalUnit = (IntervalUnit)Enum.Parse(typeof(IntervalUnit), intervalUnitStr, true);
            DailyTimeIntervalScheduleBuilder scheduleBuilder = DailyTimeIntervalScheduleBuilder.Create()
                                                               .WithInterval(interval, intervalUnit)
                                                               .WithRepeatCount(repeatCount);

            if (daysOfWeekStr != null)
            {
                ISet <DayOfWeek> daysOfWeek = new HashSet <DayOfWeek>();
                string[]         nums       = daysOfWeekStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (nums.Length > 0)
                {
                    foreach (String num in nums)
                    {
                        daysOfWeek.Add((DayOfWeek)Int32.Parse(num));
                    }
                    scheduleBuilder.OnDaysOfTheWeek(daysOfWeek);
                }
            }
            else
            {
                scheduleBuilder.OnDaysOfTheWeek(DailyTimeIntervalScheduleBuilder.AllDaysOfTheWeek);
            }

            if (timeOfDayStr != null)
            {
                string[]  nums = timeOfDayStr.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                TimeOfDay startTimeOfDay;
                if (nums.Length >= 3)
                {
                    int hour = Int32.Parse(nums[0]);
                    int min  = Int32.Parse(nums[1]);
                    int sec  = Int32.Parse(nums[2]);
                    startTimeOfDay = new TimeOfDay(hour, min, sec);
                }
                else
                {
                    startTimeOfDay = TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0);
                }
                scheduleBuilder.StartingDailyAt(startTimeOfDay);

                TimeOfDay endTimeOfDay;
                if (nums.Length >= 6)
                {
                    int hour = Int32.Parse(nums[3]);
                    int min  = Int32.Parse(nums[4]);
                    int sec  = Int32.Parse(nums[5]);
                    endTimeOfDay = new TimeOfDay(hour, min, sec);
                }
                else
                {
                    endTimeOfDay = TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59);
                }
                scheduleBuilder.EndingDailyAt(endTimeOfDay);
            }
            else
            {
                scheduleBuilder.StartingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0));
                scheduleBuilder.EndingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(23, 59, 59));
            }


            int timesTriggered = props.Int2;

            string[] statePropertyNames  = { "timesTriggered" };
            object[] statePropertyValues = { timesTriggered };

            return(new TriggerPropertyBundle(scheduleBuilder, statePropertyNames, statePropertyValues));
        }
 public static DailyTimeIntervalScheduleBuilder WeekendNights(this DailyTimeIntervalScheduleBuilder x)
 {
     return(x.OnDaysOfTheWeek(DayOfWeek.Friday, DayOfWeek.Saturday));
 }
 public static DailyTimeIntervalScheduleBuilder SchoolNights(this DailyTimeIntervalScheduleBuilder x)
 {
     return(x.OnDaysOfTheWeek(DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday));
 }