private void AddTrigger(JobNode selectedNode, Action updateAction) { var frm = new CronSelector(); if (frm.ShowDialog() != DialogResult.OK) { return; } // add cron trigger AddTrigger(selectedNode, frm.Expression, frm.GetXml(), null, NullUpdateAction); updateAction(); }
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); }