Exemplo n.º 1
0
        private void DeleteTrigger(TriggerNode selectedNode, Action updateAction)
        {
            var bRet = mScheduler.UnscheduleJob(selectedNode.Trigger.Key);

            Debug.Assert(bRet);
            updateAction();
        }
Exemplo n.º 2
0
 private void LoadCalendarNode(TriggerNode node)
 {
     if (node.Trigger.CalendarName != null)
     {
         node.Nodes.Add(new CalendarNode(node.Trigger.CalendarName));
     }
     else
     {
         node.Nodes.Add("No calendar found");
     }
 }
Exemplo n.º 3
0
        private void LoadTriggerNodes(JobNode jobNode)
        {
            var triggers = mScheduler.GetTriggersOfJob(new JobKey(jobNode.Detail.Key.Name, jobNode.Parent.Text));

            foreach (var trigger in triggers)
            {
                var node = new TriggerNode(trigger);
                jobNode.Nodes.Add(node);
                LoadCalendarNode(node);
            }
        }
Exemplo n.º 4
0
        private void AddCalendar(TriggerNode triggerNode, Action updateAction)
        {
            var allCals = mScheduler.GetCalendarNames();
            var frm     = new CalendarSelector(allCals);

            if (frm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // check if calendar will allow trigger to fire
            var absTrigg = triggerNode.Trigger as AbstractTrigger;

            if (absTrigg != null)
            {
                var selCal   = mScheduler.GetCalendar(frm.SelectedCalendar);
                var nextFire = absTrigg.ComputeFirstFireTimeUtc(selCal);
                if (nextFire == null)
                {
                    var msg = string.Format("Calendar '{0}' will not let trigger '{1}' fire.", frm.SelectedCalendar, absTrigg.Description);
                    MessageBox.Show(msg, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // create new trigger with calendar
            var trigger    = triggerNode.Trigger;
            var newTrigger = trigger.GetTriggerBuilder().
                             ModifiedByCalendar(frm.SelectedCalendar).
                             Build();

            // unschedule existing job
            var bRet = mScheduler.UnscheduleJob(trigger.Key);

            Debug.Assert(bRet);

            // reschedule it with new trigger
            // NOTE:  for some reason we have to use this API or it hangs - go figure
            var jobNode = (JobNode)triggerNode.Parent;

            mScheduler.ScheduleJob(jobNode.Detail, new HashSet <ITrigger> {
                newTrigger
            }, true);

            updateAction();
        }
Exemplo n.º 5
0
        private void DeleteCalendar(TriggerNode selectedNode, Action updateAction)
        {
            // make a copy of the original
            var copyTrigger = (AbstractTrigger)selectedNode.Trigger.DeepClone();

            // delete the original
            var bRet = mScheduler.UnscheduleJob(selectedNode.Trigger.Key);

            Debug.Assert(bRet);

            // remove calendar
            copyTrigger.CalendarName = null;

            // add the copy, less the calendar
            mScheduler.ScheduleJob(copyTrigger);
            updateAction();
        }
Exemplo n.º 6
0
        private void EditTrigger(TriggerNode selectedNode, Action updateAction)
        {
            var frm     = new CronSelector();
            var trigger = selectedNode.Trigger;
            var jobData = trigger.JobDataMap;

            if (jobData.ContainsKey(TriggerXml))
            {
                var oldCron = (string)jobData[TriggerXml];
                frm.SetXml(oldCron);
            }

            if (frm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // check if changed trigger conflicts with any calendar
            if (selectedNode.Trigger.CalendarName != null)
            {
                var cronStr     = frm.Expression;
                var selCal      = mScheduler.GetCalendar(selectedNode.Trigger.CalendarName);
                var tempTrigger = (AbstractTrigger)TriggerBuilder.Create().
                                  WithCronSchedule(cronStr).
                                  Build();
                var nextFire = tempTrigger.ComputeFirstFireTimeUtc(selCal);
                if (nextFire == null)
                {
                    var msg = string.Format("Calendar '{0}' will not let trigger '{1}' fire.", selectedNode.Trigger.CalendarName, selectedNode.Trigger.Description);
                    MessageBox.Show(msg, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // delete and re-add trigger so it survives a refresh
            var calName = selectedNode.Trigger.CalendarName;

            DeleteTrigger(selectedNode, NullUpdateAction);
            var jobNode = (JobNode)selectedNode.Parent;

            AddTrigger(jobNode, frm.Expression, frm.GetXml(), calName, updateAction);
        }
Exemplo n.º 7
0
 private void SetPauseButtonText(TriggerNode triggerNode)
 {
     CmdPause.Text = mScheduler.GetTriggerState(triggerNode.Trigger.Key) == TriggerState.Paused ? @"Resume" : @"Pause";
 }