예제 #1
0
        public static void ScheduleTasks()
        {
            nextSchedule = SchedulerController.GetNextSchedule();

            // set timer
            if (nextSchedule != null)
            {
                if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
                {
                    // this will put the timer to sleep
                    scheduleTimer.Change(Timeout.Infinite, Timeout.Infinite);

                    // run immediately
                    RunNextSchedule(null);
                }
                else
                {
                    // set timer
                    TimeSpan ts = nextSchedule.ScheduleInfo.NextRun.Subtract(DateTime.Now);
                    if (ts < TimeSpan.Zero)
                    {
                        ts = TimeSpan.Zero; // cannot be negative !
                    }
                    // invoke after the timespan
                    scheduleTimer.Change((long)ts.TotalMilliseconds, Timeout.Infinite);
                }
            }
        }
예제 #2
0
        public static int StopSchedule(int scheduleId)
        {
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            SchedulerJob schedule = GetScheduleComplete(scheduleId);

            if (schedule == null)
            {
                return(0);
            }

            foreach (BackgroundTask task in TaskController.GetScheduleTasks(scheduleId))
            {
                task.Status = BackgroundTaskStatus.Stopping;

                TaskController.UpdateTask(task);
            }

            return(0);
        }
예제 #3
0
        static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
        {
            // update next run (if required)
            if (changeNextRun)
            {
                SchedulerController.CalculateNextStartTime(schedule.ScheduleInfo);
            }

            // disable run once task
            if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime)
            {
                schedule.ScheduleInfo.Enabled = false;
            }

            Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();

            if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
            {
                // this task should be run, so
                // update its last run
                schedule.ScheduleInfo.LastRun = DateTime.Now;
            }

            // update schedule
            SchedulerController.UpdateSchedule(schedule.ScheduleInfo);

            // skip execution if the current task is still running
            if (scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
            {
                return;
            }

            // run the schedule in the separate thread
            schedule.Run();
        }
예제 #4
0
        public static void ScheduleTasks()
        {
            nextSchedule = SchedulerController.GetNextSchedule();

            // set timer
            if (nextSchedule != null)
            {
                if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
                {
                    // this will put the timer to sleep
                    scheduleTimer.Change(Timeout.Infinite, Timeout.Infinite);

                    // run immediately
                    RunNextSchedule(null);
                }
                else
                {
                    // set timer
                    TimeSpan ts = nextSchedule.ScheduleInfo.NextRun.Subtract(DateTime.Now);
                    if (ts < TimeSpan.Zero)
                        ts = TimeSpan.Zero; // cannot be negative !

                    // invoke after the timespan
                    scheduleTimer.Change((long)ts.TotalMilliseconds, Timeout.Infinite);
                }
            }
        }
예제 #5
0
        public static int StartSchedule(int scheduleId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            SchedulerJob schedule = GetScheduleComplete(scheduleId);

            if (schedule == null)
            {
                return(0);
            }

            if (TaskController.GetScheduleTasks(scheduleId).Any(x => x.Status == BackgroundTaskStatus.Run ||
                                                                x.Status == BackgroundTaskStatus.Starting))
            {
                return(0);
            }

            var parameters = schedule.ScheduleInfo.Parameters.Select(
                prm => new BackgroundTaskParameter(prm.ParameterId, prm.ParameterValue)).ToList();

            var userInfo = PackageController.GetPackageOwner(schedule.ScheduleInfo.PackageId);

            var backgroundTask = new BackgroundTask(
                Guid.NewGuid(),
                Guid.NewGuid().ToString("N"),
                userInfo.OwnerId == 0 ? userInfo.UserId : userInfo.OwnerId,
                userInfo.UserId,
                "SCHEDULER",
                "RUN_SCHEDULE",
                schedule.ScheduleInfo.ScheduleName,
                schedule.ScheduleInfo.ScheduleId,
                schedule.ScheduleInfo.ScheduleId,
                schedule.ScheduleInfo.PackageId,
                schedule.ScheduleInfo.MaxExecutionTime, parameters)
            {
                Status = BackgroundTaskStatus.Starting
            };

            TaskController.AddTask(backgroundTask);

            // update next run (if required)
            CalculateNextStartTime(schedule.ScheduleInfo);

            // disable run once task
            if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime)
            {
                schedule.ScheduleInfo.Enabled = false;
            }

            schedule.ScheduleInfo.LastRun = DateTime.Now;
            UpdateSchedule(schedule.ScheduleInfo);

            return(0);
        }
예제 #6
0
        public static void StopSchedule(SchedulerJob schedule)
        {
            Dictionary<int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();
            if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
                return;

            BackgroundTask activeTask = scheduledTasks[schedule.ScheduleInfo.ScheduleId];
            TaskManager.StopTask(activeTask.TaskId);
        }
예제 #7
0
        public static void StartSchedule(SchedulerJob schedule)
        {
            Dictionary<int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();
            if (scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
                return;

            // run schedule
            RunSchedule(schedule, false);
        }
예제 #8
0
        public static void StartSchedule(SchedulerJob schedule)
        {
            Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();

            if (scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
            {
                return;
            }

            // run schedule
            RunSchedule(schedule, false);
        }
예제 #9
0
        public static void StopSchedule(SchedulerJob schedule)
        {
            Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();

            if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
            {
                return;
            }

            BackgroundTask activeTask = scheduledTasks[schedule.ScheduleInfo.ScheduleId];

            TaskManager.StopTask(activeTask.TaskId);
        }
예제 #10
0
        public static void ScheduleTasks()
        {
            RunManualTasks();

            nextSchedule = SchedulerController.GetNextSchedule();

            if (nextSchedule != null)
            {
                if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
                {
                    RunNextSchedule(null);
                }
            }
        }
예제 #11
0
        public static void ScheduleTasks()
        {
            RunManualTasks();

            nextSchedule = SchedulerController.GetNextSchedule();

            if (nextSchedule != null)
            {
                if (nextSchedule.ScheduleInfo.NextRun <= DateTime.Now)
                {
                    RunNextSchedule(null);
                }
            }
        }
예제 #12
0
        public static int StopSchedule(int scheduleId)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            SchedulerJob schedule = GetScheduleComplete(scheduleId);

            if (schedule == null)
            {
                return(0);
            }

            Scheduler.StopSchedule(schedule);

            return(0);
        }
예제 #13
0
        internal static SchedulerJob CreateCompleteScheduleFromDataSet(DataSet ds)
        {
            if (ds.Tables[0].Rows.Count == 0)
            {
                return(null);
            }

            SchedulerJob schedule = new SchedulerJob();

            // schedule info
            schedule.ScheduleInfo = ObjectUtils.FillObjectFromDataView <ScheduleInfo>(ds.Tables[0].DefaultView);

            // task info
            schedule.Task = ObjectUtils.FillObjectFromDataView <ScheduleTaskInfo>(ds.Tables[1].DefaultView);

            // parameters info
            List <ScheduleTaskParameterInfo> parameters = new List <ScheduleTaskParameterInfo>();

            ObjectUtils.FillCollectionFromDataView <ScheduleTaskParameterInfo>(
                parameters, ds.Tables[2].DefaultView);
            schedule.ScheduleInfo.Parameters = parameters.ToArray();

            return(schedule);
        }
예제 #14
0
        static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
        {
            // update next run (if required)
            if (changeNextRun)
            {
                SchedulerController.CalculateNextStartTime(schedule.ScheduleInfo);
            }

            // disable run once task
            if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime)
                schedule.ScheduleInfo.Enabled = false;

            Dictionary<int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();
            if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
                // this task should be run, so
                // update its last run
                schedule.ScheduleInfo.LastRun = DateTime.Now;

            // update schedule
            SchedulerController.UpdateSchedule(schedule.ScheduleInfo);

            // skip execution if the current task is still running
            if (scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
                return;

            // run the schedule in the separate thread
            schedule.Run();
        }
예제 #15
0
        static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
        {
            try
            {
                // update next run (if required)
                if (changeNextRun)
                {
                    SchedulerController.CalculateNextStartTime(schedule.ScheduleInfo);
                }

                // disable run once task
                if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime)
                    schedule.ScheduleInfo.Enabled = false;

                Dictionary<int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();
                if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
                    // this task should be run, so
                    // update its last run
                    schedule.ScheduleInfo.LastRun = DateTime.Now;

                // update schedule
                int MAX_RETRY_COUNT = 10;
                int counter = 0;
                while (counter < MAX_RETRY_COUNT)
                {
                    try
                    {
                        SchedulerController.UpdateSchedule(schedule.ScheduleInfo);
                        break;
                    }
                    catch (SqlException)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }

                    counter++;
                }
                if (counter == MAX_RETRY_COUNT)
                    return;

                // skip execution if the current task is still running
                scheduledTasks = TaskManager.GetScheduledTasks();
                if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
                {
                    // run the schedule in the separate thread
                    schedule.Run();
                }
            }
            catch (Exception Ex)
            {
                try
                {
                    TaskManager.WriteError(string.Format("RunSchedule Error : {0}", Ex.Message));
                }
                catch (Exception)
                {
                }
            }
        }
예제 #16
0
        internal static SchedulerJob CreateCompleteScheduleFromDataSet(DataSet ds)
        {
            if (ds.Tables[0].Rows.Count == 0)
                return null;

            SchedulerJob schedule = new SchedulerJob();

            // schedule info
            schedule.ScheduleInfo = ObjectUtils.FillObjectFromDataView<ScheduleInfo>(ds.Tables[0].DefaultView);

            // task info
            schedule.Task = ObjectUtils.FillObjectFromDataView<ScheduleTaskInfo>(ds.Tables[1].DefaultView);

            // parameters info
            List<ScheduleTaskParameterInfo> parameters = new List<ScheduleTaskParameterInfo>();
            ObjectUtils.FillCollectionFromDataView<ScheduleTaskParameterInfo>(
                parameters, ds.Tables[2].DefaultView);
            schedule.ScheduleInfo.Parameters = parameters.ToArray();

            return schedule;
        }
예제 #17
0
        static void RunSchedule(SchedulerJob schedule, bool changeNextRun)
        {
            try
            {
                // update next run (if required)
                if (changeNextRun)
                {
                    SchedulerController.CalculateNextStartTime(schedule.ScheduleInfo);
                }

                // disable run once task
                if (schedule.ScheduleInfo.ScheduleType == ScheduleType.OneTime)
                {
                    schedule.ScheduleInfo.Enabled = false;
                }

                Dictionary <int, BackgroundTask> scheduledTasks = TaskManager.GetScheduledTasks();
                if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
                {
                    // this task should be run, so
                    // update its last run
                    schedule.ScheduleInfo.LastRun = DateTime.Now;
                }

                // update schedule
                int MAX_RETRY_COUNT = 10;
                int counter         = 0;
                while (counter < MAX_RETRY_COUNT)
                {
                    try
                    {
                        SchedulerController.UpdateSchedule(schedule.ScheduleInfo);
                        break;
                    }
                    catch (SqlException)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }

                    counter++;
                }
                if (counter == MAX_RETRY_COUNT)
                {
                    return;
                }

                // skip execution if the current task is still running
                scheduledTasks = TaskManager.GetScheduledTasks();
                if (!scheduledTasks.ContainsKey(schedule.ScheduleInfo.ScheduleId))
                {
                    // run the schedule in the separate thread
                    schedule.Run();
                }
            }
            catch (Exception Ex)
            {
                try
                {
                    TaskManager.WriteError(string.Format("RunSchedule Error : {0}", Ex.Message));
                }
                catch (Exception)
                {
                }
            }
        }