Skip to content

Commit

Permalink
Cleaning up formatting and style
Browse files Browse the repository at this point in the history
  • Loading branch information
haacked committed Dec 31, 2011
1 parent 441653f commit 5b6f31b
Show file tree
Hide file tree
Showing 24 changed files with 655 additions and 348 deletions.
16 changes: 10 additions & 6 deletions src/RouteDebug/App_Start/PreApplicationStart.cs
@@ -1,15 +1,19 @@
using System.Configuration;
using System;
using System.Configuration;
using System.Web;
using RouteDebug;
using System;

[assembly: PreApplicationStartMethod(typeof(PreApplicationStart), "Start")]

namespace RouteDebug {
public class PreApplicationStart {
public static void Start() {
namespace RouteDebug
{
public class PreApplicationStart
{
public static void Start()
{
bool enabled = Convert.ToBoolean(ConfigurationManager.AppSettings["RouteDebugger:Enabled"]);
if (enabled) {
if (enabled)
{
Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(RouteDebuggerHttpModule));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/RouteDebug/DebugHttpHandler.cs
Expand Up @@ -54,7 +54,7 @@ public void ProcessRequest(HttpContext context)
}
}

string htmlFormat = @"<html>
const string htmlFormat = @"<html>
<div id=""haackroutedebugger"" style=""background-color: #fff;"">
<style>
#haackroutedebugger, #haackroutedebugger td, #haackroutedebugger th {{background-color: #fff; font-family: verdana, helvetica, san-serif; font-size: small;}}
Expand Down Expand Up @@ -160,7 +160,7 @@ public void ProcessRequest(HttpContext context)
dataTokensRows += string.Format("\t<tr><td>{0}</td><td>{1}&nbsp;</td></tr>", key, routeData.DataTokens[key]);
}

Route matchedRoute = matchedRouteBase as Route;
var matchedRoute = matchedRouteBase as Route;

if (matchedRoute != null)
matchedRouteUrl = matchedRoute.Url;
Expand Down
11 changes: 7 additions & 4 deletions src/RouteDebug/DebugRoute.cs
@@ -1,10 +1,13 @@
using System.Web.Routing;

namespace RouteDebug {
public class DebugRoute : Route {
private static DebugRoute singleton = new DebugRoute();
namespace RouteDebug
{
public class DebugRoute : Route
{
static readonly DebugRoute singleton = new DebugRoute();

public static DebugRoute Singleton {
public static DebugRoute Singleton
{
get { return singleton; }
}

Expand Down
11 changes: 7 additions & 4 deletions src/RouteDebug/DebugRouteHandler.cs
@@ -1,10 +1,13 @@
using System.Web;
using System.Web.Routing;

namespace RouteDebug {
public class DebugRouteHandler : IRouteHandler {
public IHttpHandler GetHttpHandler(RequestContext requestContext) {
return new DebugHttpHandler { };
namespace RouteDebug
{
public class DebugRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new DebugHttpHandler();
}
}
}
23 changes: 15 additions & 8 deletions src/RouteDebug/RouteDebuggerHttpModule.cs
Expand Up @@ -2,26 +2,33 @@
using System.Web;
using System.Web.Routing;

namespace RouteDebug {
public class RouteDebuggerHttpModule : IHttpModule {
public void Init(HttpApplication context) {
namespace RouteDebug
{
public class RouteDebuggerHttpModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.EndRequest += OnEndRequest;
context.BeginRequest += new System.EventHandler(context_BeginRequest);
context.BeginRequest += OnBeginRequest;
}

void context_BeginRequest(object sender, System.EventArgs e) {
if (RouteTable.Routes.Last() != DebugRoute.Singleton) {
static void OnBeginRequest(object sender, System.EventArgs e)
{
if (RouteTable.Routes.Last() != DebugRoute.Singleton)
{
RouteTable.Routes.Add(DebugRoute.Singleton);
}
}

void OnEndRequest(object sender, System.EventArgs e) {
static void OnEndRequest(object sender, System.EventArgs e)
{
var handler = new DebugHttpHandler();

handler.ProcessRequest(HttpContext.Current);
}

public void Dispose() {
public void Dispose()
{
}
}
}
37 changes: 23 additions & 14 deletions src/RouteMagic.Mvc/MvcRouteExtensions.cs
Expand Up @@ -5,24 +5,28 @@
using System.Web.Routing;
using RouteMagic.Internals;

namespace RouteMagic {
public static class MvcRouteExtenstions {

namespace RouteMagic
{
public static class MvcRouteExtenstions
{
// The Map methods map to the MvcRouteHandler

public static Route Map(this RouteCollection routes, string name, string url) {
public static Route Map(this RouteCollection routes, string name, string url)
{
return routes.Map(name, url, null, null, null);
}

public static Route Map(this RouteCollection routes, string name, string url, object defaults) {
public static Route Map(this RouteCollection routes, string name, string url, object defaults)
{
return routes.Map(name, url, defaults, null, null);
}

public static Route Map(this RouteCollection routes, string name, string url, object defaults, object constraints) {
public static Route Map(this RouteCollection routes, string name, string url, object defaults, object constraints)
{
return routes.Map(name, url, defaults, constraints, null);
}

public static Route Map(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces) {
public static Route Map(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces)
{
var route = routes.MapRoute(name, url, defaults, constraints, namespaces);
route.SetRouteName(name);
var normalized = new NormalizeRoute(route);
Expand All @@ -32,24 +36,29 @@ public static class MvcRouteExtenstions {
return route;
}

public static IHtmlString HandlerLink(this HtmlHelper htmlHelper, string linkText, string routeName) {
public static IHtmlString HandlerLink(this HtmlHelper htmlHelper, string linkText, string routeName)
{
return htmlHelper.HandlerLink(linkText, routeName, routeValues: null, htmlAttributes: null);
}

public static IHtmlString HandlerLink(this HtmlHelper htmlHelper, string linkText, string routeName, object routeValues, object htmlAttributes) {
RouteValueDictionary routeValueDictionary = routeValues as RouteValueDictionary ?? new RouteValueDictionary(routeValues);
public static IHtmlString HandlerLink(this HtmlHelper htmlHelper, string linkText, string routeName, object routeValues, object htmlAttributes)
{
var routeValueDictionary = routeValues as RouteValueDictionary ?? new RouteValueDictionary(routeValues);
IDictionary<string, object> attributes = null;
if (htmlAttributes != null) {
if (htmlAttributes != null)
{
attributes = htmlAttributes as IDictionary<string, object> ?? new RouteValueDictionary(htmlAttributes);
}
return htmlHelper.RouteLink(linkText, routeName, routeValueDictionary, attributes);
}

public static string HandlerUrl(this UrlHelper urlHelper, string name) {
public static string HandlerUrl(this UrlHelper urlHelper, string name)
{
return urlHelper.HandlerUrl(name, routeValues: null);
}

public static string HandlerUrl(this UrlHelper urlHelper, string routeName, object routeValues) {
public static string HandlerUrl(this UrlHelper urlHelper, string routeName, object routeValues)
{
var routeValueDictionary = new RouteValueDictionary(routeValues);
routeValueDictionary.SetRouteName(routeName);
return urlHelper.RouteUrl(routeName, routeValues);
Expand Down
@@ -1,9 +1,13 @@
using System.Web;
using System.Web.Mvc;

namespace RouteMagic.RouteHandlers {
public class DependencyResolvingRouteHandler<THandler> : HttpHandlerRouteHandler<THandler> where THandler : IHttpHandler {
public DependencyResolvingRouteHandler() : base(requestContext => DependencyResolver.Current.GetService<THandler>()) {
namespace RouteMagic.RouteHandlers
{
public class DependencyResolvingRouteHandler<THandler> : HttpHandlerRouteHandler<THandler> where THandler : IHttpHandler
{
public DependencyResolvingRouteHandler()
: base(requestContext => DependencyResolver.Current.GetService<THandler>())
{
}
}
}
47 changes: 30 additions & 17 deletions src/RouteMagic/GroupRoute.cs
Expand Up @@ -3,26 +3,33 @@
using System.Web.Routing;
using RouteMagic.Internals;

namespace RouteMagic {
public class GroupRoute : RouteBase {
private const string ApplicationRootPath = "~/";
private string _path = null;
private IVirtualPathResolver _virtualPathResolver;
namespace RouteMagic
{
public class GroupRoute : RouteBase
{
const string ApplicationRootPath = "~/";
readonly string _path;
readonly IVirtualPathResolver _virtualPathResolver;

public GroupRoute(RouteCollection childRoutes)
: this(ApplicationRootPath, childRoutes, null) {
: this(ApplicationRootPath, childRoutes, null)
{
}

public GroupRoute(RouteCollection childRoutes, IVirtualPathResolver virtualPathResolver)
: this(ApplicationRootPath, childRoutes, virtualPathResolver) {
: this(ApplicationRootPath, childRoutes, virtualPathResolver)
{
}

public GroupRoute(string directoryPath, RouteCollection childRoutes)
: this(directoryPath, childRoutes, null) {
: this(directoryPath, childRoutes, null)
{
}

public GroupRoute(string directoryPath, RouteCollection childRoutes, IVirtualPathResolver virtualPathResolver) {
if (!directoryPath.StartsWith("~/")) {
public GroupRoute(string directoryPath, RouteCollection childRoutes, IVirtualPathResolver virtualPathResolver)
{
if (!directoryPath.StartsWith("~/"))
{
throw new ArgumentException("Directory Path must start with '~/'", "directoryPath");
}
_virtualPathResolver = virtualPathResolver ?? VirtualPathResolver.Instance;
Expand All @@ -32,18 +39,22 @@ public GroupRoute(string directoryPath, RouteCollection childRoutes)

}

public string VirtualPath {
public string VirtualPath
{
get;
private set;
}

public RouteCollection ChildRoutes {
public RouteCollection ChildRoutes
{
get;
private set;
}

public override RouteData GetRouteData(HttpContextBase httpContext) {
if (!httpContext.Request.AppRelativeCurrentExecutionFilePath.StartsWith(VirtualPath, StringComparison.OrdinalIgnoreCase)) {
public override RouteData GetRouteData(HttpContextBase httpContext)
{
if (!httpContext.Request.AppRelativeCurrentExecutionFilePath.StartsWith(VirtualPath, StringComparison.OrdinalIgnoreCase))
{
return null;
}
// some trickery here to strip off DirectoryPath from the Request URL in httpContext if needed
Expand All @@ -52,11 +63,13 @@ public GroupRoute(string directoryPath, RouteCollection childRoutes)
return ChildRoutes.GetRouteData(childHttpContext ?? httpContext);
}

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) {
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
string routeName = values.GetRouteName();

var virtualPath = ChildRoutes.GetVirtualPath(requestContext, routeName as string, values.WithoutRouteName());
if (virtualPath != null) {
var virtualPath = ChildRoutes.GetVirtualPath(requestContext, routeName, values.WithoutRouteName());
if (virtualPath != null)
{
string rewrittenVirtualPath = virtualPath.VirtualPath.WithoutApplicationPath(requestContext);
string directoryPath = VirtualPath.WithoutTildePrefix(); // remove tilde
rewrittenVirtualPath = rewrittenVirtualPath.Insert(0, directoryPath.WithoutTrailingSlash());
Expand Down
25 changes: 16 additions & 9 deletions src/RouteMagic/HttpHandlers/DelegateHttpHandler.cs
Expand Up @@ -2,16 +2,21 @@
using System.Web;
using System.Web.Routing;

namespace RouteMagic.HttpHandlers {
public class DelegateHttpHandler : IHttpHandler {
private Action<RequestContext> _action;
private RouteData _routeData;
namespace RouteMagic.HttpHandlers
{
public class DelegateHttpHandler : IHttpHandler
{
readonly Action<RequestContext> _action;
readonly RouteData _routeData;

public DelegateHttpHandler(Action<RequestContext> action, RouteData routeData, bool isReusable) {
if (action == null) {
public DelegateHttpHandler(Action<RequestContext> action, RouteData routeData, bool isReusable)
{
if (action == null)
{
throw new ArgumentNullException("action");
}
if (routeData == null) {
if (routeData == null)
{
throw new ArgumentNullException("routeData");
}

Expand All @@ -20,12 +25,14 @@ public class DelegateHttpHandler : IHttpHandler {
_routeData = routeData;
}

public bool IsReusable {
public bool IsReusable
{
get;
private set;
}

public void ProcessRequest(HttpContext context) {
public void ProcessRequest(HttpContext context)
{
_action(new RequestContext(new HttpContextWrapper(context), _routeData));
}
}
Expand Down

0 comments on commit 5b6f31b

Please sign in to comment.