Skip to content

Commit

Permalink
Simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
mausch committed Dec 11, 2012
1 parent a8b54d7 commit ba47bc2
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions QuartzNetWebConsole/ControllerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,30 @@
using System.Web;
using MiniMVC;
using QuartzNetWebConsole.Controllers;
using Route = System.Collections.Generic.KeyValuePair<string, System.Action<System.Web.HttpContextBase>>;

namespace QuartzNetWebConsole {
public class ControllerFactory : HttpHandlerFactory {
public override IHttpHandler GetHandler(HttpContextBase context) {
var lastUrlSegment = context.Request.Url.Segments.Last().Split('.')[0];
return routes.Where(k => k.Key.Equals(lastUrlSegment, StringComparison.InvariantCultureIgnoreCase))
.Select(k => k.Value)
.Select(k => new HttpHandlerWithReadOnlySession(k.Value))
.FirstOrDefault();
}


private readonly IEnumerable<KeyValuePair<string, IHttpHandler>> routes =
private readonly IEnumerable<Route> routes =
new[] {
KV("jobgroup", JobGroupHandler),
KV("index", IndexHandler),
KV("log", LogHandler),
KV("scheduler", SchedulerHandler),
KV("static", StaticHandler),
KV("triggerGroup", TriggerGroupHandler),
KV("triggersByJob", TriggersByJobHandler),
Route("jobgroup", JobGroupController.Execute),
Route("index", IndexController.Execute),
Route("log", LogController.Execute),
Route("scheduler", SchedulerController.Execute),
Route("static", StaticController.Execute),
Route("triggerGroup", TriggerGroupController.Execute),
Route("triggersByJob", TriggersByJobController.Execute),
};

private static readonly IHttpHandler IndexHandler = new HttpHandlerWithReadOnlySession(IndexController.Execute);
private static readonly IHttpHandler JobGroupHandler = new HttpHandlerWithReadOnlySession(JobGroupController.Execute);
private static readonly IHttpHandler LogHandler = new HttpHandlerWithReadOnlySession(LogController.Execute);
private static readonly IHttpHandler SchedulerHandler = new HttpHandlerWithReadOnlySession(SchedulerController.Execute);
private static readonly IHttpHandler StaticHandler = new HttpHandlerWithReadOnlySession(StaticController.Execute);
private static readonly IHttpHandler TriggerGroupHandler = new HttpHandlerWithReadOnlySession(TriggerGroupController.Execute);
private static readonly IHttpHandler TriggersByJobHandler = new HttpHandlerWithReadOnlySession(TriggersByJobController.Execute);


public static KeyValuePair<K, V> KV<K, V>(K key, V value) {
return new KeyValuePair<K, V>(key, value);
public static KeyValuePair<string, Action<HttpContextBase>> Route(string path, Action<HttpContextBase> action) {
return new KeyValuePair<string, Action<HttpContextBase>>(path, action);
}
}
}

0 comments on commit ba47bc2

Please sign in to comment.