Пример #1
0
 bool WeekRule(ScheduledWorkflowLaunchSchedule schedule, ScheduledWorkflowLaunchHistory lastStartedWorkflow, CultureInfo ci, CalendarWeekRule weekRule)
 {
     return(schedule.RecurEveryWeeks <= 1 || lastStartedWorkflow == null ||
            ci.Calendar.GetWeekOfYear(DateTime.Now, weekRule, DayOfWeek.Monday) >=
            ci.Calendar.GetWeekOfYear(lastStartedWorkflow.LaunchedOn, weekRule, DayOfWeek.Monday) +
            schedule.RecurEveryWeeks);
 }
Пример #2
0
 bool WeeklyDayMatch(ScheduledWorkflowLaunchSchedule schedule)
 {
     return((schedule.Monday && DateTime.Now.DayOfWeek == DayOfWeek.Monday) ||
            (schedule.Tuesday && DateTime.Now.DayOfWeek == DayOfWeek.Tuesday) ||
            (schedule.Wednesday && DateTime.Now.DayOfWeek == DayOfWeek.Wednesday) ||
            (schedule.Thursday && DateTime.Now.DayOfWeek == DayOfWeek.Thursday) ||
            (schedule.Friday && DateTime.Now.DayOfWeek == DayOfWeek.Friday) ||
            (schedule.Saturday && DateTime.Now.DayOfWeek == DayOfWeek.Saturday) ||
            (schedule.Sunday && DateTime.Now.DayOfWeek == DayOfWeek.Sunday));
 }
Пример #3
0
 bool NeedToStartMin(ScheduledWorkflow workflow, ScheduledWorkflowLaunchSchedule schedule)
 {
     if (DateTime.Now.TimeOfDay >= schedule.StartTime && schedule.RecurEveryMin > 0)
     {
         var lastStartedWorkflow = workflow.LaunchHistoryItems.OrderByDescending(l => l.LaunchedOn).FirstOrDefault();
         if (lastStartedWorkflow == null)
         {
             return(schedule.StartTime.Add(TimeSpan.FromMinutes(schedule.RecurEveryMin)) <= DateTime.Now.TimeOfDay);
         }
         return(lastStartedWorkflow.LaunchedOn.AddMinutes(schedule.RecurEveryMin) <= DateTime.Now);
     }
     return(false);
 }
Пример #4
0
        bool NeedToStartDaily(ScheduledWorkflow workflow, ScheduledWorkflowLaunchSchedule schedule)
        {
            var historyItem = workflow.LaunchHistoryItems.FirstOrDefault(l => l.LaunchedOn.Date == DateTime.Today);

            if (historyItem == null && DateTime.Now.TimeOfDay >= schedule.StartTime)
            {
                var lastStartedWorkflow = workflow.LaunchHistoryItems.OrderByDescending(l => l.LaunchedOn).FirstOrDefault();
                if (schedule.RecurEveryDays <= 1 || lastStartedWorkflow == null ||
                    DateTime.Now >= lastStartedWorkflow.LaunchedOn.Date.AddDays(schedule.RecurEveryDays).Add(schedule.StartTime))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #5
0
        bool NeedToStartWeekly(ScheduledWorkflow workflow, ScheduledWorkflowLaunchSchedule schedule)
        {
            var lastLaunch = workflow.LaunchHistoryItems.OrderByDescending(l => l.LaunchedOn)
                             .Where(l => l.LaunchedOn.Date == DateTime.Today)
                             .Select(l => l.LaunchedOn.TimeOfDay)
                             .FirstOrDefault();
            var currentTime = DateTime.Now.TimeOfDay;

            var nextLaunch = NextLaunch(workflow, lastLaunch, currentTime);

            if (currentTime >= schedule.StartTime && nextLaunch == schedule.StartTime && lastLaunch <= schedule.StartTime)
            {
                var lastStartedWorkflow = workflow.LaunchHistoryItems.OrderByDescending(l => l.LaunchedOn).FirstOrDefault();
                var ci       = CultureInfo.CurrentCulture;
                var weekRule = CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule;
                if (WeekRule(schedule, lastStartedWorkflow, ci, weekRule))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #6
0
 bool NeedToStartOneTime(ScheduledWorkflow workflow, ScheduledWorkflowLaunchSchedule schedule)
 {
     return(workflow.LaunchHistoryItems.Count == 0 && DateTime.Now.TimeOfDay >= schedule.StartTime);
 }