-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
205 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Web; | ||
using MiniMVC; | ||
|
||
namespace QuartzNetWebConsole.Controllers { | ||
public class LogController : Controller { | ||
private readonly ILogger logger = Setup.Logger; | ||
|
||
public override IResult Execute(HttpContextBase context) { | ||
if (logger == null) | ||
return new RawResult("No logger defined"); | ||
return new ViewResult(logger, ViewName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using System.Collections.Generic; | ||
using Quartz; | ||
|
||
namespace QuartzNetWebConsole { | ||
public interface ILogger: ISchedulerListener, IJobListener, ITriggerListener, IEnumerable<LogEntry> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
|
||
namespace QuartzNetWebConsole { | ||
public class LogEntry { | ||
private readonly DateTime timestamp; | ||
private readonly string description; | ||
|
||
public DateTime Timestamp { | ||
get { return timestamp; } | ||
} | ||
|
||
public string Description { | ||
get { return description; } | ||
} | ||
|
||
public LogEntry(string description) { | ||
timestamp = DateTime.Now; | ||
this.description = description; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using Quartz; | ||
using QuartzNetWebConsole.Utils; | ||
|
||
namespace QuartzNetWebConsole { | ||
public class MemoryLogger : ILogger { | ||
private readonly CircularBuffer<LogEntry> entries; | ||
|
||
public MemoryLogger(int capacity) { | ||
entries = new CircularBuffer<LogEntry>(capacity); | ||
} | ||
|
||
public void JobScheduled(Trigger trigger) { | ||
var desc = string.Format("Job {0} scheduled with trigger {1}", trigger.FullJobName, Describe(trigger)); | ||
entries.Add(new LogEntry(desc)); | ||
} | ||
|
||
private string Describe(Trigger trigger) { | ||
var cronTrigger = trigger as CronTrigger; | ||
var cronDesc = cronTrigger == null ? null : cronTrigger.CronExpressionString; | ||
|
||
var simpleTrigger = trigger as SimpleTrigger; | ||
var simpleDesc = simpleTrigger == null ? null : string.Format("interval {0}, repeat count {1}", simpleTrigger.RepeatInterval, simpleTrigger.RepeatCount); | ||
return string.Format("{0}.{1} ({2}) {3}{4}", trigger.Group, trigger.Name, trigger.GetType(), cronDesc, simpleDesc); | ||
} | ||
|
||
public void JobUnscheduled(string triggerName, string triggerGroup) { | ||
entries.Add(new LogEntry(string.Format("Trigger removed: {0}.{1}", triggerGroup, triggerName))); | ||
} | ||
|
||
public void TriggerFinalized(Trigger trigger) { | ||
entries.Add(new LogEntry(string.Format("Trigger finalized: {0}", Describe(trigger)))); | ||
} | ||
|
||
public void TriggersPaused(string triggerName, string triggerGroup) { | ||
entries.Add(new LogEntry(string.Format("Trigger paused: {0}.{1}", triggerGroup, triggerName))); | ||
} | ||
|
||
public void TriggersResumed(string triggerName, string triggerGroup) { | ||
entries.Add(new LogEntry(string.Format("Trigger resumed: {0}.{1}", triggerGroup, triggerName))); | ||
} | ||
|
||
public void JobsPaused(string jobName, string jobGroup) { | ||
entries.Add(new LogEntry(string.Format("Job paused: {0}.{1}", jobGroup, jobName))); | ||
} | ||
|
||
public void JobsResumed(string jobName, string jobGroup) { | ||
entries.Add(new LogEntry(string.Format("Job resumed: {0}.{1}", jobGroup, jobName))); | ||
} | ||
|
||
public void SchedulerError(string msg, SchedulerException cause) { | ||
entries.Add(new LogEntry(string.Format("Scheduler error: {0}\n{1}", msg, cause))); | ||
} | ||
|
||
public void SchedulerShutdown() { | ||
entries.Add(new LogEntry("Scheduler shutdown")); | ||
} | ||
|
||
public void JobToBeExecuted(JobExecutionContext context) { | ||
entries.Add(new LogEntry(string.Format("Job to be executed: {0}", Describe(context)))); | ||
} | ||
|
||
private string Describe(JobExecutionContext context) { | ||
return string.Format("{0} (trigger {1})", context.JobDetail.FullName, Describe(context.Trigger)); | ||
} | ||
|
||
public void JobExecutionVetoed(JobExecutionContext context) { | ||
entries.Add(new LogEntry(string.Format("Job execution vetoed: {0}", Describe(context)))); | ||
} | ||
|
||
public void JobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { | ||
var description = string.Format("Job was executed: {0}", Describe(context)); | ||
if (jobException != null) | ||
description += "\nwith exception: " + jobException; | ||
entries.Add(new LogEntry(description)); | ||
} | ||
|
||
public void TriggerFired(Trigger trigger, JobExecutionContext context) { | ||
entries.Add(new LogEntry(string.Format("Trigger fired: {0}", Describe(context)))); | ||
} | ||
|
||
public bool VetoJobExecution(Trigger trigger, JobExecutionContext context) { | ||
return false; | ||
} | ||
|
||
public void TriggerMisfired(Trigger trigger) { | ||
entries.Add(new LogEntry(string.Format("Trigger misfired: {0}", Describe(trigger)))); | ||
} | ||
|
||
public void TriggerComplete(Trigger trigger, JobExecutionContext context, SchedulerInstruction triggerInstructionCode) { | ||
entries.Add(new LogEntry(string.Format("Trigger complete: {0}", Describe(context)))); | ||
} | ||
|
||
string ITriggerListener.Name { | ||
get { return GetType().Name; } | ||
} | ||
|
||
string IJobListener.Name { | ||
get { return GetType().Name; } | ||
} | ||
|
||
public IEnumerator<LogEntry> GetEnumerator() { | ||
return entries.GetEnumerator(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() { | ||
return GetEnumerator(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
SampleApp/Resources/QuartzNetWebConsole.Resources.Log.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html> | ||
<head> | ||
<title>Quartz.Net Console - Log</title> | ||
<link rel="stylesheet" type="text/css" href="static.ashx?r=styles.css&t=text%2Fcss" /> | ||
</head> | ||
<body> | ||
<h1>Scheduler log</h1> | ||
<table> | ||
<tr> | ||
<th>Date / Time</th> | ||
<th>Description</th> | ||
</tr> | ||
#foreach ($i in $model) | ||
#before | ||
<tr | ||
#odd | ||
> | ||
#even | ||
class="alt"> | ||
#each | ||
<td>$i.Timestamp</td> | ||
<td>$i.Description</td> | ||
</tr> | ||
#end | ||
</table> | ||
</body> | ||
</html> |