From cb966ac70b34be0cc22cf51bd0561657ba2f8a66 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 19 Mar 2013 17:50:38 -0100 Subject: [PATCH] Web.Routing - use UmbracoContext.ContentCache --- src/Umbraco.Web/Routing/AliasUrlProvider.cs | 8 +++----- src/Umbraco.Web/Routing/DefaultUrlProvider.cs | 18 ++++++++---------- src/Umbraco.Web/Routing/IUrlProvider.cs | 6 ++---- src/Umbraco.Web/Routing/UrlProvider.cs | 4 ++-- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Web/Routing/AliasUrlProvider.cs b/src/Umbraco.Web/Routing/AliasUrlProvider.cs index 16df5293ee..f47ceaac4b 100644 --- a/src/Umbraco.Web/Routing/AliasUrlProvider.cs +++ b/src/Umbraco.Web/Routing/AliasUrlProvider.cs @@ -21,7 +21,6 @@ namespace Umbraco.Web.Routing /// Gets the nice url of a published content. /// /// The Umbraco context. - /// The content cache. /// The published content id. /// The current absolute url. /// The url mode. @@ -31,7 +30,7 @@ namespace Umbraco.Web.Routing /// absolute is true, in which case the url is always absolute. /// If the provider is unable to provide a url, it should return null. /// - 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 } @@ -44,7 +43,6 @@ namespace Umbraco.Web.Routing /// Gets the other urls of a published content. /// /// The Umbraco context. - /// The content cache. /// The published content id. /// The current absolute url. /// The other urls for the published content. @@ -52,12 +50,12 @@ namespace Umbraco.Web.Routing /// Other urls are those that GetUrl would not return in the current context, but would be valid /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...). /// - public IEnumerable GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current) + public IEnumerable GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current) { if (!FindByUrlAliasEnabled) return Enumerable.Empty(); // we have nothing to say - var node = contentCache.GetById(umbracoContext, id); + var node = umbracoContext.ContentCache.GetById(umbracoContext, id); string umbracoUrlName = null; if (node.HasProperty(Constants.Conventions.Content.UrlAlias)) umbracoUrlName = node.GetPropertyValue(Constants.Conventions.Content.UrlAlias); diff --git a/src/Umbraco.Web/Routing/DefaultUrlProvider.cs b/src/Umbraco.Web/Routing/DefaultUrlProvider.cs index 0d853413f3..be5a23b89e 100644 --- a/src/Umbraco.Web/Routing/DefaultUrlProvider.cs +++ b/src/Umbraco.Web/Routing/DefaultUrlProvider.cs @@ -21,7 +21,6 @@ namespace Umbraco.Web.Routing /// Gets the nice url of a published content. /// /// The Umbraco context. - /// The content cache. /// The published content id. /// The current absolute url. /// The url mode. @@ -30,7 +29,7 @@ namespace Umbraco.Web.Routing /// The url is absolute or relative depending on mode and on current. /// If the provider is unable to provide a url, it should return null. /// - 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; string path; @@ -56,7 +55,7 @@ namespace Umbraco.Web.Routing else { // 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) { LogHelper.Warn( @@ -84,7 +83,7 @@ namespace Umbraco.Web.Routing // no domain, respect HideTopLevelNodeFromPath for legacy purposes if (domainUri == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath) - ApplyHideTopLevelNodeFromPath(umbracoContext, contentCache, node, pathParts); + ApplyHideTopLevelNodeFromPath(umbracoContext, node, pathParts); // assemble the route pathParts.Reverse(); @@ -108,7 +107,6 @@ namespace Umbraco.Web.Routing /// Gets the other urls of a published content. /// /// The Umbraco context. - /// The content cache. /// The published content id. /// The current absolute url. /// The other urls for the published content. @@ -116,7 +114,7 @@ namespace Umbraco.Web.Routing /// Other urls are those that GetUrl would not return in the current context, but would be valid /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...). /// - public virtual IEnumerable GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current) + public virtual IEnumerable GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current) { string path; IEnumerable domainUris; @@ -137,7 +135,7 @@ namespace Umbraco.Web.Routing else { // 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) { LogHelper.Warn( @@ -165,7 +163,7 @@ namespace Umbraco.Web.Routing // no domain, respect HideTopLevelNodeFromPath for legacy purposes if (domainUris == null && global::umbraco.GlobalSettings.HideTopLevelNodeFromPath) - ApplyHideTopLevelNodeFromPath(umbracoContext, contentCache, node, pathParts); + ApplyHideTopLevelNodeFromPath(umbracoContext, node, pathParts); // assemble the route pathParts.Reverse(); @@ -273,7 +271,7 @@ namespace Umbraco.Web.Routing return uris.Select(UriUtility.UriFromUmbraco); } - static void ApplyHideTopLevelNodeFromPath(UmbracoContext umbracoContext, IPublishedContentCache contentCache, Core.Models.IPublishedContent node, IList pathParts) + static void ApplyHideTopLevelNodeFromPath(UmbracoContext umbracoContext, Core.Models.IPublishedContent node, IList pathParts) { // 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 @@ -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 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 pathParts.RemoveAt(pathParts.Count - 1); } diff --git a/src/Umbraco.Web/Routing/IUrlProvider.cs b/src/Umbraco.Web/Routing/IUrlProvider.cs index bbde44363d..b8abeadd54 100644 --- a/src/Umbraco.Web/Routing/IUrlProvider.cs +++ b/src/Umbraco.Web/Routing/IUrlProvider.cs @@ -13,7 +13,6 @@ namespace Umbraco.Web.Routing /// Gets the nice url of a published content. /// /// The Umbraco context. - /// The content cache. /// The published content id. /// The current absolute url. /// The url mode. @@ -22,13 +21,12 @@ namespace Umbraco.Web.Routing /// The url is absolute or relative depending on mode and on current. /// If the provider is unable to provide a url, it should return null. /// - string GetUrl(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current, UrlProviderMode mode); + string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode); /// /// Gets the other urls of a published content. /// /// The Umbraco context. - /// The content cache. /// The published content id. /// The current absolute url. /// The other urls for the published content. @@ -36,6 +34,6 @@ namespace Umbraco.Web.Routing /// Other urls are those that GetUrl would not return in the current context, but would be valid /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...). /// - IEnumerable GetOtherUrls(UmbracoContext umbracoContext, IPublishedContentCache contentCache, int id, Uri current); + IEnumerable GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current); } } diff --git a/src/Umbraco.Web/Routing/UrlProvider.cs b/src/Umbraco.Web/Routing/UrlProvider.cs index d658e1eff7..6746d55f72 100644 --- a/src/Umbraco.Web/Routing/UrlProvider.cs +++ b/src/Umbraco.Web/Routing/UrlProvider.cs @@ -114,7 +114,7 @@ namespace Umbraco.Web.Routing /// 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); return url ?? "#"; // legacy wants this } @@ -151,7 +151,7 @@ namespace Umbraco.Web.Routing public IEnumerable GetOtherUrls(int id, Uri current) { // 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()); + var urls = _urlProviders.SelectMany(provider => provider.GetOtherUrls(_umbracoContext, id, current) ?? Enumerable.Empty()); return urls; }