From 1b9e226f610f24315dba3a0f5cf06f08d9ed8c94 Mon Sep 17 00:00:00 2001
From: "shannon@ShandemVaio"
Date: Fri, 20 Jul 2012 22:02:28 +0600
Subject: [PATCH 1/8] Moves app initialization into new UmbracoApplication
(global.asax)
---
src/Umbraco.Core/ApplicationContext.cs | 29 +++-------
src/Umbraco.Web.UI/Global.asax | 1 +
src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 1 +
src/Umbraco.Web/Umbraco.Web.csproj | 1 +
src/Umbraco.Web/UmbracoApplication.cs | 50 +++++++++++++++++
src/Umbraco.Web/UmbracoModule.cs | 68 ++++--------------------
6 files changed, 69 insertions(+), 81 deletions(-)
create mode 100644 src/Umbraco.Web.UI/Global.asax
create mode 100644 src/Umbraco.Web/UmbracoApplication.cs
diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs
index 4f1e449a20..1f39c1b9ee 100644
--- a/src/Umbraco.Core/ApplicationContext.cs
+++ b/src/Umbraco.Core/ApplicationContext.cs
@@ -12,11 +12,7 @@ namespace Umbraco.Core
///
public class ApplicationContext
{
-
- private static ApplicationContext _instance;
- private static readonly object Locker = new object();
-
- ///
+ ///
/// Constructor
///
///
@@ -25,25 +21,12 @@ namespace Umbraco.Core
Plugins = pluginResolver;
}
- ///
- /// Singleton accessor
- ///
- public static ApplicationContext Current
- {
- get
- {
- return _instance;
- }
- set
- {
- lock (Locker)
- {
- _instance = value;
- }
- }
- }
+ ///
+ /// Singleton accessor
+ ///
+ public static ApplicationContext Current { get; set; }
- // IsReady is set to true by the boot manager once it has successfully booted
+ // IsReady is set to true by the boot manager once it has successfully booted
// note - the original umbraco module checks on content.Instance in umbraco.dll
// now, the boot task that setup the content store ensures that it is ready
bool _isReady = false;
diff --git a/src/Umbraco.Web.UI/Global.asax b/src/Umbraco.Web.UI/Global.asax
new file mode 100644
index 0000000000..1627b363bc
--- /dev/null
+++ b/src/Umbraco.Web.UI/Global.asax
@@ -0,0 +1 @@
+<%@ Application Codebehind="Global.asax.cs" Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %>
diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
index 6f4ac938d7..97a5a03c2b 100644
--- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
+++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
@@ -306,6 +306,7 @@
UI.xml
+
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 98d3136fef..a9174e4cfb 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -1759,6 +1759,7 @@
+
diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs
new file mode 100644
index 0000000000..635d873bf5
--- /dev/null
+++ b/src/Umbraco.Web/UmbracoApplication.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using Umbraco.Core;
+
+namespace Umbraco.Web
+{
+ ///
+ /// The Umbraco global.asax class
+ ///
+ public class UmbracoApplication : System.Web.HttpApplication
+ {
+
+ private static readonly TraceSource Trace = new TraceSource("UmbracoApplication");
+
+ ///
+ /// Initializes the Umbraco application
+ ///
+ ///
+ ///
+ protected virtual void Application_Start(object sender, EventArgs e)
+ {
+ Trace.TraceInformation("Initialize AppDomain");
+
+ // Backwards compatibility - set the path and URL type for ClientDependency 1.5.1 [LK]
+ ClientDependency.Core.CompositeFiles.Providers.XmlFileMapper.FileMapVirtualFolder = "~/App_Data/TEMP/ClientDependency";
+ ClientDependency.Core.CompositeFiles.Providers.BaseCompositeFileProcessingProvider.UrlTypeDefault = ClientDependency.Core.CompositeFiles.Providers.CompositeUrlType.Base64QueryStrings;
+
+ //create the ApplicationContext
+ ApplicationContext.Current = new ApplicationContext(new PluginResolver())
+ {
+ IsReady = true // fixme
+ };
+
+ Trace.TraceInformation("AppDomain is initialized");
+ }
+
+ protected virtual void Application_Error(object sender, EventArgs e)
+ {
+
+ }
+
+ protected virtual void Application_End(object sender, EventArgs e)
+ {
+
+ }
+ }
+}
diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs
index fd978332ba..d4b2ba0d35 100644
--- a/src/Umbraco.Web/UmbracoModule.cs
+++ b/src/Umbraco.Web/UmbracoModule.cs
@@ -302,7 +302,16 @@ namespace Umbraco.Web
// and there may be more than 1 application per application domain
public void Init(HttpApplication app)
{
- InitializeApplication(app);
+ // used to be done in PostAuthorizeRequest but then it disabled OutputCaching due
+ // to rewriting happening too early in the chain (Alex Norcliffe 2010-02).
+ app.PostResolveRequestCache += (sender, e) =>
+ {
+ HttpContext httpContext = ((HttpApplication)sender).Context;
+ ProcessRequest(httpContext);
+ };
+
+ // todo: initialize request errors handler
+ // todo: initialize XML cache flush
}
public void Dispose()
@@ -310,62 +319,5 @@ namespace Umbraco.Web
#endregion
- #region Initialize
-
- private static volatile bool _appDomainInitialized = false;
- static readonly object AppDomainLock = new object();
-
- ///
- /// Initializes the application one time only
- ///
- void InitializeDomain()
- {
- if (!_appDomainInitialized)
- {
- lock (AppDomainLock)
- {
- if (!_appDomainInitialized)
- {
- Trace.TraceInformation("Initialize AppDomain");
-
- //create the ApplicationContext
- ApplicationContext.Current = new ApplicationContext(new PluginResolver());
-
- //TODO: Why is this necessary? if the ApplicationContext is null, then its not ready
- ApplicationContext.Current.IsReady = true; // fixme
-
- // Backwards compatibility - set the path and URL type for ClientDependency 1.5.1 [LK]
- ClientDependency.Core.CompositeFiles.Providers.XmlFileMapper.FileMapVirtualFolder = "~/App_Data/TEMP/ClientDependency";
- ClientDependency.Core.CompositeFiles.Providers.BaseCompositeFileProcessingProvider.UrlTypeDefault = ClientDependency.Core.CompositeFiles.Providers.CompositeUrlType.Base64QueryStrings;
-
- _appDomainInitialized = true;
- }
- Trace.TraceInformation("AppDomain is initialized");
- }
- }
- }
-
- void InitializeApplication(HttpApplication app)
- {
- // we can't do in in module.Init because we need HttpContext.
- app.BeginRequest += (sender, e) =>
- {
- Trace.TraceInformation("Welcome to Umbraco!");
- InitializeDomain();
- };
-
- // used to be done in PostAuthorizeRequest but then it disabled OutputCaching due
- // to rewriting happening too early in the chain (Alex Norcliffe 2010-02).
- app.PostResolveRequestCache += (sender, e) =>
- {
- HttpContext httpContext = ((HttpApplication)sender).Context;
- ProcessRequest(httpContext);
- };
-
- // todo: initialize request errors handler
- // todo: initialize XML cache flush
- }
-
- #endregion
}
}
From 6c872e8a651eac478f338be7bfeffa3ca754fdd2 Mon Sep 17 00:00:00 2001
From: "shannon@ShandemVaio"
Date: Fri, 20 Jul 2012 23:10:43 +0600
Subject: [PATCH 2/8] Implements singly registered RoutesCache object and
re-interfaces IRoutesCache which can now be set at runtime. Exposes
UmbracoContext via DocumentRequest which simplifies some things. Removes
dependency on UmbracoContext from DefaultRoutesCache, now InPreviewMode is
checked before passing processing to the IRoutesCache provider. Changed
NiceUrls to NiceUrlResolver.
---
src/Umbraco.Web/ContentStore.cs | 9 +-
.../{NiceUrls.cs => NiceUrlResolver.cs} | 24 +++-
src/Umbraco.Web/Routing/DefaultRoutesCache.cs | 72 +++++++++++
src/Umbraco.Web/Routing/DocumentRequest.cs | 42 +++---
src/Umbraco.Web/Routing/IRoutesCache.cs | 11 ++
src/Umbraco.Web/Routing/LookupByPath.cs | 18 ++-
.../Routing/LookupByPathWithTemplate.cs | 2 +-
src/Umbraco.Web/Routing/LookupByProfile.cs | 2 +-
src/Umbraco.Web/Routing/RoutesCache.cs | 120 +++++++-----------
src/Umbraco.Web/Routing/RoutingEnvironment.cs | 17 +--
src/Umbraco.Web/Umbraco.Web.csproj | 4 +-
src/Umbraco.Web/UmbracoContext.cs | 36 ++----
src/Umbraco.Web/UmbracoModule.cs | 16 ++-
13 files changed, 228 insertions(+), 145 deletions(-)
rename src/Umbraco.Web/{NiceUrls.cs => NiceUrlResolver.cs} (86%)
create mode 100644 src/Umbraco.Web/Routing/DefaultRoutesCache.cs
create mode 100644 src/Umbraco.Web/Routing/IRoutesCache.cs
diff --git a/src/Umbraco.Web/ContentStore.cs b/src/Umbraco.Web/ContentStore.cs
index d123342f22..e13714c9ac 100644
--- a/src/Umbraco.Web/ContentStore.cs
+++ b/src/Umbraco.Web/ContentStore.cs
@@ -12,8 +12,15 @@ namespace Umbraco.Web
///
internal class ContentStore
{
- private readonly UmbracoContext _umbracoContext;
+ ///
+ /// Delegate to return the current UmbracoContext
+ ///
+ private readonly UmbracoContext _umbracoContext;
+ ///
+ /// Constructor accepting a delegate to resolve the UmbracoContext
+ ///
+ ///
public ContentStore(UmbracoContext umbracoContext)
{
_umbracoContext = umbracoContext;
diff --git a/src/Umbraco.Web/NiceUrls.cs b/src/Umbraco.Web/NiceUrlResolver.cs
similarity index 86%
rename from src/Umbraco.Web/NiceUrls.cs
rename to src/Umbraco.Web/NiceUrlResolver.cs
index ae2ff6cf70..1e7da3b26e 100644
--- a/src/Umbraco.Web/NiceUrls.cs
+++ b/src/Umbraco.Web/NiceUrlResolver.cs
@@ -7,9 +7,12 @@ using umbraco.cms.businesslogic.web;
namespace Umbraco.Web
{
- internal class NiceUrls
+ ///
+ /// Resolves NiceUrls for a given node id
+ ///
+ internal class NiceUrlResolver
{
- public NiceUrls(ContentStore contentStore, UmbracoContext umbracoContext, RoutesCache routesCache)
+ public NiceUrlResolver(ContentStore contentStore, UmbracoContext umbracoContext, IRoutesCache routesCache)
{
_umbracoContext = umbracoContext;
_contentStore = contentStore;
@@ -18,7 +21,7 @@ namespace Umbraco.Web
private readonly UmbracoContext _umbracoContext;
private readonly ContentStore _contentStore;
- private readonly RoutesCache _routesCache;
+ private readonly IRoutesCache _routesCache;
// note: this could be a parameter...
const string UrlNameProperty = "@urlName";
@@ -34,10 +37,13 @@ namespace Umbraco.Web
public virtual string GetNiceUrl(int nodeId, int startNodeDepth, bool forceDomain)
{
- string route;
- string path;
+ string path;
+
+ // will not read cache if previewing!
+ var route = !_umbracoContext.InPreviewMode
+ ? _routesCache.GetRoute(nodeId)
+ : null;
- route = _routesCache.GetRoute(nodeId); // will not read cache if previewing
if (route != null)
{
int pos = route.IndexOf('/');
@@ -85,7 +91,11 @@ namespace Umbraco.Web
parts.Reverse();
path = "/" + string.Join("/", parts);
route = string.Format("{0}{1}", id, path);
- _routesCache.Store(nodeId, route); // will not write if previewing
+
+ if (!_umbracoContext.InPreviewMode)
+ {
+ _routesCache.Store(nodeId, route); // will not write if previewing
+ }
return FormatUrl(domain, path);
}
diff --git a/src/Umbraco.Web/Routing/DefaultRoutesCache.cs b/src/Umbraco.Web/Routing/DefaultRoutesCache.cs
new file mode 100644
index 0000000000..a755e9c489
--- /dev/null
+++ b/src/Umbraco.Web/Routing/DefaultRoutesCache.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+
+namespace Umbraco.Web.Routing
+{
+ ///
+ /// The default implementation of IRoutesCache
+ ///
+ internal class DefaultRoutesCache : IRoutesCache
+ {
+ private readonly object _lock = new object();
+ private Dictionary _routes;
+ private Dictionary _nodeIds;
+
+ public DefaultRoutesCache()
+ {
+ Clear();
+
+ // here we should register handlers to clear the cache when content changes
+ // at the moment this is done by library, which clears everything when content changed
+ //
+ // but really, we should do some partial refreshes!
+ // otherwise, we could even cache 404 errors...
+ }
+
+ public void Store(int nodeId, string route)
+ {
+ lock (_lock)
+ {
+ _routes[nodeId] = route;
+ _nodeIds[route] = nodeId;
+ }
+ }
+
+ public string GetRoute(int nodeId)
+ {
+ lock (_lock)
+ {
+ return _routes.ContainsKey(nodeId) ? _routes[nodeId] : null;
+ }
+ }
+
+ public int GetNodeId(string route)
+ {
+ lock (_lock)
+ {
+ return _nodeIds.ContainsKey(route) ? _nodeIds[route] : 0;
+ }
+ }
+
+ public void ClearNode(int nodeId)
+ {
+ lock (_lock)
+ {
+ if (_routes.ContainsKey(nodeId))
+ {
+ _nodeIds.Remove(_routes[nodeId]);
+ _routes.Remove(nodeId);
+ }
+ }
+ }
+
+ public void Clear()
+ {
+ lock (_lock)
+ {
+ _routes = new Dictionary();
+ _nodeIds = new Dictionary();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Routing/DocumentRequest.cs b/src/Umbraco.Web/Routing/DocumentRequest.cs
index efa44a1881..65844d84c8 100644
--- a/src/Umbraco.Web/Routing/DocumentRequest.cs
+++ b/src/Umbraco.Web/Routing/DocumentRequest.cs
@@ -16,12 +16,12 @@ namespace Umbraco.Web.Routing
{
static readonly TraceSource Trace = new TraceSource("DocumentRequest");
- public DocumentRequest(Uri uri, RoutingEnvironment lookups, UmbracoContext umbracoContext, NiceUrls niceUrls)
+ public DocumentRequest(Uri uri, RoutingEnvironment lookups, UmbracoContext umbracoContext, NiceUrlResolver niceUrlResolver)
{
// register lookups
_environment = lookups;
- _umbracoContext = umbracoContext;
- _niceUrls = niceUrls;
+ UmbracoContext = umbracoContext;
+ _niceUrlResolver = niceUrlResolver;
// prepare the host
var host = uri.Host;
@@ -55,13 +55,25 @@ namespace Umbraco.Web.Routing
this.QueryString = uri.Query.TrimStart('?');
}
+ readonly RoutingEnvironment _environment;
+ private readonly NiceUrlResolver _niceUrlResolver;
+
+ ///
+ /// the id of the requested node, if any, else zero.
+ ///
+ int _nodeId = 0;
+
+ ///
+ /// the requested node, if any, else null.
+ ///
+ XmlNode _node = null;
+
#region Properties
- // the id of the requested node, if any, else zero.
- int _nodeId = 0;
-
- // the requested node, if any, else null.
- XmlNode _node = null;
+ ///
+ /// Returns the current UmbracoContext
+ ///
+ public UmbracoContext UmbracoContext { get; private set; }
///
/// Gets the request host name.
@@ -176,15 +188,9 @@ namespace Umbraco.Web.Routing
#region Resolve
- readonly RoutingEnvironment _environment;
- private readonly UmbracoContext _umbracoContext;
- private readonly NiceUrls _niceUrls;
-
///
/// Determines the site root (if any) matching the http request.
- ///
- /// The host name part of the http request, eg. www.example.com.
- /// The url part of the http request, starting with a slash, eg. /foo/bar.
+ ///
/// A value indicating whether a domain was found.
public bool ResolveSiteRoot()
{
@@ -432,9 +438,9 @@ namespace Umbraco.Web.Routing
if (this.Node == null)
throw new InvalidOperationException("There is no node.");
- var templateAlias = _umbracoContext.HttpContext.Request.QueryString["altTemplate"];
+ var templateAlias = UmbracoContext.HttpContext.Request.QueryString["altTemplate"];
if (string.IsNullOrWhiteSpace(templateAlias))
- templateAlias = _umbracoContext.HttpContext.Request.Form["altTemplate"];
+ templateAlias = UmbracoContext.HttpContext.Request.Form["altTemplate"];
// fixme - we might want to support cookies?!? NO but provide a hook to change the template
@@ -488,7 +494,7 @@ namespace Umbraco.Web.Routing
redirectId = -1;
string redirectUrl = "#";
if (redirectId > 0)
- redirectUrl = _niceUrls.GetNiceUrl(redirectId);
+ redirectUrl = _niceUrlResolver.GetNiceUrl(redirectId);
if (redirectUrl != "#")
this.RedirectUrl = redirectUrl;
}
diff --git a/src/Umbraco.Web/Routing/IRoutesCache.cs b/src/Umbraco.Web/Routing/IRoutesCache.cs
new file mode 100644
index 0000000000..0f4a1044ec
--- /dev/null
+++ b/src/Umbraco.Web/Routing/IRoutesCache.cs
@@ -0,0 +1,11 @@
+namespace Umbraco.Web.Routing
+{
+ internal interface IRoutesCache
+ {
+ void Store(int nodeId, string route);
+ string GetRoute(int nodeId);
+ int GetNodeId(string route);
+ void ClearNode(int nodeId);
+ void Clear();
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Routing/LookupByPath.cs b/src/Umbraco.Web/Routing/LookupByPath.cs
index d5e9dbba19..30dc31f546 100644
--- a/src/Umbraco.Web/Routing/LookupByPath.cs
+++ b/src/Umbraco.Web/Routing/LookupByPath.cs
@@ -9,7 +9,7 @@ namespace Umbraco.Web.Routing
[LookupWeight(10)]
internal class LookupByPath : ILookup
{
- public LookupByPath(ContentStore contentStore, RoutesCache routesCache)
+ public LookupByPath(ContentStore contentStore, IRoutesCache routesCache)
{
ContentStore = contentStore;
RoutesCache = routesCache;
@@ -18,7 +18,7 @@ namespace Umbraco.Web.Routing
static readonly TraceSource Trace = new TraceSource("LookupByPath");
protected ContentStore ContentStore;
- protected RoutesCache RoutesCache;
+ protected IRoutesCache RoutesCache;
public virtual bool LookupDocument(DocumentRequest docreq)
{
@@ -31,7 +31,12 @@ namespace Umbraco.Web.Routing
{
Trace.TraceInformation("Test route \"{0}\"", route);
- var nodeId = RoutesCache.GetNodeId(route);
+ //return '0' if in preview mode!
+ var nodeId = !docreq.UmbracoContext.InPreviewMode
+ ? RoutesCache.GetNodeId(route)
+ : 0;
+
+
XmlNode node = null;
if (nodeId > 0)
{
@@ -55,7 +60,12 @@ namespace Umbraco.Web.Routing
{
docreq.Node = node;
Trace.TraceInformation("Query matches, id={0}", docreq.NodeId);
- RoutesCache.Store(docreq.NodeId, route);
+
+ if (!docreq.UmbracoContext.InPreviewMode)
+ {
+ RoutesCache.Store(docreq.NodeId, route); // will not write if previewing
+ }
+
}
else
{
diff --git a/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs b/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs
index 1b91be23aa..11454bcdb2 100644
--- a/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs
+++ b/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs
@@ -13,7 +13,7 @@ namespace Umbraco.Web.Routing
{
static readonly TraceSource Trace = new TraceSource("LookupByPathWithTemplate");
- public LookupByPathWithTemplate(ContentStore contentStore, RoutesCache routesCache)
+ public LookupByPathWithTemplate(ContentStore contentStore, IRoutesCache routesCache)
: base(contentStore, routesCache)
{
}
diff --git a/src/Umbraco.Web/Routing/LookupByProfile.cs b/src/Umbraco.Web/Routing/LookupByProfile.cs
index a65eafac2e..c3044349e7 100644
--- a/src/Umbraco.Web/Routing/LookupByProfile.cs
+++ b/src/Umbraco.Web/Routing/LookupByProfile.cs
@@ -18,7 +18,7 @@ namespace Umbraco.Web.Routing
static readonly TraceSource Trace = new TraceSource("LookupByProfile");
- public LookupByProfile(ContentStore contentStore, RoutesCache routesCache, UmbracoContext umbracoContext)
+ public LookupByProfile(ContentStore contentStore, IRoutesCache routesCache, UmbracoContext umbracoContext)
: base(contentStore, routesCache)
{
_umbracoContext = umbracoContext;
diff --git a/src/Umbraco.Web/Routing/RoutesCache.cs b/src/Umbraco.Web/Routing/RoutesCache.cs
index d366dc23f9..dcb7843e1b 100644
--- a/src/Umbraco.Web/Routing/RoutesCache.cs
+++ b/src/Umbraco.Web/Routing/RoutesCache.cs
@@ -1,81 +1,57 @@
-using System.Collections.Generic;
+using System;
namespace Umbraco.Web.Routing
{
- internal class RoutesCache
- {
- private readonly object _lock = new object();
- private Dictionary _routes;
- private Dictionary _nodeIds;
+ ///
+ /// A singly registered object to assign and get the current IRoutesCache provider
+ ///
+ internal class RoutesCache
+ {
+ private static readonly RoutesCache Instance = new RoutesCache();
+ private static IRoutesCache _provider;
- private readonly UmbracoContext _umbracoContext;
+ ///
+ /// public contructor assigns the DefaultRoutesCache as the default provider
+ ///
+ public RoutesCache()
+ :this(null)
+ {
+ }
- public RoutesCache(UmbracoContext umbracoContext)
- {
- _umbracoContext = umbracoContext;
+ ///
+ /// Constructor sets a custom provider if specified
+ ///
+ ///
+ internal RoutesCache(IRoutesCache provider)
+ {
+ _provider = provider ?? new DefaultRoutesCache();
+ }
- Clear();
+ ///
+ /// Set the routes cache provider
+ ///
+ ///
+ public static void SetProvider(IRoutesCache provider)
+ {
+ if (provider == null) throw new ArgumentNullException("provider");
+ _provider = provider;
+ }
- // here we should register handlers to clear the cache when content changes
- // at the moment this is done by library, which clears everything when content changed
- //
- // but really, we should do some partial refreshes!
- // otherwise, we could even cache 404 errors...
- }
+ ///
+ /// Singleton accessor
+ ///
+ public static RoutesCache Current
+ {
+ get { return Instance; }
+ }
- public void Store(int nodeId, string route)
- {
- if (_umbracoContext.InPreviewMode)
- return;
-
- lock (_lock)
- {
- _routes[nodeId] = route;
- _nodeIds[route] = nodeId;
- }
- }
-
- public string GetRoute(int nodeId)
- {
- if (_umbracoContext.InPreviewMode)
- return null;
-
- lock (_lock)
- {
- return _routes.ContainsKey(nodeId) ? _routes[nodeId] : null;
- }
- }
-
- public int GetNodeId(string route)
- {
- if (_umbracoContext.InPreviewMode)
- return 0;
-
- lock (_lock)
- {
- return _nodeIds.ContainsKey(route) ? _nodeIds[route] : 0;
- }
- }
-
- public void ClearNode(int nodeId)
- {
- lock (_lock)
- {
- if (_routes.ContainsKey(nodeId))
- {
- _nodeIds.Remove(_routes[nodeId]);
- _routes.Remove(nodeId);
- }
- }
- }
-
- public void Clear()
- {
- lock (_lock)
- {
- _routes = new Dictionary();
- _nodeIds = new Dictionary();
- }
- }
- }
+ ///
+ /// Get the current provider
+ ///
+ ///
+ public IRoutesCache GetProvider()
+ {
+ return _provider;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Routing/RoutingEnvironment.cs b/src/Umbraco.Web/Routing/RoutingEnvironment.cs
index cf848625be..0affeb6799 100644
--- a/src/Umbraco.Web/Routing/RoutingEnvironment.cs
+++ b/src/Umbraco.Web/Routing/RoutingEnvironment.cs
@@ -3,10 +3,11 @@ using System.Linq;
namespace Umbraco.Web.Routing
{
- // represents a request for one specified Umbraco document to be rendered
- // by one specified template, using one particular culture.
- //
-
+
+ ///
+ /// represents a request for one specified Umbraco document to be rendered by one specified template,
+ /// using one particular culture.
+ ///
internal class RoutingEnvironment
{
public RoutingEnvironment(
@@ -28,13 +29,9 @@ namespace Umbraco.Web.Routing
}).ToList();
}
- public IEnumerable Lookups
- {
- get;
- private set;
- }
+ public IEnumerable Lookups { get; private set; }
- public ILookupNotFound LookupNotFound { get; private set; }
+ public ILookupNotFound LookupNotFound { get; private set; }
public ContentStore ContentStore { get; private set; }
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index a9174e4cfb..b3ec0b677e 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -240,11 +240,12 @@
-
+
+
@@ -252,6 +253,7 @@
+
diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs
index 4992fa3e07..6d6729b7c7 100644
--- a/src/Umbraco.Web/UmbracoContext.cs
+++ b/src/Umbraco.Web/UmbracoContext.cs
@@ -49,7 +49,7 @@ namespace Umbraco.Web
///
/// Gets the current Umbraco Context.
///
- public static UmbracoContext Current
+ public static UmbracoContext Current
{
get
{
@@ -126,6 +126,16 @@ namespace Umbraco.Web
///
internal DocumentRequest DocumentRequest { get; set; }
+ ///
+ /// Gets/sets the NiceUrlResolver object
+ ///
+ internal NiceUrlResolver NiceUrlResolver { get; set; }
+
+ ///
+ /// Gets/sets the RoutingEnvironment object
+ ///
+ internal RoutingEnvironment RoutingEnvironment { get; set; }
+
///
/// Exposes the HttpContext for the current request
///
@@ -193,29 +203,7 @@ namespace Umbraco.Web
&& !currentUrl.StartsWith(IOHelper.ResolveUrl(SystemDirectories.Umbraco)); // is not in admin UI
}
}
-
- ///
- /// Gets the current Live Editing Context.
- ///
- public virtual ILiveEditingContext LiveEditingContext
- {
- get
- {
- //TODO: this should be done with a wrapper: http://issues.umbraco.org/issue/U4-61
- var value = (ILiveEditingContext)HttpContext.Items["LiveEditingContext"];
- if (value == null)
- {
- LiveEditingContext = value = new DefaultLiveEditingContext();
- }
- return value;
- }
-
- set
- {
- //TODO: this should be done with a wrapper: http://issues.umbraco.org/issue/U4-61
- HttpContext.Items["LiveEditingContext"] = value;
- }
- }
+
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs
index d4b2ba0d35..1087e61fe3 100644
--- a/src/Umbraco.Web/UmbracoModule.cs
+++ b/src/Umbraco.Web/UmbracoModule.cs
@@ -37,11 +37,9 @@ namespace Umbraco.Web
UmbracoContext.Current = umbracoContext;
//create a content store
- var contentStore = new ContentStore(umbracoContext);
- //create the routes cache
- var routesCache = new RoutesCache(umbracoContext);
+ var contentStore = new ContentStore(umbracoContext);
//create the nice urls
- var niceUrls = new NiceUrls(contentStore, umbracoContext, routesCache);
+ var niceUrls = new NiceUrlResolver(contentStore, umbracoContext, RoutesCache.Current.GetProvider());
//create the RoutingEnvironment (one per http request as it relies on the umbraco context!)
var routingEnvironment = new RoutingEnvironment(
ApplicationContext.Current.Plugins.ResolveLookups().ToArray(),
@@ -49,9 +47,15 @@ namespace Umbraco.Web
contentStore);
// create the new document request which will cleanup the uri once and for all
var docreq = new DocumentRequest(uri, routingEnvironment, umbracoContext, niceUrls);
-
- // initialize the document request on the UmbracoContext (this is circular dependency!!!)
+
+ //NOTE: we are putting these objects on the UmbracoContext because these might be handy for developers in the future to
+ // access if we make them public.
+ // initialize the DocumentRequest on the UmbracoContext (this is circular dependency!!!)
umbracoContext.DocumentRequest = docreq;
+ // initialize the RoutingEnvironment on the UmbracoContext (this is circular dependency!!!)
+ umbracoContext.RoutingEnvironment = routingEnvironment;
+ // initialize the RoutingEnvironment on the UmbracoContext (this is circular dependency!!!)
+ umbracoContext.NiceUrlResolver = niceUrls;
//create the LegacyRequestInitializer (one per http request as it relies on the umbraco context!)
var legacyRequestInitializer = new LegacyRequestInitializer(umbracoContext);
From 8f278bcaa52b31bee4bfbfe33c4b06e94278ecfd Mon Sep 17 00:00:00 2001
From: "shannon@ShandemVaio"
Date: Fri, 20 Jul 2012 23:42:55 +0600
Subject: [PATCH 3/8] Added singleton for managing ILookups collection, allows
for adding/removing/inserting at runtime/startup
---
src/Umbraco.Core/ApplicationContext.cs | 2 +-
src/Umbraco.Web/PluginResolverExtensions.cs | 2 +-
src/Umbraco.Web/Routing/DocumentRequest.cs | 3 +-
src/Umbraco.Web/Routing/RouteLookups.cs | 105 ++++++++++++++++++
src/Umbraco.Web/Routing/RoutingEnvironment.cs | 15 +--
src/Umbraco.Web/Umbraco.Web.csproj | 1 +
src/Umbraco.Web/UmbracoApplication.cs | 4 +
src/Umbraco.Web/UmbracoModule.cs | 2 +-
8 files changed, 118 insertions(+), 16 deletions(-)
create mode 100644 src/Umbraco.Web/Routing/RouteLookups.cs
diff --git a/src/Umbraco.Core/ApplicationContext.cs b/src/Umbraco.Core/ApplicationContext.cs
index 1f39c1b9ee..6d4892e911 100644
--- a/src/Umbraco.Core/ApplicationContext.cs
+++ b/src/Umbraco.Core/ApplicationContext.cs
@@ -24,7 +24,7 @@ namespace Umbraco.Core
///
/// Singleton accessor
///
- public static ApplicationContext Current { get; set; }
+ public static ApplicationContext Current { get; internal set; }
// IsReady is set to true by the boot manager once it has successfully booted
// note - the original umbraco module checks on content.Instance in umbraco.dll
diff --git a/src/Umbraco.Web/PluginResolverExtensions.cs b/src/Umbraco.Web/PluginResolverExtensions.cs
index fbbf81c853..102172f15f 100644
--- a/src/Umbraco.Web/PluginResolverExtensions.cs
+++ b/src/Umbraco.Web/PluginResolverExtensions.cs
@@ -7,7 +7,7 @@ using umbraco.BusinessLogic.Utils;
namespace Umbraco.Web
{
- ///
+ ///
/// Extension methods for the PluginResolver
///
public static class PluginResolverExtensions
diff --git a/src/Umbraco.Web/Routing/DocumentRequest.cs b/src/Umbraco.Web/Routing/DocumentRequest.cs
index 65844d84c8..bb51181849 100644
--- a/src/Umbraco.Web/Routing/DocumentRequest.cs
+++ b/src/Umbraco.Web/Routing/DocumentRequest.cs
@@ -251,7 +251,8 @@ namespace Umbraco.Web.Routing
// the first successful lookup, if any, will set this.Node, and may also set this.Template
// some lookups may implement caching
Trace.TraceInformation("{0}Begin lookup", tracePrefix);
- _environment.Lookups.Any(lookup => lookup.LookupDocument(this));
+ var lookups = _environment.RouteLookups.GetLookups();
+ lookups.Any(lookup => lookup.LookupDocument(this));
Trace.TraceInformation("{0}End lookup, {1}", tracePrefix, (this.HasNode ? "a document was found" : "no document was found"));
// fixme - not handling umbracoRedirect
diff --git a/src/Umbraco.Web/Routing/RouteLookups.cs b/src/Umbraco.Web/Routing/RouteLookups.cs
new file mode 100644
index 0000000000..9e6671c9e0
--- /dev/null
+++ b/src/Umbraco.Web/Routing/RouteLookups.cs
@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using Umbraco.Core;
+
+namespace Umbraco.Web.Routing
+{
+ ///
+ /// Represents a collection of ILookups used for routing that are registered in the application
+ ///
+ internal class RouteLookups
+ {
+ private static readonly List Lookups = new List();
+ private static readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();
+
+ ///
+ /// Singleton accessor
+ ///
+ public static RouteLookups Current { get; internal set; }
+
+ internal RouteLookups(IEnumerable lookups)
+ {
+ Lookups.AddRange(SortByWeight(lookups));
+ }
+
+ ///
+ /// Returns all of the lookups
+ ///
+ ///
+ public IEnumerable GetLookups()
+ {
+ return Lookups;
+ }
+
+ ///
+ /// Removes an ILookup based on the specified Type
+ ///
+ ///
+ public void RemoveLookup()
+ where T : ILookup
+ {
+ using (new WriteLock(Lock))
+ {
+ Lookups.Remove(Lookups.SingleOrDefault(x => x is T));
+ }
+ }
+
+ ///
+ /// Adds a new lookup to the end of the list
+ ///
+ ///
+ public void AddLookup(ILookup lookup)
+ {
+ if (CheckExists(lookup))
+ throw new InvalidOperationException("The lookup type " + lookup.GetType() + " already exists in the lookup collection");
+
+ using (new WriteLock(Lock))
+ {
+ Lookups.Add(lookup);
+ }
+ }
+
+ ///
+ /// Inserts a lookup at the specified index
+ ///
+ ///
+ ///
+ public void InsertLookup(int index, ILookup lookup)
+ {
+ if (CheckExists(lookup))
+ throw new InvalidOperationException("The lookup type " + lookup.GetType() + " already exists in the lookup collection");
+
+ using (new WriteLock(Lock))
+ {
+ Lookups.Insert(index, lookup);
+ }
+ }
+
+ ///
+ /// checks if a lookup already exists by type
+ ///
+ ///
+ ///
+ private static bool CheckExists(ILookup lookup)
+ {
+ return Lookups.Any(x => x.GetType() == lookup.GetType());
+ }
+
+ ///
+ /// Sorts the ILookups in the list based on an attribute weight if one is specified
+ ///
+ ///
+ ///
+ private static IEnumerable SortByWeight(IEnumerable lookups)
+ {
+ return lookups.OrderBy(x =>
+ {
+ var attribute = x.GetType().GetCustomAttributes(true).OfType().SingleOrDefault();
+ return attribute == null ? LookupWeightAttribute.DefaultWeight : attribute.Weight;
+ }).ToList();
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Routing/RoutingEnvironment.cs b/src/Umbraco.Web/Routing/RoutingEnvironment.cs
index 0affeb6799..0c5d770e86 100644
--- a/src/Umbraco.Web/Routing/RoutingEnvironment.cs
+++ b/src/Umbraco.Web/Routing/RoutingEnvironment.cs
@@ -11,25 +11,16 @@ namespace Umbraco.Web.Routing
internal class RoutingEnvironment
{
public RoutingEnvironment(
- IEnumerable lookups,
+ RouteLookups lookups,
ILookupNotFound lookupNotFound,
ContentStore contentStore)
{
- Lookups = SortByPartWeight(lookups);
+ RouteLookups = lookups;
LookupNotFound = lookupNotFound;
ContentStore = contentStore;
}
- private static IEnumerable SortByPartWeight(IEnumerable lookups)
- {
- return lookups.OrderBy(x =>
- {
- var attribute = x.GetType().GetCustomAttributes(true).OfType().SingleOrDefault();
- return attribute == null ? LookupWeightAttribute.DefaultWeight : attribute.Weight;
- }).ToList();
- }
-
- public IEnumerable Lookups { get; private set; }
+ public RouteLookups RouteLookups { get; private set; }
public ILookupNotFound LookupNotFound { get; private set; }
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index b3ec0b677e..3b5d82ee48 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -242,6 +242,7 @@
+
diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs
index 635d873bf5..5febadc78a 100644
--- a/src/Umbraco.Web/UmbracoApplication.cs
+++ b/src/Umbraco.Web/UmbracoApplication.cs
@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Linq;
using System.Text;
using Umbraco.Core;
+using Umbraco.Web.Routing;
namespace Umbraco.Web
{
@@ -34,6 +35,9 @@ namespace Umbraco.Web
IsReady = true // fixme
};
+ //create the route lookups singleton
+ RouteLookups.Current = new RouteLookups(ApplicationContext.Current.Plugins.ResolveLookups());
+
Trace.TraceInformation("AppDomain is initialized");
}
diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs
index 1087e61fe3..bcd976c8d3 100644
--- a/src/Umbraco.Web/UmbracoModule.cs
+++ b/src/Umbraco.Web/UmbracoModule.cs
@@ -42,7 +42,7 @@ namespace Umbraco.Web
var niceUrls = new NiceUrlResolver(contentStore, umbracoContext, RoutesCache.Current.GetProvider());
//create the RoutingEnvironment (one per http request as it relies on the umbraco context!)
var routingEnvironment = new RoutingEnvironment(
- ApplicationContext.Current.Plugins.ResolveLookups().ToArray(),
+ RouteLookups.Current,
new LookupFor404(contentStore),
contentStore);
// create the new document request which will cleanup the uri once and for all
From be51bfa67f0968acbb3d270b8a3cef05785c66c3 Mon Sep 17 00:00:00 2001
From: "shannon@ShandemVaio"
Date: Sat, 21 Jul 2012 00:20:50 +0600
Subject: [PATCH 4/8] Changed RoutingEnvironment to RoutingContet. Cleaned up
how the context reference each other, now this starts making a bunch of
sense. Have empty ctor's on all ILookups since their methods get passed a
DocumentRequest object which has access to all of the context's and
properties that they will ever need.
---
src/Umbraco.Web/NiceUrlResolver.cs | 8 +--
src/Umbraco.Web/PluginResolverExtensions.cs | 21 +------
src/Umbraco.Web/Routing/DocumentRequest.cs | 57 +++++++++++--------
src/Umbraco.Web/Routing/LookupByAlias.cs | 9 +--
src/Umbraco.Web/Routing/LookupById.cs | 19 +------
src/Umbraco.Web/Routing/LookupByPath.cs | 24 +++-----
.../Routing/LookupByPathWithTemplate.cs | 7 +--
src/Umbraco.Web/Routing/LookupByProfile.cs | 15 ++---
src/Umbraco.Web/Routing/LookupFor404.cs | 18 ++----
src/Umbraco.Web/Routing/RouteLookups.cs | 39 ++++++++-----
...outingEnvironment.cs => RoutingContext.cs} | 17 +++---
src/Umbraco.Web/Umbraco.Web.csproj | 2 +-
src/Umbraco.Web/UmbracoContext.cs | 33 +++++------
src/Umbraco.Web/UmbracoModule.cs | 29 +++++-----
14 files changed, 129 insertions(+), 169 deletions(-)
rename src/Umbraco.Web/Routing/{RoutingEnvironment.cs => RoutingContext.cs} (58%)
diff --git a/src/Umbraco.Web/NiceUrlResolver.cs b/src/Umbraco.Web/NiceUrlResolver.cs
index 1e7da3b26e..57d5e2f78c 100644
--- a/src/Umbraco.Web/NiceUrlResolver.cs
+++ b/src/Umbraco.Web/NiceUrlResolver.cs
@@ -12,16 +12,14 @@ namespace Umbraco.Web
///
internal class NiceUrlResolver
{
- public NiceUrlResolver(ContentStore contentStore, UmbracoContext umbracoContext, IRoutesCache routesCache)
+ public NiceUrlResolver(ContentStore contentStore, UmbracoContext umbracoContext)
{
_umbracoContext = umbracoContext;
_contentStore = contentStore;
- _routesCache = routesCache;
}
private readonly UmbracoContext _umbracoContext;
private readonly ContentStore _contentStore;
- private readonly IRoutesCache _routesCache;
// note: this could be a parameter...
const string UrlNameProperty = "@urlName";
@@ -41,7 +39,7 @@ namespace Umbraco.Web
// will not read cache if previewing!
var route = !_umbracoContext.InPreviewMode
- ? _routesCache.GetRoute(nodeId)
+ ? _umbracoContext.RoutesCache.GetRoute(nodeId)
: null;
if (route != null)
@@ -94,7 +92,7 @@ namespace Umbraco.Web
if (!_umbracoContext.InPreviewMode)
{
- _routesCache.Store(nodeId, route); // will not write if previewing
+ _umbracoContext.RoutesCache.Store(nodeId, route); // will not write if previewing
}
return FormatUrl(domain, path);
diff --git a/src/Umbraco.Web/PluginResolverExtensions.cs b/src/Umbraco.Web/PluginResolverExtensions.cs
index 102172f15f..9bbab2bb1c 100644
--- a/src/Umbraco.Web/PluginResolverExtensions.cs
+++ b/src/Umbraco.Web/PluginResolverExtensions.cs
@@ -13,7 +13,7 @@ namespace Umbraco.Web
public static class PluginResolverExtensions
{
- private static volatile IEnumerable _lookups;
+ private static volatile IEnumerable _lookups;
private static readonly object Locker = new object();
///
@@ -21,7 +21,7 @@ namespace Umbraco.Web
///
///
///
- internal static IEnumerable ResolveLookups(this PluginResolver plugins)
+ internal static IEnumerable ResolveLookups(this PluginResolver plugins)
{
if (_lookups == null)
{
@@ -29,22 +29,7 @@ namespace Umbraco.Web
{
if (_lookups == null)
{
- var lookupTypes = TypeFinder.FindClassesOfType();
- var lookups = new List();
- foreach (var l in lookupTypes)
- {
- try
- {
- var typeInstance = Activator.CreateInstance(l) as ILookup;
- lookups.Add(typeInstance);
- }
- catch (Exception ex)
- {
- Log.Add(LogTypes.Error, -1, "Error loading ILookup: " + ex.ToString());
- }
- }
- //set the global
- _lookups = lookups;
+ _lookups = TypeFinder.FindClassesOfType();
}
}
}
diff --git a/src/Umbraco.Web/Routing/DocumentRequest.cs b/src/Umbraco.Web/Routing/DocumentRequest.cs
index bb51181849..af62b651ef 100644
--- a/src/Umbraco.Web/Routing/DocumentRequest.cs
+++ b/src/Umbraco.Web/Routing/DocumentRequest.cs
@@ -6,6 +6,7 @@ using System.Globalization;
using System.Diagnostics;
// legacy
+using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.template;
using umbraco.cms.businesslogic.member;
@@ -16,12 +17,9 @@ namespace Umbraco.Web.Routing
{
static readonly TraceSource Trace = new TraceSource("DocumentRequest");
- public DocumentRequest(Uri uri, RoutingEnvironment lookups, UmbracoContext umbracoContext, NiceUrlResolver niceUrlResolver)
+ public DocumentRequest(Uri uri, RoutingContext routingContext)
{
- // register lookups
- _environment = lookups;
- UmbracoContext = umbracoContext;
- _niceUrlResolver = niceUrlResolver;
+ RoutingContext = routingContext;
// prepare the host
var host = uri.Host;
@@ -55,9 +53,6 @@ namespace Umbraco.Web.Routing
this.QueryString = uri.Query.TrimStart('?');
}
- readonly RoutingEnvironment _environment;
- private readonly NiceUrlResolver _niceUrlResolver;
-
///
/// the id of the requested node, if any, else zero.
///
@@ -71,9 +66,9 @@ namespace Umbraco.Web.Routing
#region Properties
///
- /// Returns the current UmbracoContext
+ /// Returns the current RoutingContext
///
- public UmbracoContext UmbracoContext { get; private set; }
+ public RoutingContext RoutingContext { get; private set; }
///
/// Gets the request host name.
@@ -128,7 +123,7 @@ namespace Umbraco.Web.Routing
_node = value;
this.Template = null;
if (_node != null)
- _nodeId = int.Parse(_environment.ContentStore.GetNodeProperty(_node, "@id"));
+ _nodeId = int.Parse(RoutingContext.ContentStore.GetNodeProperty(_node, "@id"));
else
_nodeId = 0;
}
@@ -251,8 +246,22 @@ namespace Umbraco.Web.Routing
// the first successful lookup, if any, will set this.Node, and may also set this.Template
// some lookups may implement caching
Trace.TraceInformation("{0}Begin lookup", tracePrefix);
- var lookups = _environment.RouteLookups.GetLookups();
- lookups.Any(lookup => lookup.LookupDocument(this));
+ var lookups = RoutingContext.RouteLookups.GetLookups();
+ lookups.Any(lookup =>
+ {
+ //create the instance
+ try
+ {
+ var instance = (ILookup)Activator.CreateInstance(lookup);
+ return instance.LookupDocument(this);
+ }
+ catch (Exception ex)
+ {
+ Log.Add(LogTypes.Error, -1, "Error loading ILookup: " + ex.ToString());
+ return false;
+ }
+ });
+
Trace.TraceInformation("{0}End lookup, {1}", tracePrefix, (this.HasNode ? "a document was found" : "no document was found"));
// fixme - not handling umbracoRedirect
@@ -292,7 +301,7 @@ namespace Umbraco.Web.Routing
Trace.TraceInformation("{0}No document, try notFound lookup", tracePrefix);
// if it fails then give up, there isn't much more that we can do
- if (_environment.LookupNotFound == null || !_environment.LookupNotFound.LookupDocument(this))
+ if (RoutingContext.LookupNotFound == null || !RoutingContext.LookupNotFound.LookupDocument(this))
{
Trace.TraceInformation("{0}Failed to find a document, give up", tracePrefix);
break;
@@ -344,7 +353,7 @@ namespace Umbraco.Web.Routing
throw new InvalidOperationException("There is no node.");
bool redirect = false;
- string internalRedirect = _environment.ContentStore.GetNodeProperty(this.Node, "umbracoInternalRedirectId");
+ string internalRedirect = RoutingContext.ContentStore.GetNodeProperty(this.Node, "umbracoInternalRedirectId");
if (!string.IsNullOrWhiteSpace(internalRedirect))
{
@@ -368,7 +377,7 @@ namespace Umbraco.Web.Routing
else
{
// redirect to another page
- var node = _environment.ContentStore.GetNodeById(internalRedirectId);
+ var node = RoutingContext.ContentStore.GetNodeById(internalRedirectId);
this.Node = node;
if (node != null)
{
@@ -396,7 +405,7 @@ namespace Umbraco.Web.Routing
if (this.Node == null)
throw new InvalidOperationException("There is no node.");
- var path = _environment.ContentStore.GetNodeProperty(this.Node, "@path");
+ var path = RoutingContext.ContentStore.GetNodeProperty(this.Node, "@path");
if (Access.IsProtected(this.NodeId, path))
{
@@ -409,14 +418,14 @@ namespace Umbraco.Web.Routing
Trace.TraceInformation("{0}Not logged in, redirect to login page", tracePrefix);
var loginPageId = Access.GetLoginPage(path);
if (loginPageId != this.NodeId)
- this.Node = _environment.ContentStore.GetNodeById(loginPageId);
+ this.Node = RoutingContext.ContentStore.GetNodeById(loginPageId);
}
else if (!Access.HasAccces(this.NodeId, user.ProviderUserKey))
{
Trace.TraceInformation("{0}Current member has not access, redirect to error page", tracePrefix);
var errorPageId = Access.GetErrorPage(path);
if (errorPageId != this.NodeId)
- this.Node = _environment.ContentStore.GetNodeById(errorPageId);
+ this.Node = RoutingContext.ContentStore.GetNodeById(errorPageId);
}
else
{
@@ -439,9 +448,9 @@ namespace Umbraco.Web.Routing
if (this.Node == null)
throw new InvalidOperationException("There is no node.");
- var templateAlias = UmbracoContext.HttpContext.Request.QueryString["altTemplate"];
+ var templateAlias = RoutingContext.UmbracoContext.HttpContext.Request.QueryString["altTemplate"];
if (string.IsNullOrWhiteSpace(templateAlias))
- templateAlias = UmbracoContext.HttpContext.Request.Form["altTemplate"];
+ templateAlias = RoutingContext.UmbracoContext.HttpContext.Request.Form["altTemplate"];
// fixme - we might want to support cookies?!? NO but provide a hook to change the template
@@ -449,7 +458,7 @@ namespace Umbraco.Web.Routing
{
if (string.IsNullOrWhiteSpace(templateAlias))
{
- templateAlias = _environment.ContentStore.GetNodeProperty(this.Node, "@template");
+ templateAlias = RoutingContext.ContentStore.GetNodeProperty(this.Node, "@template");
Trace.TraceInformation("{0}Look for template id={1}", tracePrefix, templateAlias);
int templateId;
if (!int.TryParse(templateAlias, out templateId))
@@ -491,11 +500,11 @@ namespace Umbraco.Web.Routing
if (this.HasNode)
{
int redirectId;
- if (!int.TryParse(_environment.ContentStore.GetNodeProperty(this.Node, "umbracoRedirect"), out redirectId))
+ if (!int.TryParse(RoutingContext.ContentStore.GetNodeProperty(this.Node, "umbracoRedirect"), out redirectId))
redirectId = -1;
string redirectUrl = "#";
if (redirectId > 0)
- redirectUrl = _niceUrlResolver.GetNiceUrl(redirectId);
+ redirectUrl = RoutingContext.NiceUrlResolver.GetNiceUrl(redirectId);
if (redirectUrl != "#")
this.RedirectUrl = redirectUrl;
}
diff --git a/src/Umbraco.Web/Routing/LookupByAlias.cs b/src/Umbraco.Web/Routing/LookupByAlias.cs
index 8d9cf2c081..153520106a 100644
--- a/src/Umbraco.Web/Routing/LookupByAlias.cs
+++ b/src/Umbraco.Web/Routing/LookupByAlias.cs
@@ -13,14 +13,9 @@ namespace Umbraco.Web.Routing
[LookupWeight(50)]
internal class LookupByAlias : ILookup
{
- public LookupByAlias(ContentStore contentStore)
- {
- _contentStore = contentStore;
- }
-
+
static readonly TraceSource Trace = new TraceSource("LookupByAlias");
- readonly ContentStore _contentStore;
public bool LookupDocument(DocumentRequest docreq)
{
@@ -28,7 +23,7 @@ namespace Umbraco.Web.Routing
if (docreq.Path != "/") // no alias if "/"
{
- node = _contentStore.GetNodeByUrlAlias(docreq.HasDomain ? docreq.Domain.RootNodeId : 0, docreq.Path);
+ node = docreq.RoutingContext.ContentStore.GetNodeByUrlAlias(docreq.HasDomain ? docreq.Domain.RootNodeId : 0, docreq.Path);
if (node != null)
{
Trace.TraceInformation("Path \"{0}\" is an alias for id={1}", docreq.Path, docreq.NodeId);
diff --git a/src/Umbraco.Web/Routing/LookupById.cs b/src/Umbraco.Web/Routing/LookupById.cs
index 8370df4ecc..61f63f7e77 100644
--- a/src/Umbraco.Web/Routing/LookupById.cs
+++ b/src/Umbraco.Web/Routing/LookupById.cs
@@ -10,24 +10,9 @@ namespace Umbraco.Web.Routing
[LookupWeight(20)]
internal class LookupById : ILookup
{
- public LookupById(ContentStore contentStore)
- {
- _contentStore = contentStore;
- }
-
+
static readonly TraceSource Trace = new TraceSource("LookupById");
- readonly ContentStore _contentStore;
-
- ////[Import]
- //IContentStore ContentStoreImport
- //{
- // set { _contentStore = value; }
- //}
-
- //public LookupById()
- //{ }
-
public bool LookupDocument(DocumentRequest docreq)
{
XmlNode node = null;
@@ -43,7 +28,7 @@ namespace Umbraco.Web.Routing
if (nodeId > 0)
{
Trace.TraceInformation("Id={0}", nodeId);
- node = _contentStore.GetNodeById(nodeId);
+ node = docreq.RoutingContext.ContentStore.GetNodeById(nodeId);
if (node != null)
{
docreq.Node = node;
diff --git a/src/Umbraco.Web/Routing/LookupByPath.cs b/src/Umbraco.Web/Routing/LookupByPath.cs
index 30dc31f546..62590276e2 100644
--- a/src/Umbraco.Web/Routing/LookupByPath.cs
+++ b/src/Umbraco.Web/Routing/LookupByPath.cs
@@ -9,17 +9,9 @@ namespace Umbraco.Web.Routing
[LookupWeight(10)]
internal class LookupByPath : ILookup
{
- public LookupByPath(ContentStore contentStore, IRoutesCache routesCache)
- {
- ContentStore = contentStore;
- RoutesCache = routesCache;
- }
-
+
static readonly TraceSource Trace = new TraceSource("LookupByPath");
- protected ContentStore ContentStore;
- protected IRoutesCache RoutesCache;
-
public virtual bool LookupDocument(DocumentRequest docreq)
{
var route = docreq.HasDomain ? (docreq.Domain.RootNodeId.ToString() + docreq.Path) : docreq.Path;
@@ -32,15 +24,15 @@ namespace Umbraco.Web.Routing
Trace.TraceInformation("Test route \"{0}\"", route);
//return '0' if in preview mode!
- var nodeId = !docreq.UmbracoContext.InPreviewMode
- ? RoutesCache.GetNodeId(route)
+ var nodeId = !docreq.RoutingContext.UmbracoContext.InPreviewMode
+ ? docreq.RoutingContext.UmbracoContext.RoutesCache.GetNodeId(route)
: 0;
XmlNode node = null;
if (nodeId > 0)
{
- node = ContentStore.GetNodeById(nodeId);
+ node = docreq.RoutingContext.ContentStore.GetNodeById(nodeId);
if (node != null)
{
docreq.Node = node;
@@ -48,22 +40,22 @@ namespace Umbraco.Web.Routing
}
else
{
- RoutesCache.ClearNode(nodeId);
+ docreq.RoutingContext.UmbracoContext.RoutesCache.ClearNode(nodeId);
}
}
if (node == null)
{
Trace.TraceInformation("Cache miss, query");
- node = ContentStore.GetNodeByRoute(route);
+ node = docreq.RoutingContext.ContentStore.GetNodeByRoute(route);
if (node != null)
{
docreq.Node = node;
Trace.TraceInformation("Query matches, id={0}", docreq.NodeId);
- if (!docreq.UmbracoContext.InPreviewMode)
+ if (!docreq.RoutingContext.UmbracoContext.InPreviewMode)
{
- RoutesCache.Store(docreq.NodeId, route); // will not write if previewing
+ docreq.RoutingContext.UmbracoContext.RoutesCache.Store(docreq.NodeId, route); // will not write if previewing
}
}
diff --git a/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs b/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs
index 11454bcdb2..6c3a105e87 100644
--- a/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs
+++ b/src/Umbraco.Web/Routing/LookupByPathWithTemplate.cs
@@ -11,12 +11,7 @@ namespace Umbraco.Web.Routing
[LookupWeight(30)]
internal class LookupByPathWithTemplate : LookupByPath, ILookup
{
- static readonly TraceSource Trace = new TraceSource("LookupByPathWithTemplate");
-
- public LookupByPathWithTemplate(ContentStore contentStore, IRoutesCache routesCache)
- : base(contentStore, routesCache)
- {
- }
+ static readonly TraceSource Trace = new TraceSource("LookupByPathWithTemplate");
public override bool LookupDocument(DocumentRequest docreq)
{
diff --git a/src/Umbraco.Web/Routing/LookupByProfile.cs b/src/Umbraco.Web/Routing/LookupByProfile.cs
index c3044349e7..cbf66cfae6 100644
--- a/src/Umbraco.Web/Routing/LookupByProfile.cs
+++ b/src/Umbraco.Web/Routing/LookupByProfile.cs
@@ -14,15 +14,7 @@ namespace Umbraco.Web.Routing
[LookupWeight(40)]
internal class LookupByProfile : LookupByPath, ILookup
{
- private readonly UmbracoContext _umbracoContext;
- static readonly TraceSource Trace = new TraceSource("LookupByProfile");
-
-
- public LookupByProfile(ContentStore contentStore, IRoutesCache routesCache, UmbracoContext umbracoContext)
- : base(contentStore, routesCache)
- {
- _umbracoContext = umbracoContext;
- }
+ static readonly TraceSource Trace = new TraceSource("LookupByProfile");
public override bool LookupDocument(DocumentRequest docreq)
{
@@ -44,7 +36,10 @@ namespace Umbraco.Web.Routing
node = LookupDocumentNode(docreq, route);
if (node != null)
- _umbracoContext.HttpContext.Items["umbMemberLogin"] = memberLogin;
+ {
+ //TODO: Should be handled by Context Items class manager (http://issues.umbraco.org/issue/U4-61)
+ docreq.RoutingContext.UmbracoContext.HttpContext.Items["umbMemberLogin"] = memberLogin;
+ }
else
Trace.TraceInformation("No document matching profile path?");
}
diff --git a/src/Umbraco.Web/Routing/LookupFor404.cs b/src/Umbraco.Web/Routing/LookupFor404.cs
index 08bc6ec0cd..4b29d61c16 100644
--- a/src/Umbraco.Web/Routing/LookupFor404.cs
+++ b/src/Umbraco.Web/Routing/LookupFor404.cs
@@ -11,18 +11,12 @@ namespace Umbraco.Web.Routing
{
internal class LookupFor404 : ILookupNotFound
{
- public LookupFor404(ContentStore contentStore)
- {
- _contentStore = contentStore;
- }
-
+
static TraceSource _trace = new TraceSource("LookupByAlias");
- private readonly ContentStore _contentStore;
-
public bool LookupDocument(DocumentRequest docRequest)
{
- docRequest.Node = HandlePageNotFound(docRequest.Path);
+ docRequest.Node = HandlePageNotFound(docRequest);
return docRequest.HasNode;
}
@@ -30,17 +24,17 @@ namespace Umbraco.Web.Routing
// copied from presentation/requestHandler
// temporary!!
- XmlNode HandlePageNotFound(string url)
+ XmlNode HandlePageNotFound(DocumentRequest docRequest)
{
- HttpContext.Current.Trace.Write("NotFoundHandler", string.Format("Running for url='{0}'.", url));
+ HttpContext.Current.Trace.Write("NotFoundHandler", string.Format("Running for url='{0}'.", docRequest.Path));
XmlNode currentPage = null;
foreach (var handler in GetNotFoundHandlers())
{
- if (handler.Execute(url) && handler.redirectID > 0)
+ if (handler.Execute(docRequest.Path) && handler.redirectID > 0)
{
//currentPage = umbracoContent.GetElementById(handler.redirectID.ToString());
- currentPage = _contentStore.GetNodeById(handler.redirectID);
+ currentPage = docRequest.RoutingContext.ContentStore.GetNodeById(handler.redirectID);
// FIXME - could it be null?
diff --git a/src/Umbraco.Web/Routing/RouteLookups.cs b/src/Umbraco.Web/Routing/RouteLookups.cs
index 9e6671c9e0..6dd33576e4 100644
--- a/src/Umbraco.Web/Routing/RouteLookups.cs
+++ b/src/Umbraco.Web/Routing/RouteLookups.cs
@@ -7,11 +7,11 @@ using Umbraco.Core;
namespace Umbraco.Web.Routing
{
///
- /// Represents a collection of ILookups used for routing that are registered in the application
+ /// Represents a collection of ILookup types used for routing that are registered in the application
///
internal class RouteLookups
{
- private static readonly List Lookups = new List();
+ private static readonly List Lookups = new List();
private static readonly ReaderWriterLockSlim Lock = new ReaderWriterLockSlim();
///
@@ -19,7 +19,7 @@ namespace Umbraco.Web.Routing
///
public static RouteLookups Current { get; internal set; }
- internal RouteLookups(IEnumerable lookups)
+ internal RouteLookups(IEnumerable lookups)
{
Lookups.AddRange(SortByWeight(lookups));
}
@@ -28,7 +28,7 @@ namespace Umbraco.Web.Routing
/// Returns all of the lookups
///
///
- public IEnumerable GetLookups()
+ public IEnumerable GetLookups()
{
return Lookups;
}
@@ -46,14 +46,27 @@ namespace Umbraco.Web.Routing
}
}
+ ///
+ /// Adds a new lookup to the end of the list
+ ///
+ ///
+ public void AddLookup()
+ where T : ILookup
+ {
+ AddLookup(typeof (T));
+ }
+
///
/// Adds a new lookup to the end of the list
///
///
- public void AddLookup(ILookup lookup)
- {
+ public void AddLookup(Type lookup)
+ {
+ if (!typeof(ILookup).IsAssignableFrom(lookup))
+ throw new InvalidOperationException("The type specified is not of type " + typeof (ILookup));
+
if (CheckExists(lookup))
- throw new InvalidOperationException("The lookup type " + lookup.GetType() + " already exists in the lookup collection");
+ throw new InvalidOperationException("The lookup type " + lookup + " already exists in the lookup collection");
using (new WriteLock(Lock))
{
@@ -66,10 +79,10 @@ namespace Umbraco.Web.Routing
///
///
///
- public void InsertLookup(int index, ILookup lookup)
+ public void InsertLookup(int index, Type lookup)
{
if (CheckExists(lookup))
- throw new InvalidOperationException("The lookup type " + lookup.GetType() + " already exists in the lookup collection");
+ throw new InvalidOperationException("The lookup type " + lookup + " already exists in the lookup collection");
using (new WriteLock(Lock))
{
@@ -82,9 +95,9 @@ namespace Umbraco.Web.Routing
///
///
///
- private static bool CheckExists(ILookup lookup)
+ private static bool CheckExists(Type lookup)
{
- return Lookups.Any(x => x.GetType() == lookup.GetType());
+ return Lookups.Any(x => x == lookup);
}
///
@@ -92,11 +105,11 @@ namespace Umbraco.Web.Routing
///
///
///
- private static IEnumerable SortByWeight(IEnumerable lookups)
+ private static IEnumerable SortByWeight(IEnumerable lookups)
{
return lookups.OrderBy(x =>
{
- var attribute = x.GetType().GetCustomAttributes(true).OfType().SingleOrDefault();
+ var attribute = x.GetCustomAttributes(true).OfType().SingleOrDefault();
return attribute == null ? LookupWeightAttribute.DefaultWeight : attribute.Weight;
}).ToList();
}
diff --git a/src/Umbraco.Web/Routing/RoutingEnvironment.cs b/src/Umbraco.Web/Routing/RoutingContext.cs
similarity index 58%
rename from src/Umbraco.Web/Routing/RoutingEnvironment.cs
rename to src/Umbraco.Web/Routing/RoutingContext.cs
index 0c5d770e86..7f2013a0d9 100644
--- a/src/Umbraco.Web/Routing/RoutingEnvironment.cs
+++ b/src/Umbraco.Web/Routing/RoutingContext.cs
@@ -8,23 +8,26 @@ namespace Umbraco.Web.Routing
/// represents a request for one specified Umbraco document to be rendered by one specified template,
/// using one particular culture.
///
- internal class RoutingEnvironment
+ internal class RoutingContext
{
- public RoutingEnvironment(
+ public RoutingContext(
+ UmbracoContext umbracoContext,
RouteLookups lookups,
ILookupNotFound lookupNotFound,
- ContentStore contentStore)
+ ContentStore contentStore,
+ NiceUrlResolver niceUrlResolver)
{
- RouteLookups = lookups;
+ UmbracoContext = umbracoContext;
+ RouteLookups = lookups;
LookupNotFound = lookupNotFound;
ContentStore = contentStore;
+ NiceUrlResolver = niceUrlResolver;
}
+ public UmbracoContext UmbracoContext { get; private set; }
public RouteLookups RouteLookups { get; private set; }
-
public ILookupNotFound LookupNotFound { get; private set; }
-
public ContentStore ContentStore { get; private set; }
-
+ public NiceUrlResolver NiceUrlResolver { get; private set; }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 3b5d82ee48..0dae665f09 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -256,7 +256,7 @@
-
+
database.ascx
diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs
index 6d6729b7c7..abb13a45b1 100644
--- a/src/Umbraco.Web/UmbracoContext.cs
+++ b/src/Umbraco.Web/UmbracoContext.cs
@@ -32,18 +32,23 @@ namespace Umbraco.Web
///
private static UmbracoContext _umbracoContext;
- ///
- /// Creates a new Umbraco context.
- ///
- ///
- ///
- internal UmbracoContext(HttpContextBase httpContext, ApplicationContext applicationContext)
+ ///
+ /// Creates a new Umbraco context.
+ ///
+ ///
+ ///
+ ///
+ internal UmbracoContext(
+ HttpContextBase httpContext,
+ ApplicationContext applicationContext,
+ IRoutesCache routesCache)
{
if (httpContext == null) throw new ArgumentNullException("httpContext");
if (applicationContext == null) throw new ArgumentNullException("applicationContext");
HttpContext = httpContext;
Application = applicationContext;
+ RoutesCache = routesCache;
}
///
@@ -91,7 +96,9 @@ namespace Umbraco.Web
///
public ApplicationContext Application { get; private set; }
- ///
+ internal IRoutesCache RoutesCache { get; private set; }
+
+ ///
/// Gets/sets the original URL of the request
///
internal Uri OriginalUrl { get; set; }
@@ -124,17 +131,7 @@ namespace Umbraco.Web
///
/// Gets/sets the DocumentRequest object
///
- internal DocumentRequest DocumentRequest { get; set; }
-
- ///
- /// Gets/sets the NiceUrlResolver object
- ///
- internal NiceUrlResolver NiceUrlResolver { get; set; }
-
- ///
- /// Gets/sets the RoutingEnvironment object
- ///
- internal RoutingEnvironment RoutingEnvironment { get; set; }
+ internal DocumentRequest DocumentRequest { get; set; }
///
/// Exposes the HttpContext for the current request
diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs
index bcd976c8d3..aeb2754e48 100644
--- a/src/Umbraco.Web/UmbracoModule.cs
+++ b/src/Umbraco.Web/UmbracoModule.cs
@@ -33,29 +33,28 @@ namespace Umbraco.Web
httpContext.Response.AddHeader("X-Umbraco-Version", string.Format("{0}.{1}", GlobalSettings.VersionMajor, GlobalSettings.VersionMinor));
//create the UmbracoContext singleton, one per request!!
- var umbracoContext = new UmbracoContext(new HttpContextWrapper(httpContext), ApplicationContext.Current);
+ var umbracoContext = new UmbracoContext(
+ new HttpContextWrapper(httpContext),
+ ApplicationContext.Current,
+ RoutesCache.Current.GetProvider());
UmbracoContext.Current = umbracoContext;
//create a content store
var contentStore = new ContentStore(umbracoContext);
//create the nice urls
- var niceUrls = new NiceUrlResolver(contentStore, umbracoContext, RoutesCache.Current.GetProvider());
- //create the RoutingEnvironment (one per http request as it relies on the umbraco context!)
- var routingEnvironment = new RoutingEnvironment(
- RouteLookups.Current,
- new LookupFor404(contentStore),
- contentStore);
+ var niceUrls = new NiceUrlResolver(contentStore, umbracoContext);
+ //create the RoutingContext (one per http request)
+ var routingContext = new RoutingContext(
+ umbracoContext,
+ RouteLookups.Current,
+ new LookupFor404(),
+ contentStore,
+ niceUrls);
// create the new document request which will cleanup the uri once and for all
- var docreq = new DocumentRequest(uri, routingEnvironment, umbracoContext, niceUrls);
+ var docreq = new DocumentRequest(uri, routingContext);
- //NOTE: we are putting these objects on the UmbracoContext because these might be handy for developers in the future to
- // access if we make them public.
- // initialize the DocumentRequest on the UmbracoContext (this is circular dependency!!!)
+ // initialize the DocumentRequest on the UmbracoContext (this is circular dependency but i think in this case is ok)
umbracoContext.DocumentRequest = docreq;
- // initialize the RoutingEnvironment on the UmbracoContext (this is circular dependency!!!)
- umbracoContext.RoutingEnvironment = routingEnvironment;
- // initialize the RoutingEnvironment on the UmbracoContext (this is circular dependency!!!)
- umbracoContext.NiceUrlResolver = niceUrls;
//create the LegacyRequestInitializer (one per http request as it relies on the umbraco context!)
var legacyRequestInitializer = new LegacyRequestInitializer(umbracoContext);
From c60abf747c91f3c4c6f95a947a6cd7b2281a8323 Mon Sep 17 00:00:00 2001
From: "shannon@ShandemVaio"
Date: Sat, 21 Jul 2012 00:42:11 +0600
Subject: [PATCH 5/8] Updated the default.aspx and page classes to match what
Stephen had in his fork. Have updated the web.config to use the new
HttpModule but the XPath statement that is generated for the LookupByPath
doesn't seem to be matching my root node. But everything else is actually
working!
---
src/Umbraco.Web.UI/web.Template.config | 460 ++++++------
src/Umbraco.Web/UmbracoContext.cs | 3 +
.../umbraco.presentation/default.aspx.cs | 503 +++++--------
src/Umbraco.Web/umbraco.presentation/page.cs | 660 +++++++++---------
4 files changed, 745 insertions(+), 881 deletions(-)
diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config
index 773c4e0f47..ac9db87f0b 100644
--- a/src/Umbraco.Web.UI/web.Template.config
+++ b/src/Umbraco.Web.UI/web.Template.config
@@ -1,263 +1,267 @@
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+ -->
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
+ -->
+
+
+
+
-
-
+
+
-
-
+ -->
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs
index abb13a45b1..95625ab475 100644
--- a/src/Umbraco.Web/UmbracoContext.cs
+++ b/src/Umbraco.Web/UmbracoContext.cs
@@ -49,6 +49,9 @@ namespace Umbraco.Web
HttpContext = httpContext;
Application = applicationContext;
RoutesCache = routesCache;
+
+ //set the original url
+ OriginalUrl = httpContext.Request.Url;
}
///
diff --git a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs
index 53b4b19dc1..f10b0bce4c 100644
--- a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs
@@ -1,359 +1,230 @@
using System;
+using System.Threading;
using System.Web;
+using System.Web.Routing;
using System.Web.UI;
using System.IO;
using System.Xml;
using System.Text.RegularExpressions;
-using umbraco.presentation;
+using Umbraco.Web;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic;
namespace umbraco
{
- ///
- /// Summary description for WebForm1.
- ///
- ///
- public partial class UmbracoDefault : Page
- {
+ ///
+ /// Summary description for WebForm1.
+ ///
+ ///
+ public partial class UmbracoDefault : Page
+ {
+ page _upage = null;
- private Guid m_version = Guid.Empty;
- private string m_tmp = requestHandler.cleanUrl();
- private page m_umbPage = null;
- private requestHandler m_umbRequest = null;
+ bool _validateRequest = true;
- private bool m_validateRequest = true;
+ const string TraceCategory = "UmbracoDefault";
- ///
- /// To turn off request validation set this to false before the PageLoad event. This equelevant to the validateRequest page directive
- /// and has nothing to do with "normal" validation controls. Default value is true.
- ///
- public bool ValidateRequest
- {
- get { return m_validateRequest; }
- set { m_validateRequest = value; }
- }
+ ///
+ /// To turn off request validation set this to false before the PageLoad event. This equivalent to the validateRequest page directive
+ /// and has nothing to do with "normal" validation controls. Default value is true.
+ ///
+ public bool ValidateRequest
+ {
+ get { return _validateRequest; }
+ set { _validateRequest = value; }
+ }
- protected override void Render(HtmlTextWriter output)
- {
+ // fixme - switch over to OnPreInit override
+ void Page_PreInit(Object sender, EventArgs e)
+ {
+ Trace.Write(TraceCategory, "Begin PreInit");
- // Get content
- TextWriter tempWriter = new StringWriter();
- base.Render(new HtmlTextWriter(tempWriter));
- string pageContents = tempWriter.ToString();
+ // moved into LegacyRequestInitializer
+ // initialize the UmbracoContext instance
+ //if (UmbracoContext.Current == null)
+ // UmbracoContext.Current = new UmbracoContext(HttpContext.Current);
- pageContents = template.ParseInternalLinks(pageContents);
+ // get the document request
+ var docreq = UmbracoContext.Current.DocumentRequest;
- // preview
- if (UmbracoContext.Current.InPreviewMode)
- {
- Trace.Write("Runtime Engine", "Umbraco is running in preview mode.");
+ // load request parameters
+ // any reason other than liveEditing why we want to do this?!
+ Guid requestVersion;
+ if (!Guid.TryParse(Request["umbVersion"], out requestVersion))
+ requestVersion = Guid.Empty;
+ int requestId;
+ if (!int.TryParse(Request["umbPageID"], out requestId))
+ requestId = -1;
- int bodyPos = pageContents.ToLower().IndexOf("
Page not found
");
+ UmbracoContext.Current.HttpContext.Response.Write("No umbraco document matches the url '" + HttpUtility.HtmlEncode(Request.Url.ToString()) + "'.
");
- #region Web Form Designer generated code
+ // fixme - should try to get infos from the DocumentRequest?
- protected override void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
-
- if (!UmbracoSettings.UseAspNetMasterPages)
- initUmbracoPage();
- base.OnInit(e);
-
- // Add Umbraco header
- if (!UmbracoSettings.RemoveUmbracoVersionHeader)
- Response.AddHeader("X-Umbraco-Version", string.Format("{0}.{1}", GlobalSettings.VersionMajor, GlobalSettings.VersionMinor));
- }
-
- private void initUmbracoPage()
- {
-
- RequestInitEventArgs e = new RequestInitEventArgs();
- e.Page = m_umbPage;
-
- if(m_umbPage != null)
- e.PageId = m_umbPage.PageID;
-
- e.Context = System.Web.HttpContext.Current;
-
- FireBeforeRequestInit(e);
- if (!e.Cancel)
- {
- if (!UmbracoSettings.EnableSplashWhileLoading || !content.Instance.isInitializing)
- {
-
- if (m_umbPage != null)
- {
- // Add page elements to global items
- try
- {
-
- System.Web.HttpContext.Current.Items.Add("pageElements", m_umbPage.Elements);
-
- }
- catch (ArgumentException)
- {
-
- System.Web.HttpContext.Current.Items.Remove("pageElements");
- System.Web.HttpContext.Current.Items.Add("pageElements", m_umbPage.Elements);
- }
-
- string tempCulture = m_umbPage.GetCulture();
- if (tempCulture != "")
- {
- System.Web.HttpContext.Current.Trace.Write("default.aspx", "Culture changed to " + tempCulture);
- System.Threading.Thread.CurrentThread.CurrentCulture =
- System.Globalization.CultureInfo.CreateSpecificCulture(tempCulture);
- System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
- }
-
- if (!UmbracoSettings.UseAspNetMasterPages)
- {
- layoutControls.umbracoPageHolder pageHolder = new umbraco.layoutControls.umbracoPageHolder();
- pageHolder.ID = "umbPageHolder";
- Page.Controls.Add(pageHolder);
- m_umbPage.RenderPage(m_umbPage.Template);
- layoutControls.umbracoPageHolder umbPageHolder =
- (layoutControls.umbracoPageHolder)Page.FindControl("umbPageHolder");
- umbPageHolder.Populate(m_umbPage);
- }
-
- }
- else
- {
- // If there's no published content, show friendly error
- if (umbraco.content.Instance.XmlContent.SelectSingleNode("/root/*") == null)
- Response.Redirect(IO.SystemDirectories.Config + "/splashes/noNodes.aspx");
- else
- {
-
- GenerateNotFoundContent();
- }
- }
- }
- else
- {
- Response.Redirect(IO.SystemDirectories.Config + "/splashes/booting.aspx?orgUrl=" + Request.Url);
- }
-
- FireAfterRequestInit(e);
- }
- }
-
- private void GenerateNotFoundContent()
- {
- Response.StatusCode = 404;
- Response.Write("Page not found
");
- if (m_umbRequest != null)
- HttpContext.Current.Response.Write("No umbraco document matches the url '" + HttpUtility.HtmlEncode(Request.Url.ToString()) + "'
umbraco tried this to match it using this xpath query'" + m_umbRequest.PageXPathQuery + "')");
- else
- HttpContext.Current.Response.Write("
No umbraco document matches the url '" + HttpUtility.HtmlEncode(Request.Url.ToString()) + "'
");
- Response.Write("");
- Response.Write("This page can be replaced with a custom 404 page by adding the id of the umbraco document to show as 404 page in the /config/umbracoSettings.config file. Just add the id to the '/settings/content/errors/error404' element.
");
- Response.Write("For more information, visit information about custom 404 on the umbraco website.
");
- Response.Write("This page is intentionally left ugly ;-)
");
- Response.Write("");
- }
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- }
-
- #endregion
-
-
-
- ///
- /// The preinit event handler
- ///
- public delegate void RequestInitEventHandler(object sender, RequestInitEventArgs e);
- ///
- /// occurs before the umbraco page is initialized for rendering.
- ///
- public static event RequestInitEventHandler BeforeRequestInit;
- ///
- /// Raises the event.
- ///
- /// The instance containing the event data.
- protected internal new virtual void FireBeforeRequestInit(RequestInitEventArgs e)
- {
- if (BeforeRequestInit != null)
- BeforeRequestInit(this, e);
- }
-
- ///
- /// Occurs when [after save].
- ///
- public static event RequestInitEventHandler AfterRequestInit;
- ///
- /// Raises the event.
- ///
- /// The instance containing the event data.
- protected virtual void FireAfterRequestInit(RequestInitEventArgs e)
- {
- if (AfterRequestInit != null)
- AfterRequestInit(this, e);
-
- }
- }
-
- //Request Init Events Arguments
- public class RequestInitEventArgs : System.ComponentModel.CancelEventArgs
- {
- public page Page { get; internal set; }
- public HttpContext Context { get; internal set; }
- public string Url { get; internal set; }
- public int PageId { get; internal set; }
- }
+ Response.Write("This page can be replaced with a custom 404. Check the documentation for \"custom 404\".
");
+ Response.Write("This page is intentionally left ugly ;-)
");
+ Response.Write("