From ba47bc27766a32493907ff862696305bc0fe3055 Mon Sep 17 00:00:00 2001 From: mausch Date: Tue, 11 Dec 2012 13:09:04 -0300 Subject: [PATCH] Simpler --- QuartzNetWebConsole/ControllerFactory.cs | 33 +++++++++--------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/QuartzNetWebConsole/ControllerFactory.cs b/QuartzNetWebConsole/ControllerFactory.cs index d9c222b..3ef9769 100644 --- a/QuartzNetWebConsole/ControllerFactory.cs +++ b/QuartzNetWebConsole/ControllerFactory.cs @@ -4,39 +4,30 @@ using System.Web; using MiniMVC; using QuartzNetWebConsole.Controllers; +using Route = System.Collections.Generic.KeyValuePair>; 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> routes = + private readonly IEnumerable 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 KV(K key, V value) { - return new KeyValuePair(key, value); + public static KeyValuePair> Route(string path, Action action) { + return new KeyValuePair>(path, action); } } } \ No newline at end of file