Web.Routing - use UmbracoContext.ContentCache

This commit is contained in:
Stephan
2013-03-19 17:50:38 -01:00
parent cce32f406f
commit cb966ac70b
4 changed files with 15 additions and 21 deletions

View File

@@ -21,7 +21,6 @@ namespace Umbraco.Web.Routing
/// Gets the nice url of a published content. /// Gets the nice url of a published content.
/// </summary> /// </summary>
/// <param name="umbracoContext">The Umbraco context.</param> /// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="contentCache">The content cache.</param>
/// <param name="id">The published content id.</param> /// <param name="id">The published content id.</param>
/// <param name="current">The current absolute url.</param> /// <param name="current">The current absolute url.</param>
/// <param name="mode">The url mode.</param> /// <param name="mode">The url mode.</param>
@@ -31,7 +30,7 @@ namespace Umbraco.Web.Routing
/// <c>absolute</c> is true, in which case the url is always absolute.</para> /// <c>absolute</c> is true, in which case the url is always absolute.</para>
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para> /// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
/// </remarks> /// </remarks>
public string GetUrl(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current, UrlProviderMode mode) public string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{ {
return null; // we have nothing to say return null; // we have nothing to say
} }
@@ -44,7 +43,6 @@ namespace Umbraco.Web.Routing
/// Gets the other urls of a published content. /// Gets the other urls of a published content.
/// </summary> /// </summary>
/// <param name="umbracoContext">The Umbraco context.</param> /// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="contentCache">The content cache.</param>
/// <param name="id">The published content id.</param> /// <param name="id">The published content id.</param>
/// <param name="current">The current absolute url.</param> /// <param name="current">The current absolute url.</param>
/// <returns>The other urls for the published content.</returns> /// <returns>The other urls for the published content.</returns>
@@ -52,12 +50,12 @@ namespace Umbraco.Web.Routing
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid /// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para> /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
/// </remarks> /// </remarks>
public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current) public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{ {
if (!FindByUrlAliasEnabled) if (!FindByUrlAliasEnabled)
return Enumerable.Empty<string>(); // we have nothing to say return Enumerable.Empty<string>(); // we have nothing to say
var node = contentCache.GetById(umbracoContext, id); var node = umbracoContext.ContentCache.GetById(umbracoContext, id);
string umbracoUrlName = null; string umbracoUrlName = null;
if (node.HasProperty(Constants.Conventions.Content.UrlAlias)) if (node.HasProperty(Constants.Conventions.Content.UrlAlias))
umbracoUrlName = node.GetPropertyValue<string>(Constants.Conventions.Content.UrlAlias); umbracoUrlName = node.GetPropertyValue<string>(Constants.Conventions.Content.UrlAlias);

View File

@@ -21,7 +21,6 @@ namespace Umbraco.Web.Routing
/// Gets the nice url of a published content. /// Gets the nice url of a published content.
/// </summary> /// </summary>
/// <param name="umbracoContext">The Umbraco context.</param> /// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="contentCache">The content cache.</param>
/// <param name="id">The published content id.</param> /// <param name="id">The published content id.</param>
/// <param name="current">The current absolute url.</param> /// <param name="current">The current absolute url.</param>
/// <param name="mode">The url mode.</param> /// <param name="mode">The url mode.</param>
@@ -30,7 +29,7 @@ namespace Umbraco.Web.Routing
/// <para>The url is absolute or relative depending on <c>mode</c> and on <c>current</c>.</para> /// <para>The url is absolute or relative depending on <c>mode</c> and on <c>current</c>.</para>
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para> /// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
/// </remarks> /// </remarks>
public virtual string GetUrl(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current, UrlProviderMode mode) public virtual string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode)
{ {
DomainAndUri domainUri; DomainAndUri domainUri;
string path; string path;
@@ -56,7 +55,7 @@ namespace Umbraco.Web.Routing
else else
{ {
// there was no route in the cache - create a route // there was no route in the cache - create a route
var node = contentCache.GetById(umbracoContext, id); var node = umbracoContext.ContentCache.GetById(umbracoContext, id);
if (node == null) if (node == null)
{ {
LogHelper.Warn<DefaultUrlProvider>( LogHelper.Warn<DefaultUrlProvider>(
@@ -84,7 +83,7 @@ namespace Umbraco.Web.Routing
// no domain, respect HideTopLevelNodeFromPath for legacy purposes // no domain, respect HideTopLevelNodeFromPath for legacy purposes
if (domainUri == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath) if (domainUri == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath)
ApplyHideTopLevelNodeFromPath(umbracoContext, contentCache, node, pathParts); ApplyHideTopLevelNodeFromPath(umbracoContext, node, pathParts);
// assemble the route // assemble the route
pathParts.Reverse(); pathParts.Reverse();
@@ -108,7 +107,6 @@ namespace Umbraco.Web.Routing
/// Gets the other urls of a published content. /// Gets the other urls of a published content.
/// </summary> /// </summary>
/// <param name="umbracoContext">The Umbraco context.</param> /// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="contentCache">The content cache.</param>
/// <param name="id">The published content id.</param> /// <param name="id">The published content id.</param>
/// <param name="current">The current absolute url.</param> /// <param name="current">The current absolute url.</param>
/// <returns>The other urls for the published content.</returns> /// <returns>The other urls for the published content.</returns>
@@ -116,7 +114,7 @@ namespace Umbraco.Web.Routing
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid /// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para> /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
/// </remarks> /// </remarks>
public virtual IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current) public virtual IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current)
{ {
string path; string path;
IEnumerable<DomainAndUri> domainUris; IEnumerable<DomainAndUri> domainUris;
@@ -137,7 +135,7 @@ namespace Umbraco.Web.Routing
else else
{ {
// there was no route in the cache - create a route // there was no route in the cache - create a route
var node = contentCache.GetById(umbracoContext, id); var node = umbracoContext.ContentCache.GetById(umbracoContext, id);
if (node == null) if (node == null)
{ {
LogHelper.Warn<DefaultUrlProvider>( LogHelper.Warn<DefaultUrlProvider>(
@@ -165,7 +163,7 @@ namespace Umbraco.Web.Routing
// no domain, respect HideTopLevelNodeFromPath for legacy purposes // no domain, respect HideTopLevelNodeFromPath for legacy purposes
if (domainUris == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath) if (domainUris == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath)
ApplyHideTopLevelNodeFromPath(umbracoContext, contentCache, node, pathParts); ApplyHideTopLevelNodeFromPath(umbracoContext, node, pathParts);
// assemble the route // assemble the route
pathParts.Reverse(); pathParts.Reverse();
@@ -273,7 +271,7 @@ namespace Umbraco.Web.Routing
return uris.Select(UriUtility.UriFromUmbraco); return uris.Select(UriUtility.UriFromUmbraco);
} }
static void ApplyHideTopLevelNodeFromPath(UmbracoContext umbracoContext, IPublishedContentCache contentCache, Core.Models.IPublishedContent node, IList<string> pathParts) static void ApplyHideTopLevelNodeFromPath(UmbracoContext umbracoContext, Core.Models.IPublishedContent node, IList<string> pathParts)
{ {
// in theory if hideTopLevelNodeFromPath is true, then there should be only once // in theory if hideTopLevelNodeFromPath is true, then there should be only once
// top-level node, or else domains should be assigned. but for backward compatibility // top-level node, or else domains should be assigned. but for backward compatibility
@@ -285,7 +283,7 @@ namespace Umbraco.Web.Routing
// that's the way it works pre-4.10 and we try to be backward compat for the time being // that's the way it works pre-4.10 and we try to be backward compat for the time being
if (node.Parent == null) if (node.Parent == null)
{ {
var rootNode = contentCache.GetByRoute(umbracoContext, "/", true); var rootNode = umbracoContext.ContentCache.GetByRoute(umbracoContext, "/", true);
if (rootNode.Id == node.Id) // remove only if we're the default node if (rootNode.Id == node.Id) // remove only if we're the default node
pathParts.RemoveAt(pathParts.Count - 1); pathParts.RemoveAt(pathParts.Count - 1);
} }

View File

@@ -13,7 +13,6 @@ namespace Umbraco.Web.Routing
/// Gets the nice url of a published content. /// Gets the nice url of a published content.
/// </summary> /// </summary>
/// <param name="umbracoContext">The Umbraco context.</param> /// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="contentCache">The content cache.</param>
/// <param name="id">The published content id.</param> /// <param name="id">The published content id.</param>
/// <param name="current">The current absolute url.</param> /// <param name="current">The current absolute url.</param>
/// <param name="mode">The url mode.</param> /// <param name="mode">The url mode.</param>
@@ -22,13 +21,12 @@ namespace Umbraco.Web.Routing
/// <para>The url is absolute or relative depending on <c>mode</c> and on <c>current</c>.</para> /// <para>The url is absolute or relative depending on <c>mode</c> and on <c>current</c>.</para>
/// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para> /// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para>
/// </remarks> /// </remarks>
string GetUrl(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current, UrlProviderMode mode); string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode);
/// <summary> /// <summary>
/// Gets the other urls of a published content. /// Gets the other urls of a published content.
/// </summary> /// </summary>
/// <param name="umbracoContext">The Umbraco context.</param> /// <param name="umbracoContext">The Umbraco context.</param>
/// <param name="contentCache">The content cache.</param>
/// <param name="id">The published content id.</param> /// <param name="id">The published content id.</param>
/// <param name="current">The current absolute url.</param> /// <param name="current">The current absolute url.</param>
/// <returns>The other urls for the published content.</returns> /// <returns>The other urls for the published content.</returns>
@@ -36,6 +34,6 @@ namespace Umbraco.Web.Routing
/// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid /// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid
/// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para> /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para>
/// </remarks> /// </remarks>
IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current); IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current);
} }
} }

View File

@@ -114,7 +114,7 @@ namespace Umbraco.Web.Routing
/// </remarks> /// </remarks>
public string GetUrl(int id, Uri current, UrlProviderMode mode) public string GetUrl(int id, Uri current, UrlProviderMode mode)
{ {
var url = _urlProviders.Select(provider => provider.GetUrl(_umbracoContext, _umbracoContext.ContentCache, id, current, mode)) var url = _urlProviders.Select(provider => provider.GetUrl(_umbracoContext, id, current, mode))
.FirstOrDefault(u => u != null); .FirstOrDefault(u => u != null);
return url ?? "#"; // legacy wants this return url ?? "#"; // legacy wants this
} }
@@ -151,7 +151,7 @@ namespace Umbraco.Web.Routing
public IEnumerable<string> GetOtherUrls(int id, Uri current) public IEnumerable<string> GetOtherUrls(int id, Uri current)
{ {
// providers can return null or an empty list or a non-empty list, be prepared // providers can return null or an empty list or a non-empty list, be prepared
var urls = _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, _umbracoContext.ContentCache, id, current) ?? Enumerable.Empty<string>()); var urls = _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, id, current) ?? Enumerable.Empty<string>());
return urls; return urls;
} }