Web.Routing - reorganize finders for better backward compat. with pre-4.10
This commit is contained in:
@@ -34,7 +34,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
if (id > 0)
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByLegacy404>("Got id={1}.", () => id);
|
||||
LogHelper.Debug<ContentFinderByLegacy404>("Got id={0}.", () => id);
|
||||
|
||||
content = pcr.RoutingContext.PublishedContentStore.GetDocumentById(
|
||||
pcr.RoutingContext.UmbracoContext,
|
||||
|
||||
@@ -12,25 +12,18 @@ using umbraco.interfaces;
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an implementation of <see cref="IContentFinder"/> to be used as a last chance finder,
|
||||
/// that handles backward compatilibty with legacy <c>INotFoundHandler</c>.
|
||||
/// Provides an implementation of <see cref="IContentFinder"/> that runs legacy <c>INotFoundHandler</c>.
|
||||
/// </summary>
|
||||
internal class ContentLastChanceFinder : IContentFinder
|
||||
internal class ContentFinderByNotFoundHandlers : IContentFinder
|
||||
{
|
||||
// notes
|
||||
//
|
||||
// at the moment we load the legacy INotFoundHandler
|
||||
// excluding those that have been replaced by proper lookups,
|
||||
// excluding those that have been replaced by proper finders,
|
||||
// and run them.
|
||||
//
|
||||
// when we finaly obsolete INotFoundHandler, we'll have to move
|
||||
// over here code from legacy requestHandler.hande404, which
|
||||
// basically uses umbraco.library.GetCurrentNotFoundPageId();
|
||||
// which also would need to be refactored / migrated here.
|
||||
//
|
||||
// the best way to do this would be to create a DefaultLastChanceLookup2
|
||||
// that would do everything by itself, and let ppl use it if they
|
||||
// want, then make it the default one, then remove this one.
|
||||
// code from requestHandler.handle404 has been moved over to
|
||||
// the new ContentFinderByLegacy404 finder.
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
@@ -49,7 +42,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
IPublishedContent HandlePageNotFound(PublishedContentRequest docRequest)
|
||||
{
|
||||
LogHelper.Debug<ContentLastChanceFinder>("Running for url='{0}'.", () => docRequest.Uri.AbsolutePath);
|
||||
LogHelper.Debug<ContentFinderByNotFoundHandlers>("Running for url='{0}'.", () => docRequest.Uri.AbsolutePath);
|
||||
|
||||
//XmlNode currentPage = null;
|
||||
IPublishedContent currentPage = null;
|
||||
@@ -66,7 +59,7 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
// FIXME - could it be null?
|
||||
|
||||
LogHelper.Debug<ContentLastChanceFinder>("Handler '{0}' found node with id={1}.", () => handler.GetType().FullName, () => handler.redirectID);
|
||||
LogHelper.Debug<ContentFinderByNotFoundHandlers>("Handler '{0}' found node with id={1}.", () => handler.GetType().FullName, () => handler.redirectID);
|
||||
|
||||
//// check for caching
|
||||
//if (handler.CacheUrl)
|
||||
@@ -97,7 +90,7 @@ namespace Umbraco.Web.Routing
|
||||
// initialize handlers
|
||||
// create the definition cache
|
||||
|
||||
LogHelper.Debug<ContentLastChanceFinder>("Registering custom handlers.");
|
||||
LogHelper.Debug<ContentFinderByNotFoundHandlers>("Registering custom handlers.");
|
||||
|
||||
var customHandlerTypes = new List<Type>();
|
||||
|
||||
@@ -108,21 +101,17 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
var assemblyName = n.Attributes.GetNamedItem("assembly").Value;
|
||||
|
||||
// skip those that are in umbraco.dll because we have replaced them with finders
|
||||
if (assemblyName == "umbraco")
|
||||
continue;
|
||||
|
||||
var typeName = n.Attributes.GetNamedItem("type").Value;
|
||||
string ns = assemblyName;
|
||||
var nsAttr = n.Attributes.GetNamedItem("namespace");
|
||||
if (nsAttr != null && !string.IsNullOrWhiteSpace(nsAttr.Value))
|
||||
ns = nsAttr.Value;
|
||||
|
||||
if (assemblyName == "umbraco" && (ns + "." + typeName) != "umbraco.handle404")
|
||||
{
|
||||
// skip those that are in umbraco.dll because we have replaced them with IContentFinder
|
||||
// but do not skip "handle404" as that's the built-in legacy final handler, and for the time
|
||||
// being people will have it in their config.
|
||||
continue;
|
||||
}
|
||||
|
||||
LogHelper.Debug<ContentLastChanceFinder>("Registering '{0}.{1},{2}'.", () => ns, () => typeName, () => assemblyName);
|
||||
LogHelper.Debug<ContentFinderByNotFoundHandlers>("Registering '{0}.{1},{2}'.", () => ns, () => typeName, () => assemblyName);
|
||||
|
||||
Type type = null;
|
||||
try
|
||||
@@ -135,7 +124,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error<ContentLastChanceFinder>("Error registering handler, ignoring.", e);
|
||||
LogHelper.Error<ContentFinderByNotFoundHandlers>("Error registering handler, ignoring.", e);
|
||||
}
|
||||
|
||||
if (type != null)
|
||||
@@ -168,7 +157,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error<ContentLastChanceFinder>(string.Format("Error instanciating handler {0}, ignoring.", type.FullName), e);
|
||||
LogHelper.Error<ContentFinderByNotFoundHandlers>(string.Format("Error instanciating handler {0}, ignoring.", type.FullName), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds a template for the current node.
|
||||
/// Finds a template for the current node, if any.
|
||||
/// </summary>
|
||||
private void FindTemplate()
|
||||
{
|
||||
@@ -534,8 +534,11 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
const string tracePrefix = "FindTemplate: ";
|
||||
|
||||
if (_pcr.PublishedContent == null)
|
||||
throw new InvalidOperationException("There is no PublishedContent.");
|
||||
if (_pcr.PublishedContent == null)
|
||||
{
|
||||
_pcr.Template = null;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -329,6 +329,7 @@
|
||||
<Compile Include="Routing\ContentFinderByNotFoundHandler.cs" />
|
||||
<Compile Include="Routing\ContentFinderByPageIdQuery.cs" />
|
||||
<Compile Include="Mvc\SurfaceControllerResolver.cs" />
|
||||
<Compile Include="Routing\ContentFinderByNotFoundHandlers.cs" />
|
||||
<Compile Include="Routing\NotFoundHandlerHelper.cs" />
|
||||
<Compile Include="Routing\PublishedContentRequestEngine.cs" />
|
||||
<Compile Include="Search\ExamineEvents.cs" />
|
||||
@@ -429,7 +430,6 @@
|
||||
<Compile Include="WebBootManager.cs" />
|
||||
<Compile Include="Routing\LegacyRequestInitializer.cs" />
|
||||
<Compile Include="Mvc\ControllerExtensions.cs" />
|
||||
<Compile Include="Routing\ContentLastChanceFinder.cs" />
|
||||
<Compile Include="Routing\IContentLastChanceFinderResolver.cs" />
|
||||
<Compile Include="Routing\ContentFinderByUrlAlias.cs" />
|
||||
<Compile Include="Media\ThumbnailProviders\AbstractThumbnailProvider.cs" />
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace Umbraco.Web
|
||||
typeof (RenderControllerFactory)
|
||||
});
|
||||
|
||||
IContentLastChanceFinderResolver.Current = new IContentLastChanceFinderResolver(new ContentLastChanceFinder());
|
||||
IContentLastChanceFinderResolver.Current = new IContentLastChanceFinderResolver(new ContentFinderByLegacy404());
|
||||
|
||||
IContentFinderResolver.Current = new IContentFinderResolver(
|
||||
//add all known resolvers in the correct order, devs can then modify this list on application startup either by binding to events
|
||||
@@ -205,7 +205,8 @@ namespace Umbraco.Web
|
||||
typeof (ContentFinderByIdPath),
|
||||
typeof (ContentFinderByNiceUrlAndTemplate),
|
||||
typeof (ContentFinderByProfile),
|
||||
typeof (ContentFinderByUrlAlias)
|
||||
typeof (ContentFinderByUrlAlias),
|
||||
typeof (ContentFinderByNotFoundHandlers)
|
||||
});
|
||||
|
||||
RoutesCacheResolver.Current = new RoutesCacheResolver(new DefaultRoutesCache(_isForTesting == false));
|
||||
|
||||
Reference in New Issue
Block a user