Web.Routing - refactor & resharp

This commit is contained in:
Stephan
2013-02-28 20:20:40 -01:00
parent c637c517b8
commit 85e73df3c8
2 changed files with 49 additions and 65 deletions

View File

@@ -1,22 +1,9 @@
using System;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using System.Xml;
using System.Globalization;
using System.Diagnostics;
// legacy
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.NodeFactory;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.member;
using umbraco.interfaces;
namespace Umbraco.Web.Routing
{
@@ -37,7 +24,7 @@ namespace Umbraco.Web.Routing
// the engine that does all the processing
// because in order to keep things clean and separated,
// the content request is just a data holder
private PublishedContentRequestEngine _engine;
private readonly PublishedContentRequestEngine _engine;
/// <summary>
/// Initializes a new instance of the <see cref="PublishedContentRequest"/> class with a specific Uri and routing context.
@@ -49,12 +36,12 @@ namespace Umbraco.Web.Routing
if (uri == null) throw new ArgumentNullException("uri");
if (routingContext == null) throw new ArgumentNullException("routingContext");
this.Uri = uri;
this.RoutingContext = routingContext;
Uri = uri;
RoutingContext = routingContext;
_engine = new PublishedContentRequestEngine(this);
this.RenderingEngine = RenderingEngine.Unknown;
RenderingEngine = RenderingEngine.Unknown;
}
/// <summary>
@@ -95,22 +82,17 @@ namespace Umbraco.Web.Routing
#region PublishedContent
/// <summary>
/// The identifier of the requested IPublishedContent, if any, else zero.
/// </summary>
private int _publishedContentId = 0;
/// <summary>
/// The requested IPublishedContent, if any, else <c>null</c>.
/// </summary>
private IPublishedContent _publishedContent = null;
private IPublishedContent _publishedContent;
/// <summary>
/// The initial requested IPublishedContent, if any, else <c>null</c>.
/// </summary>
/// <remarks>The initial requested content is the content that was found by the finders,
/// before anything such as 404, redirect... took place.</remarks>
private IPublishedContent _initialPublishedContent = null;
private IPublishedContent _initialPublishedContent;
/// <summary>
/// Gets or sets the requested content.
@@ -122,8 +104,7 @@ namespace Umbraco.Web.Routing
set
{
_publishedContent = value;
this.TemplateModel = null;
_publishedContentId = _publishedContent != null ? _publishedContent.Id : 0;
TemplateModel = null;
}
}
@@ -135,20 +116,31 @@ namespace Umbraco.Web.Routing
public IPublishedContent InitialPublishedContent { get { return _initialPublishedContent; } }
/// <summary>
/// Gets or sets a value indicating whether the current published content is the initial one.
/// Gets value indicating whether the current published content is the initial one.
/// </summary>
public bool IsInitialPublishedContent
{
get { return _initialPublishedContent != null && _initialPublishedContent == _publishedContent; }
set { _initialPublishedContent = _publishedContent; }
get
{
return _initialPublishedContent != null && _initialPublishedContent == _publishedContent;
}
}
/// <summary>
/// Indicates that the current PublishedContent is the initial one.
/// </summary>
public void SetIsInitialPublishedContent()
{
// note: it can very well be null if the initial content was not found
_initialPublishedContent = _publishedContent;
}
/// <summary>
/// Gets a value indicating whether the content request has a content.
/// </summary>
public bool HasPublishedContent
{
get { return this.PublishedContent != null; }
get { return PublishedContent != null; }
}
#endregion
@@ -173,10 +165,10 @@ namespace Umbraco.Web.Routing
set
{
_template = value;
this.RenderingEngine = RenderingEngine.Unknown; // reset
RenderingEngine = RenderingEngine.Unknown; // reset
if (_template != null)
this.RenderingEngine = _engine.FindTemplateRenderingEngine(_template.Alias);
RenderingEngine = _engine.FindTemplateRenderingEngine(_template.Alias);
}
}
@@ -204,25 +196,19 @@ namespace Umbraco.Web.Routing
{
if (string.IsNullOrWhiteSpace(alias))
{
this.TemplateModel = null;
TemplateModel = null;
return true;
}
else
{
// NOTE - can we stil get it with whitespaces in it due to old legacy bugs?
alias = alias.Replace(" ", "");
var model = ApplicationContext.Current.Services.FileService.GetTemplate(alias);
if (model == null)
{
return false;
}
else
{
this.TemplateModel = model;
return true;
}
}
// NOTE - can we stil get it with whitespaces in it due to old legacy bugs?
alias = alias.Replace(" ", "");
var model = ApplicationContext.Current.Services.FileService.GetTemplate(alias);
if (model == null)
return false;
TemplateModel = model;
return true;
}
/// <summary>
@@ -253,7 +239,7 @@ namespace Umbraco.Web.Routing
/// </summary>
public bool HasDomain
{
get { return this.Domain != null; }
get { return Domain != null; }
}
/// <summary>
@@ -261,8 +247,8 @@ namespace Umbraco.Web.Routing
/// </summary>
public CultureInfo Culture { get; set; }
// TODO: fixme - do we want to have an ordered list of alternate cultures,
// to allow for fallbacks when doing dictionnary lookup and such?
// note: do we want to have an ordered list of alternate cultures,
// to allow for fallbacks when doing dictionnary lookup and such?
#endregion
@@ -318,13 +304,13 @@ namespace Umbraco.Web.Routing
/// where we want to allow developers to indicate a request is 404 but not to cancel it.</remarks>
public void SetIs404()
{
this.Is404 = true;
Is404 = true;
}
/// <summary>
/// Gets a value indicating whether the content request triggers a redirect (permanent or not).
/// </summary>
public bool IsRedirect { get { return !string.IsNullOrWhiteSpace(this.RedirectUrl); } }
public bool IsRedirect { get { return !string.IsNullOrWhiteSpace(RedirectUrl); } }
/// <summary>
/// Gets or sets a value indicating whether the redirect is permanent.

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Globalization;
using System.IO;
@@ -13,15 +11,14 @@ using Umbraco.Core.Logging;
using umbraco;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.language;
using umbraco.cms.businesslogic.template;
using umbraco.cms.businesslogic.member;
namespace Umbraco.Web.Routing
{
internal class PublishedContentRequestEngine
{
private PublishedContentRequest _pcr;
private RoutingContext _routingContext;
private readonly PublishedContentRequest _pcr;
private readonly RoutingContext _routingContext;
/// <summary>
/// Initializes a new instance of the <see cref="PublishedContentRequestEngine"/> class with a content request.
@@ -342,7 +339,7 @@ namespace Umbraco.Web.Routing
// indicate that the published content (if any) we have at the moment is the
// one that was found by the standard finders before anything else took place.
_pcr.IsInitialPublishedContent = true;
_pcr.SetIsInitialPublishedContent();
}
/// <summary>
@@ -382,8 +379,9 @@ namespace Umbraco.Web.Routing
// follow internal redirects as long as it's not running out of control ie infinite loop of some sort
j = 0;
while (FollowInternalRedirects() && j++ < maxLoop) ;
if (j == maxLoop) // we're running out of control
while (FollowInternalRedirects() && j++ < maxLoop)
{ }
if (j == maxLoop) // we're running out of control
break;
// ensure access
@@ -447,8 +445,8 @@ namespace Umbraco.Web.Routing
// redirect to another page
var node = _routingContext.PublishedContentStore.GetDocumentById(_routingContext.UmbracoContext, internalRedirectId);
_pcr.PublishedContent = node;
if (node != null)
_pcr.PublishedContent = node;
if (node != null)
{
redirect = true;
LogHelper.Debug<PublishedContentRequestEngine>("{0}Redirecting to id={1}", () => tracePrefix, () => internalRedirectId);
@@ -535,8 +533,8 @@ namespace Umbraco.Web.Routing
// read the alternate template alias, from querystring, form, cookie or server vars,
// only if the published content is the initial once, else the alternate template
// does not apply
string altTemplate = _pcr.IsInitialPublishedContent
? _routingContext.UmbracoContext.HttpContext.Request["altTemplate"]
string altTemplate = _pcr.IsInitialPublishedContent
? _routingContext.UmbracoContext.HttpContext.Request["altTemplate"]
: null;
if (string.IsNullOrWhiteSpace(altTemplate))