| @@ -12,6 +12,7 @@ using Quartz.Impl; | |||||
| using Quartz.Impl.Triggers; | using Quartz.Impl.Triggers; | ||||
| using Quartz.Job; | using Quartz.Job; | ||||
| using System.IO; | using System.IO; | ||||
| using Quartz.Util; | |||||
| namespace ClickForensics.Quartz.Manager | namespace ClickForensics.Quartz.Manager | ||||
| { | { | ||||
| @@ -67,8 +68,8 @@ namespace ClickForensics.Quartz.Manager | |||||
| setTriggerType(); | setTriggerType(); | ||||
| txtCronExpression.Text = trigger.CronExpressionString; | txtCronExpression.Text = trigger.CronExpressionString; | ||||
| txtTriggerDescription.Text = trigger.Description; | txtTriggerDescription.Text = trigger.Description; | ||||
| txtTriggerGroup.Text = trigger.Name.Group; | |||||
| txtTriggerName.Text = trigger.Name; | |||||
| txtTriggerGroup.Text = trigger.Key.Group; | |||||
| txtTriggerName.Text = trigger.Key.Name; | |||||
| } | } | ||||
| private void setJobData(IJobDetail detail) | private void setJobData(IJobDetail detail) | ||||
| @@ -109,39 +110,40 @@ namespace ClickForensics.Quartz.Manager | |||||
| private void btnAdd_Click(object sender, EventArgs e) | private void btnAdd_Click(object sender, EventArgs e) | ||||
| { | { | ||||
| JobDetail = getJobDetail(); | JobDetail = getJobDetail(); | ||||
| AbstractTrigger trigger = getTrigger(); | |||||
| Trigger.JobGroup = JobDetail.Key.Group; | |||||
| Trigger.JobName = JobDetail.Key.Name; | |||||
| ITrigger trigger = getTrigger(JobDetail); | |||||
| this.Close(); | this.Close(); | ||||
| } | } | ||||
| private IJobDetail getJobDetail() | private IJobDetail getJobDetail() | ||||
| { | { | ||||
| IJobDetail detail = new IJobDetail(); | |||||
| detail.Description = txtJobDescription.Text; | |||||
| detail.Group = txtJobGroup.Text; | |||||
| detail.JobDataMap = getJobDataMap(); | |||||
| detail.JobType = getJobType(); | |||||
| detail.Name = txtJobName.Text; | |||||
| IJobDetail detail = JobBuilder | |||||
| .NewJob() | |||||
| .OfType(getJobType()) | |||||
| .WithDescription(txtJobDescription.Text) | |||||
| .WithIdentity(new JobKey(txtJobName.Text, txtJobGroup.Text)) | |||||
| .UsingJobData(getJobDataMap()) | |||||
| .Build(); | |||||
| return detail; | return detail; | ||||
| } | } | ||||
| private AbstractTrigger getTrigger() | |||||
| private ITrigger getTrigger(IJobDetail jobDetail) | |||||
| { | { | ||||
| AbstractTrigger trigger; | |||||
| var builder = | |||||
| TriggerBuilder | |||||
| .Create() | |||||
| .ForJob(jobDetail) | |||||
| .WithDescription(txtTriggerDescription.Text) | |||||
| .WithIdentity(new TriggerKey(txtTriggerName.Text, txtTriggerGroup.Text)); | |||||
| if (cboTriggerType.SelectedText == "Simple") | if (cboTriggerType.SelectedText == "Simple") | ||||
| { | { | ||||
| trigger = new SimpleTrigger(); | |||||
| return builder.WithSchedule(SimpleScheduleBuilder.Create()).Build(); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| trigger = new CronTrigger(); | |||||
| ((CronTrigger)trigger).CronExpressionString = txtCronExpression.Text; | |||||
| return builder.WithSchedule(CronScheduleBuilder.CronSchedule(txtCronExpression.Text)).Build(); | |||||
| } | } | ||||
| trigger.Description = txtTriggerDescription.Text; | |||||
| trigger.Group = txtTriggerGroup.Text; | |||||
| trigger.Name = txtTriggerName.Text; | |||||
| return trigger; | |||||
| } | } | ||||
| private Type getJobType() | private Type getJobType() | ||||
| @@ -54,8 +54,9 @@ | |||||
| <Reference Include="Common.Logging"> | <Reference Include="Common.Logging"> | ||||
| <HintPath>..\lib\Common.Logging.dll</HintPath> | <HintPath>..\lib\Common.Logging.dll</HintPath> | ||||
| </Reference> | </Reference> | ||||
| <Reference Include="Quartz"> | |||||
| <HintPath>..\lib\Quartz.dll</HintPath> | |||||
| <Reference Include="Quartz, Version=2.0.0.29445, Culture=neutral, processorArchitecture=MSIL"> | |||||
| <SpecificVersion>False</SpecificVersion> | |||||
| <HintPath>..\..\quartznet\build\4.0\Debug\Quartz.Server\Quartz.dll</HintPath> | |||||
| </Reference> | </Reference> | ||||
| <Reference Include="System" /> | <Reference Include="System" /> | ||||
| <Reference Include="System.configuration" /> | <Reference Include="System.configuration" /> | ||||
| @@ -21,35 +21,35 @@ namespace ClickForensics.Quartz.Manager | |||||
| void CronTriggerDisplay_Load(object sender, EventArgs e) | void CronTriggerDisplay_Load(object sender, EventArgs e) | ||||
| { | { | ||||
| txtCronExpression.Text = _trigger.CronExpressionString; | |||||
| lblDescription.Text = _trigger.Description; | |||||
| lblGroup.Text = _trigger.Group; | |||||
| lblName.Text = _trigger.Name; | |||||
| if (_trigger.GetNextFireTimeUtc().HasValue) | |||||
| txtCronExpression.Text = _Trigger.CronExpressionString; | |||||
| lblDescription.Text = _Trigger.Description; | |||||
| lblGroup.Text = _Trigger.Key.Group; | |||||
| lblName.Text = _Trigger.Key.Name; | |||||
| if (_Trigger.GetNextFireTimeUtc().HasValue) | |||||
| { | { | ||||
| lblNextFireTime.Text = _trigger.GetNextFireTimeUtc().Value.ToLocalTime().ToString(); | |||||
| lblNextFireTime.Text = _Trigger.GetNextFireTimeUtc().Value.ToLocalTime().ToString(); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| lblNextFireTime.Text = "Unknown"; | lblNextFireTime.Text = "Unknown"; | ||||
| } | } | ||||
| if (_trigger.GetPreviousFireTimeUtc().HasValue) | |||||
| if (_Trigger.GetPreviousFireTimeUtc().HasValue) | |||||
| { | { | ||||
| lblPreviousFireTime.Text = _trigger.GetPreviousFireTimeUtc().Value.ToLocalTime().ToString(); | |||||
| lblPreviousFireTime.Text = _Trigger.GetPreviousFireTimeUtc().Value.ToLocalTime().ToString(); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| lblPreviousFireTime.Text = "Unknown"; | lblPreviousFireTime.Text = "Unknown"; | ||||
| } | } | ||||
| } | } | ||||
| public CronTriggerDisplay(CronTriggerImpl trigger) | |||||
| public CronTriggerDisplay(ICronTrigger trigger) | |||||
| : this() | : this() | ||||
| { | { | ||||
| _trigger = trigger; | |||||
| _Trigger = trigger; | |||||
| } | } | ||||
| private CronTriggerImpl _trigger; | |||||
| private ICronTrigger _Trigger; | |||||
| } | } | ||||
| } | } | ||||
| @@ -12,6 +12,7 @@ using System.Net.Sockets; | |||||
| //using ClickForensics.Quartz.Jobs; | //using ClickForensics.Quartz.Jobs; | ||||
| using System.IO; | using System.IO; | ||||
| using Quartz.Impl; | using Quartz.Impl; | ||||
| using Quartz.Impl.Matchers; | |||||
| using Quartz.Impl.Triggers; | using Quartz.Impl.Triggers; | ||||
| namespace ClickForensics.Quartz.Manager | namespace ClickForensics.Quartz.Manager | ||||
| @@ -59,9 +60,9 @@ namespace ClickForensics.Quartz.Manager | |||||
| { | { | ||||
| btnPause.Enabled = true; | btnPause.Enabled = true; | ||||
| setPauseButtonText(); | setPauseButtonText(); | ||||
| if (((TriggerNode)e.Node).Trigger is CronTrigger) | |||||
| if (((TriggerNode)e.Node).Trigger is ICronTrigger) | |||||
| { | { | ||||
| pnlDetails.Controls.Add(new CronTriggerDisplay((CronTrigger)((TriggerNode)e.Node).Trigger)); | |||||
| pnlDetails.Controls.Add(new CronTriggerDisplay((ICronTrigger)((TriggerNode)e.Node).Trigger)); | |||||
| jobDetailsToggle(true); | jobDetailsToggle(true); | ||||
| } | } | ||||
| btnEdit.Enabled = true; | btnEdit.Enabled = true; | ||||
| @@ -76,9 +77,7 @@ namespace ClickForensics.Quartz.Manager | |||||
| private void setPauseButtonText() | private void setPauseButtonText() | ||||
| { | { | ||||
| TriggerNode node = (TriggerNode)jobGroupsTreeView.SelectedNode; | TriggerNode node = (TriggerNode)jobGroupsTreeView.SelectedNode; | ||||
| string name = node.Trigger.Name; | |||||
| string group = node.Trigger.Group; | |||||
| if (Scheduler.GetScheduler().GetTriggerState(name, group) == TriggerState.Paused) | |||||
| if (Scheduler.GetScheduler().GetTriggerState(node.Trigger.Key) == TriggerState.Paused) | |||||
| { | { | ||||
| btnPause.Text = "Resume"; | btnPause.Text = "Resume"; | ||||
| } | } | ||||
| @@ -135,7 +134,7 @@ namespace ClickForensics.Quartz.Manager | |||||
| schedulerNode.ContextMenuStrip = ctxScheduler; | schedulerNode.ContextMenuStrip = ctxScheduler; | ||||
| jobGroupsTreeView.Nodes.Add(schedulerNode); | jobGroupsTreeView.Nodes.Add(schedulerNode); | ||||
| TreeNode jobGroupsNode = schedulerNode.Nodes.Add("Job Groups"); | TreeNode jobGroupsNode = schedulerNode.Nodes.Add("Job Groups"); | ||||
| string[] jobGroups = Scheduler.GetScheduler().JobGroupNames; | |||||
| var jobGroups = Scheduler.GetScheduler().GetJobGroupNames(); | |||||
| foreach (string jobGroup in jobGroups) | foreach (string jobGroup in jobGroups) | ||||
| { | { | ||||
| TreeNode jobGroupNode = jobGroupsNode.Nodes.Add(jobGroup); | TreeNode jobGroupNode = jobGroupsNode.Nodes.Add(jobGroup); | ||||
| @@ -188,12 +187,13 @@ namespace ClickForensics.Quartz.Manager | |||||
| private void addJobNodes(TreeNode node) | private void addJobNodes(TreeNode node) | ||||
| { | { | ||||
| string group = node.Parent.Text; | string group = node.Parent.Text; | ||||
| string[] jobs = Scheduler.GetScheduler().GetJobNames(group); | |||||
| foreach (string jobName in jobs) | |||||
| var groupMatcher = GroupMatcher<JobKey>.GroupContains(group); | |||||
| var jobKeys = Scheduler.GetScheduler().GetJobKeys(groupMatcher); | |||||
| foreach (var jobKey in jobKeys) | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| IJobDetail detail = Scheduler.GetScheduler().GetJobDetail(new JobKey(jobName, group)); | |||||
| IJobDetail detail = Scheduler.GetScheduler().GetJobDetail(jobKey); | |||||
| JobNode jobNode = new JobNode(detail); | JobNode jobNode = new JobNode(detail); | ||||
| node.Nodes.Add(jobNode); | node.Nodes.Add(jobNode); | ||||
| addTriggerNodes(jobNode); | addTriggerNodes(jobNode); | ||||
| @@ -221,9 +221,9 @@ namespace ClickForensics.Quartz.Manager | |||||
| private void addTriggerNodes(TreeNode treeNode) | private void addTriggerNodes(TreeNode treeNode) | ||||
| { | { | ||||
| AbstractTrigger[] triggers = Scheduler.GetScheduler().GetTriggersOfJob(treeNode.Text, treeNode.Parent.Parent.Text); | |||||
| var triggers = Scheduler.GetScheduler().GetTriggersOfJob(new JobKey(treeNode.Text, treeNode.Parent.Parent.Text)); | |||||
| TreeNode triggersNode = treeNode.Nodes.Add("Triggers"); | TreeNode triggersNode = treeNode.Nodes.Add("Triggers"); | ||||
| foreach (AbstractTrigger trigger in triggers) | |||||
| foreach (var trigger in triggers) | |||||
| { | { | ||||
| TriggerNode node = new TriggerNode(trigger); | TriggerNode node = new TriggerNode(trigger); | ||||
| triggersNode.Nodes.Add(node); | triggersNode.Nodes.Add(node); | ||||
| @@ -313,9 +313,7 @@ namespace ClickForensics.Quartz.Manager | |||||
| private void btnRunJobNow_Click(object sender, EventArgs e) | private void btnRunJobNow_Click(object sender, EventArgs e) | ||||
| { | { | ||||
| JobNode node = (JobNode)jobGroupsTreeView.SelectedNode; | JobNode node = (JobNode)jobGroupsTreeView.SelectedNode; | ||||
| string job = node.Detail.Name; | |||||
| string group = node.Detail.Group; | |||||
| Scheduler.GetScheduler().TriggerJobWithVolatileTrigger(job, group); | |||||
| Scheduler.GetScheduler().TriggerJob(node.Detail.Key); | |||||
| } | } | ||||
| private void btnDeleteJob_Click(object sender, EventArgs e) | private void btnDeleteJob_Click(object sender, EventArgs e) | ||||
| @@ -324,15 +322,13 @@ namespace ClickForensics.Quartz.Manager | |||||
| if (selectedNode is JobNode) | if (selectedNode is JobNode) | ||||
| { | { | ||||
| JobNode node = (JobNode)jobGroupsTreeView.SelectedNode; | JobNode node = (JobNode)jobGroupsTreeView.SelectedNode; | ||||
| string job = node.Detail.Name; | |||||
| string group = node.Detail.Group; | |||||
| Scheduler.GetScheduler().DeleteJob(job, group); | |||||
| Scheduler.GetScheduler().DeleteJob(node.Detail.Key); | |||||
| jobGroupsTreeView.SelectedNode.Remove(); | jobGroupsTreeView.SelectedNode.Remove(); | ||||
| } | } | ||||
| if (selectedNode is TriggerNode) | if (selectedNode is TriggerNode) | ||||
| { | { | ||||
| Scheduler.GetScheduler().UnscheduleJob(((TriggerNode)selectedNode).Trigger.Name, ((TriggerNode)selectedNode).Trigger.Group); | |||||
| Scheduler.GetScheduler().UnscheduleJob(((TriggerNode)selectedNode).Trigger.Key); | |||||
| } | } | ||||
| //loadJobGroups(); | //loadJobGroups(); | ||||
| @@ -341,15 +337,13 @@ namespace ClickForensics.Quartz.Manager | |||||
| private void btnPause_Click(object sender, EventArgs e) | private void btnPause_Click(object sender, EventArgs e) | ||||
| { | { | ||||
| TriggerNode node = (TriggerNode)jobGroupsTreeView.SelectedNode; | TriggerNode node = (TriggerNode)jobGroupsTreeView.SelectedNode; | ||||
| string name = node.Trigger.Name; | |||||
| string group = node.Trigger.Group; | |||||
| if (Scheduler.GetScheduler().GetTriggerState(name, group) == TriggerState.Paused) | |||||
| if (Scheduler.GetScheduler().GetTriggerState(node.Trigger.Key) == TriggerState.Paused) | |||||
| { | { | ||||
| Scheduler.GetScheduler().ResumeTrigger(name, group); | |||||
| Scheduler.GetScheduler().ResumeTrigger(node.Trigger.Key); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| Scheduler.GetScheduler().PauseTrigger(name, group); | |||||
| Scheduler.GetScheduler().PauseTrigger(node.Trigger.Key); | |||||
| } | } | ||||
| setPauseButtonText(); | setPauseButtonText(); | ||||
| } | } | ||||
| @@ -361,7 +355,7 @@ namespace ClickForensics.Quartz.Manager | |||||
| form.ShowDialog(); | form.ShowDialog(); | ||||
| if (form.JobDetail != null && form.Trigger != null) | if (form.JobDetail != null && form.Trigger != null) | ||||
| { | { | ||||
| Scheduler.GetScheduler().RescheduleJob(node.Trigger.Name, node.Trigger.Group, form.Trigger); | |||||
| Scheduler.GetScheduler().RescheduleJob(node.Trigger.Key, form.Trigger); | |||||
| loadJobGroups(); | loadJobGroups(); | ||||
| } | } | ||||
| } | } | ||||
| @@ -147,14 +147,16 @@ namespace ClickForensics.Quartz.Manager | |||||
| public void BackupToFile(System.IO.FileInfo file) | public void BackupToFile(System.IO.FileInfo file) | ||||
| { | { | ||||
| IScheduler scheduler = GetScheduler(); | IScheduler scheduler = GetScheduler(); | ||||
| string[] jobGroupNames = scheduler.JobGroupNames; | |||||
| var jobGroupNames = scheduler.GetJobGroupNames(); | |||||
| List<IJobDetail> jobDetails = new List<IJobDetail>(); | List<IJobDetail> jobDetails = new List<IJobDetail>(); | ||||
| foreach (var jobGroup in jobGroupNames) | foreach (var jobGroup in jobGroupNames) | ||||
| { | { | ||||
| string[] jobNames = scheduler.GetJobNames(jobGroup); | |||||
| foreach (var jobName in jobNames) | |||||
| var groupMatcher = GroupMatcher<JobKey>.GroupContains(jobGroup); | |||||
| var jobKeys = scheduler.GetJobKeys(groupMatcher); | |||||
| foreach (var jobKey in jobKeys) | |||||
| { | { | ||||
| jobDetails.Add(scheduler.GetJobDetail(jobName, jobGroup)); | |||||
| jobDetails.Add(scheduler.GetJobDetail(jobKey)); | |||||
| } | } | ||||
| } | } | ||||
| writeToFile(file, jobDetails); | writeToFile(file, jobDetails); | ||||
| @@ -173,16 +175,17 @@ namespace ClickForensics.Quartz.Manager | |||||
| , new XAttribute("overwrite-existing-jobs", "true") | , new XAttribute("overwrite-existing-jobs", "true") | ||||
| ) | ) | ||||
| ); | ); | ||||
| foreach (JobDetail detail in jobDetails) | |||||
| foreach (IJobDetail detail in jobDetails) | |||||
| { | { | ||||
| doc.Root.Add( | doc.Root.Add( | ||||
| new XElement(ns + "job" | new XElement(ns + "job" | ||||
| , new XElement(ns + "job-detail" | , new XElement(ns + "job-detail" | ||||
| , new XElement(ns + "name", detail.Name) | |||||
| , new XElement(ns + "group", detail.Group) | |||||
| , new XElement(ns + "name", detail.Key.Name) | |||||
| , new XElement(ns + "group", detail.Key.Group) | |||||
| , new XElement(ns + "description", detail.Description) | , new XElement(ns + "description", detail.Description) | ||||
| , new XElement(ns + "job-type", detail.JobType.FullName + "," + detail.JobType.Assembly.FullName) | , new XElement(ns + "job-type", detail.JobType.FullName + "," + detail.JobType.Assembly.FullName) | ||||
| , new XElement(ns + "volatile", detail.Volatile) | |||||
| //TODO: Apparently volatile is no longer available. Check. | |||||
| //, new XElement(ns + "volatile", detail.Volatile) | |||||
| , new XElement(ns + "durable", detail.Durable) | , new XElement(ns + "durable", detail.Durable) | ||||
| , new XElement(ns + "recover", detail.RequestsRecovery) | , new XElement(ns + "recover", detail.RequestsRecovery) | ||||
| , getJobDataMap(ns, detail.JobDataMap) | , getJobDataMap(ns, detail.JobDataMap) | ||||
| @@ -246,8 +249,8 @@ namespace ClickForensics.Quartz.Manager | |||||
| private void addCommonTriggerData(XNamespace ns, XElement rootTriggerElement, AbstractTrigger trigger) | private void addCommonTriggerData(XNamespace ns, XElement rootTriggerElement, AbstractTrigger trigger) | ||||
| { | { | ||||
| rootTriggerElement.Add( | rootTriggerElement.Add( | ||||
| new XElement(ns + "name", trigger.Name) | |||||
| , new XElement(ns + "group", trigger.Group) | |||||
| new XElement(ns + "name", trigger.Key.Name) | |||||
| , new XElement(ns + "group", trigger.Key.Group) | |||||
| , new XElement(ns + "description", trigger.Description) | , new XElement(ns + "description", trigger.Description) | ||||
| , new XElement(ns + "misfire-instruction", getMisfireInstructionText(trigger)) | , new XElement(ns + "misfire-instruction", getMisfireInstructionText(trigger)) | ||||
| //, new XElement(ns + "volatile", trigger.Volatile) | //, new XElement(ns + "volatile", trigger.Volatile) | ||||
| @@ -10,12 +10,12 @@ namespace ClickForensics.Quartz.Manager | |||||
| { | { | ||||
| public class TriggerNode : TreeNode | public class TriggerNode : TreeNode | ||||
| { | { | ||||
| public TriggerNode(AbstractTrigger trigger) | |||||
| public TriggerNode(ITrigger trigger) | |||||
| { | { | ||||
| Text = trigger.Name; | |||||
| Text = Trigger.Key.Name; | |||||
| Trigger = trigger; | Trigger = trigger; | ||||
| } | } | ||||
| public AbstractTrigger Trigger { get; set; } | |||||
| public ITrigger Trigger { get; set; } | |||||
| } | } | ||||
| } | } | ||||