Esempio n. 1
0
        public static void ScheduleTask(DateTime executeTime)
        {
            SchedulingManager schedulingManager = SchedulingManager.GetManager();

            var existingTask = schedulingManager.GetTaskData().FirstOrDefault(x => x.Key == HashtagSearchScheduledTask.TaskKey);

            if (existingTask == null && usgConfig.RunHashtagSearch && !usgConfig.UserKey.IsNullOrWhitespace())
            {
                // Create a new scheduled task
                HashtagSearchScheduledTask newTask = new HashtagSearchScheduledTask()
                {
                    ExecuteTime = executeTime
                };
                schedulingManager.AddTask(newTask);
            }
            else if (usgConfig.RunHashtagSearch && !usgConfig.UserKey.IsNullOrWhitespace())
            {
                // Updates the existing scheduled task
                existingTask.ExecuteTime = executeTime;
            }
            else
            {
                //Delete the task
                schedulingManager.DeleteItem(existingTask);
            }

            SchedulingManager.RescheduleNextRun();
            schedulingManager.SaveChanges();
        }
        private void RescheduleTask()
        {
            SchedulingManager schedulingManager = SchedulingManager.GetManager();

            ReportsImportScheduledTask newTask = new ReportsImportScheduledTask()
            {
                Key              = this.Key,
                ExecuteTime      = DateTime.UtcNow.AddSeconds(30 * 60),
                LastExecutedTime = this.LastExecutedTime
            };

            schedulingManager.AddTask(newTask);
            SchedulingManager.RescheduleNextRun();
            schedulingManager.SaveChanges();
        }