diff --git a/QuartzNetWebConsole.Views/Views.vb b/QuartzNetWebConsole.Views/Views.vb index f42ae08..fb298cb 100644 --- a/QuartzNetWebConsole.Views/Views.vb +++ b/QuartzNetWebConsole.Views/Views.vb @@ -231,7 +231,7 @@ Public Module Views End Function - Public Function TriggerGroup(group As String, paused As Boolean, thisUrl As String, highlight As String, triggers As IEnumerable(Of TriggerWithState)) As XElement + Public Function TriggerGroup(group As String, paused As Boolean?, thisUrl As String, highlight As String, triggers As IEnumerable(Of TriggerWithState)) As XElement Dim schedulerOp = Function(method As String) "scheduler.ashx?method=" + method + "&groupName=" + group + "&next=" + HttpUtility.UrlEncode(thisUrl) @@ -244,10 +244,11 @@ Public Module Views Index

Trigger group <%= group %>

- Status: <%= If(paused, "paused", "started") %> - <%= If(paused, - SimpleForm(schedulerOp("ResumeTriggerGroup"), "Resume this trigger group"), - SimpleForm(schedulerOp("PauseTriggerGroup"), "Pause this trigger group")) %> + Status: <%= IfNullable(paused, ifNull:="N/A", ifTrue:="paused", ifFalse:="started") %> + <%= IfNullable(paused, + ifNull:=, + ifTrue:=SimpleForm(schedulerOp("ResumeTriggerGroup"), "Resume this trigger group"), + ifFalse:=SimpleForm(schedulerOp("PauseTriggerGroup"), "Pause this trigger group")) %>

Triggers

<%= TriggerTable(triggers, thisUrl, highlight) %> @@ -336,34 +337,36 @@ Public Module Views Public Function TriggerTable(triggers As IEnumerable(Of TriggerWithState), thisUrl As String, highlight As String) As XElement Return _ - - - - - - - - - - - - - - - - - - - - <%= From tr In triggers + If(triggers Is Nothing, + Not available, +
NameDescriptionPriorityJob groupJob nameStart time UTCEnd time UTCFinal fire time UTCNext fire time UTCRepeat countRepeat intervalTimes triggeredCronCalendarState
+ + + + + + + + + + + + + + + + + + + <%= From tr In triggers Let trigger = tr.Trigger Let high = highlight = trigger.Key.ToString() Let simpleTrigger = TryCast(trigger, SimpleTriggerImpl) Let cronTrigger = TryCast(trigger, CronTriggerImpl) Let op = Function(method As String) "scheduler.ashx?method=" & method & - "&triggerName=" + trigger.Key.Name + - "&groupName=" + trigger.Key.Group + - "&next=" + HttpUtility.UrlEncode(thisUrl) + "&triggerName=" + trigger.Key.Name + + "&groupName=" + trigger.Key.Group + + "&next=" + HttpUtility.UrlEncode(thisUrl) Select class=<%= If(highlight = trigger.Key.ToString(), "highlight", "") %>> @@ -398,6 +401,6 @@ Public Module Views <%= SimpleForm(op("UnscheduleJob"), "Delete") %> %> -
NameDescriptionPriorityJob groupJob nameStart time UTCEnd time UTCFinal fire time UTCNext fire time UTCRepeat countRepeat intervalTimes triggeredCronCalendarState
+ ) End Function End Module diff --git a/QuartzNetWebConsole/ControllerFactory.cs b/QuartzNetWebConsole/ControllerFactory.cs index 8237ef6..e2deba1 100644 --- a/QuartzNetWebConsole/ControllerFactory.cs +++ b/QuartzNetWebConsole/ControllerFactory.cs @@ -28,8 +28,8 @@ private static ISchedulerWrapper GetSchedulerWrapper() { Route("log", LogController.Execute), Route("scheduler", ctx => SchedulerController.Execute(ctx, GetSchedulerWrapper)), Route("static", StaticController.Execute), - Route("triggerGroup", ctx => TriggerGroupController.Execute(ctx, Setup.Scheduler)), - Route("triggersByJob", ctx => TriggersByJobController.Execute(ctx, Setup.Scheduler)), + Route("triggerGroup", ctx => TriggerGroupController.Execute(ctx, GetSchedulerWrapper)), + Route("triggersByJob", ctx => TriggersByJobController.Execute(ctx, GetSchedulerWrapper)), }; public static Route Route(string path, Action action) { diff --git a/QuartzNetWebConsole/Controllers/TriggerGroupController.cs b/QuartzNetWebConsole/Controllers/TriggerGroupController.cs index 31b8dd3..df7aa63 100644 --- a/QuartzNetWebConsole/Controllers/TriggerGroupController.cs +++ b/QuartzNetWebConsole/Controllers/TriggerGroupController.cs @@ -3,24 +3,32 @@ using System.Web; using MiniMVC; using Quartz; +using Quartz.Impl; using Quartz.Impl.Matchers; +using QuartzNetWebConsole.Utils; using QuartzNetWebConsole.Views; +using System.Collections.Generic; namespace QuartzNetWebConsole.Controllers { public class TriggerGroupController { - public static void Execute(HttpContextBase context, Func getScheduler) { + private static IEnumerable GetTriggers(ISchedulerWrapper scheduler, string group) { + var triggerKeys = scheduler.GetTriggerKeys(GroupMatcher.GroupEquals(group)); + if (triggerKeys == null) + return null; + return triggerKeys.Select(t => { + var trigger = scheduler.GetTrigger(t); + var state = scheduler.GetTriggerState(t); + return new TriggerWithState(trigger, state); + }); + } + + public static void Execute(HttpContextBase context, Func getScheduler) { var scheduler = getScheduler(); + var highlight = context.Request.QueryString["highlight"]; var group = context.Request.QueryString["group"]; - var triggerKeys = scheduler.GetTriggerKeys(GroupMatcher.GroupEquals(group)); - var triggers = triggerKeys - .Select(t => { - var trigger = scheduler.GetTrigger(t); - var state = scheduler.GetTriggerState(t); - return new TriggerWithState(trigger, state); - }); + var triggers = GetTriggers(scheduler, group); var thisUrl = context.Request.RawUrl; var paused = scheduler.IsTriggerGroupPaused(group); - var highlight = context.Request.QueryString["highlight"]; var v = Views.Views.TriggerGroup(group, paused, thisUrl, highlight, triggers); context.Response.Html(Helpers.XHTML(v)); } diff --git a/QuartzNetWebConsole/Controllers/TriggersByJobController.cs b/QuartzNetWebConsole/Controllers/TriggersByJobController.cs index 1d46a34..2cac0cb 100644 --- a/QuartzNetWebConsole/Controllers/TriggersByJobController.cs +++ b/QuartzNetWebConsole/Controllers/TriggersByJobController.cs @@ -3,22 +3,30 @@ using System.Web; using MiniMVC; using Quartz; +using QuartzNetWebConsole.Utils; using QuartzNetWebConsole.Views; +using System.Collections.Generic; namespace QuartzNetWebConsole.Controllers { public class TriggersByJobController { - public static void Execute(HttpContextBase context, Func getScheduler) { + private static IEnumerable GetTriggers(ISchedulerWrapper scheduler, JobKey jobKey) { + var triggers = scheduler.GetTriggersOfJob(jobKey); + if (triggers == null) + return null; + return triggers.Select(t => { + var state = scheduler.GetTriggerState(t.Key); + return new TriggerWithState(t, state); + }); + } + + public static void Execute(HttpContextBase context, Func getScheduler) { var scheduler = getScheduler(); + var highlight = context.Request.QueryString["highlight"]; var group = context.Request.QueryString["group"]; var job = context.Request.QueryString["job"]; var jobKey = new JobKey(job, group); + var triggers = GetTriggers(scheduler, jobKey); var thisUrl = context.Request.RawUrl; - var triggers = scheduler.GetTriggersOfJob(jobKey) - .Select(t => { - var state = scheduler.GetTriggerState(t.Key); - return new TriggerWithState(t, state); - }); - var highlight = context.Request.QueryString["highlight"]; var m = new TriggersByJobModel(triggers, thisUrl, group, job, highlight); context.Response.Html(Helpers.XHTML(Views.Views.TriggersByJob(m))); } diff --git a/QuartzNetWebConsole/Utils/ISchedulerWrapper.cs b/QuartzNetWebConsole/Utils/ISchedulerWrapper.cs index 4959c5d..7813fe2 100644 --- a/QuartzNetWebConsole/Utils/ISchedulerWrapper.cs +++ b/QuartzNetWebConsole/Utils/ISchedulerWrapper.cs @@ -37,5 +37,9 @@ public interface ISchedulerWrapper { bool InStandbyMode { get; } ICalendar GetCalendar(string name); SchedulerMetaData GetMetaData(); + IEnumerable GetTriggersOfJob(JobKey jobKey); + ISet GetTriggerKeys(GroupMatcher matcher); + ITrigger GetTrigger(TriggerKey triggerKey); + TriggerState GetTriggerState(TriggerKey triggerKey); } } \ No newline at end of file diff --git a/QuartzNetWebConsole/Utils/SchedulerWrapper.cs b/QuartzNetWebConsole/Utils/SchedulerWrapper.cs index 32e8a1b..eaafa83 100644 --- a/QuartzNetWebConsole/Utils/SchedulerWrapper.cs +++ b/QuartzNetWebConsole/Utils/SchedulerWrapper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Quartz; using Quartz.Collection; using Quartz.Impl.Matchers; @@ -142,6 +143,30 @@ public SchedulerMetaData GetMetaData() { return scheduler.GetMetaData(); } + public IEnumerable GetTriggersOfJob(JobKey jobKey) { + try { + return scheduler.GetTriggersOfJob(jobKey); + } catch (NotImplementedException) { + return null; + } + } + + public ISet GetTriggerKeys(GroupMatcher matcher) { + try { + return scheduler.GetTriggerKeys(matcher); + } catch (NotImplementedException) { + return null; + } + } + + public ITrigger GetTrigger(TriggerKey triggerKey) { + return scheduler.GetTrigger(triggerKey); + } + + public TriggerState GetTriggerState(TriggerKey triggerKey) { + return scheduler.GetTriggerState(triggerKey); + } + public string SchedulerName { get { return scheduler.SchedulerName;