Refactor IPublishedContent.GetCultureFromDomains()

This commit is contained in:
Stephan
2019-04-17 14:41:54 +02:00
parent e062ea8d31
commit a996d46b6f
21 changed files with 153 additions and 114 deletions

View File

@@ -27,13 +27,18 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
}
/// <inheritdoc />
public IEnumerable<Domain> GetAssigned(int contentId, bool includeWildcards)
public IEnumerable<Domain> GetAssigned(int documentId, bool includeWildcards = false)
{
return _domainService.GetAssignedDomains(contentId, includeWildcards)
return _domainService.GetAssignedDomains(documentId, includeWildcards)
.Where(x => x.RootContentId.HasValue && x.LanguageIsoCode.IsNullOrWhiteSpace() == false)
.Select(x => new Domain(x.Id, x.DomainName, x.RootContentId.Value, CultureInfo.GetCultureInfo(x.LanguageIsoCode), x.IsWildcard));
}
/// <inheritdoc />
public bool HasAssigned(int documentId, bool includeWildcards = false)
=> documentId > 0 && GetAssigned(documentId, includeWildcards).Any();
/// <inheritdoc />
public string DefaultCulture { get; }
}
}

View File

@@ -22,7 +22,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly RoutesCache _routesCache;
private readonly IDomainCache _domainCache;
private readonly DomainHelper _domainHelper;
private readonly PublishedContentTypeCache _contentTypeCache;
// initialize a PublishedContentCache instance with
@@ -48,7 +47,6 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
_routesCache = routesCache; // may be null for unit-testing
_contentTypeCache = contentTypeCache;
_domainCache = domainCache;
_domainHelper = new DomainHelper(_domainCache, siteDomainHelper);
_xmlStore = xmlStore;
_xml = _xmlStore.Xml; // capture - because the cache has to remain consistent
@@ -107,7 +105,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
// that would be returned - the "deepest" route - and that is the route we want to cache, *not* the
// longer one - so make sure we don't cache the wrong route
var deepest = DomainHelper.ExistsDomainInPath(_domainCache.GetAll(false), content.Path, domainRootNodeId) == false;
var deepest = DomainUtilities.ExistsDomainInPath(_domainCache.GetAll(false), content.Path, domainRootNodeId) == false;
if (deepest)
_routesCache.Store(content.Id, route, true); // trusted route
@@ -267,7 +265,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
// or we reach the content root, collecting urls in the way
var pathParts = new List<string>();
var n = node;
var hasDomains = _domainHelper.NodeHasDomains(n.Id);
var hasDomains = _domainCache.HasAssigned(n.Id);
while (hasDomains == false && n != null) // n is null at root
{
// get the url
@@ -276,7 +274,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
// move to parent node
n = n.Parent;
hasDomains = n != null && _domainHelper.NodeHasDomains(n.Id);
hasDomains = n != null && _domainCache.HasAssigned(n.Id);
}
// no domain, respect HideTopLevelNodeFromPath for legacy purposes

View File

@@ -1656,7 +1656,7 @@ namespace Umbraco.Web.Editors
{
try
{
var uri = DomainHelper.ParseUriFromDomainName(domain.Name, Request.RequestUri);
var uri = DomainUtilities.ParseUriFromDomainName(domain.Name, Request.RequestUri);
}
catch (UriFormatException)
{

View File

@@ -123,23 +123,17 @@ namespace Umbraco.Web.Editors
// Since a Macro might contain thing thats related to the culture of the "IPublishedContent" (ie Dictionary keys) we want
// to set the current culture to the culture related to the content item. This is hacky but it works.
// fixme I don't even know how this ever worked?!
// fixme
// in a 1:1 situation we do not handle the language being edited
// so the macro renders in the wrong language
// assume this was some sort of "the culture of the item"
// but... with multilingual it does not make any sense?!
//var culture = publishedContent.GetCulture();
string culture = ""; // needs to be eg fr-FR
var culture = publishedContent.GetCultureFromDomains();
if (culture != null)
{
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture);
_variationContextAccessor.VariationContext = new VariationContext(culture);
}
else
{
_variationContextAccessor.VariationContext = new VariationContext(); //must have an active variation context!
}
// must have an active variation context!
_variationContextAccessor.VariationContext = new VariationContext(culture);
var result = Request.CreateResponse();
//need to create a specific content result formatted as HTML since this controller has been configured

View File

@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Routing;
namespace Umbraco.Web.PublishedCache
@@ -6,20 +8,29 @@ namespace Umbraco.Web.PublishedCache
public interface IDomainCache
{
/// <summary>
/// Returns all <see cref="Domain"/> in the current domain cache including any domains that may be referenced by content items that are no longer published
/// Gets all <see cref="Domain"/> in the current domain cache, including any domains that may be referenced by documents that are no longer published.
/// </summary>
/// <param name="includeWildcards"></param>
/// <returns></returns>
IEnumerable<Domain> GetAll(bool includeWildcards);
/// <summary>
/// Returns all assigned <see cref="Domain"/> for the content id specified even if the content item is not published
/// Gets all assigned <see cref="Domain"/> for specified document, even if it is not published.
/// </summary>
/// <param name="contentId"></param>
/// <param name="includeWildcards"></param>
/// <returns></returns>
IEnumerable<Domain> GetAssigned(int contentId, bool includeWildcards);
/// <param name="documentId">The document identifier.</param>
/// <param name="includeWildcards">A value indicating whether to consider wildcard domains.</param>
IEnumerable<Domain> GetAssigned(int documentId, bool includeWildcards = false);
/// <summary>
/// Determines whether a document has domains.
/// </summary>
/// <param name="documentId">The document identifier.</param>
/// <param name="includeWildcards">A value indicating whether to consider wildcard domains.</param>
bool HasAssigned(int documentId, bool includeWildcards = false);
/// <summary>
/// Gets the system default culture.
/// </summary>
string DefaultCulture { get; }
}
}

View File

@@ -23,9 +23,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
private readonly ContentStore.Snapshot _snapshot;
private readonly IAppCache _snapshotCache;
private readonly IAppCache _elementsCache;
private readonly DomainHelper _domainHelper;
private readonly IDomainCache _domainCache;
private readonly IGlobalSettings _globalSettings;
private readonly ILocalizationService _localizationService;
#region Constructor
@@ -34,15 +33,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
// it's too late for UmbracoContext which has captured previewDefault and stuff into these ctor vars
// but, no, UmbracoContext returns snapshot.Content which comes from elements SO a resync should create a new cache
public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, DomainHelper domainHelper, IGlobalSettings globalSettings, ILocalizationService localizationService)
public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, IGlobalSettings globalSettings)
: base(previewDefault)
{
_snapshot = snapshot;
_snapshotCache = snapshotCache;
_elementsCache = elementsCache;
_domainHelper = domainHelper;
_domainCache = domainCache;
_globalSettings = globalSettings;
_localizationService = localizationService;
}
private bool HideTopLevelNodeFromPath => _globalSettings.HideTopLevelNodeFromPath;
@@ -150,7 +148,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var pathParts = new List<string>();
var n = node;
var urlSegment = n.UrlSegment(culture);
var hasDomains = _domainHelper.NodeHasDomains(n.Id);
var hasDomains = _domainCache.HasAssigned(n.Id);
while (hasDomains == false && n != null) // n is null at root
{
// no segment indicates this is not published when this is a variant
@@ -163,7 +161,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (n != null)
urlSegment = n.UrlSegment(culture);
hasDomains = n != null && _domainHelper.NodeHasDomains(n.Id);
hasDomains = n != null && _domainCache.HasAssigned(n.Id);
}
// at this point this will be the urlSegment of the root, no segment indicates this is not published when this is a variant

View File

@@ -4,16 +4,23 @@ using Umbraco.Web.Routing;
namespace Umbraco.Web.PublishedCache.NuCache
{
/// <summary>
/// Implements <see cref="IDomainCache"/> for NuCache.
/// </summary>
internal class DomainCache : IDomainCache
{
private readonly SnapDictionary<int, Domain>.Snapshot _snapshot;
/// <summary>
/// Initializes a new instance of the <see cref="DomainCache"/> class.
/// </summary>
public DomainCache(SnapDictionary<int, Domain>.Snapshot snapshot, string defaultCulture)
{
_snapshot = snapshot;
DefaultCulture = defaultCulture; // capture - fast
DefaultCulture = defaultCulture;
}
/// <inheritdoc />
public IEnumerable<Domain> GetAll(bool includeWildcards)
{
var list = _snapshot.GetAll();
@@ -21,17 +28,23 @@ namespace Umbraco.Web.PublishedCache.NuCache
return list;
}
public IEnumerable<Domain> GetAssigned(int contentId, bool includeWildcards)
/// <inheritdoc />
public IEnumerable<Domain> GetAssigned(int documentId, bool includeWildcards = false)
{
// probably this could be optimized with an index
// but then we'd need a custom DomainStore of some sort
var list = _snapshot.GetAll();
list = list.Where(x => x.ContentId == contentId);
list = list.Where(x => x.ContentId == documentId);
if (includeWildcards == false) list = list.Where(x => x.IsWildcard == false);
return list;
}
/// <inheritdoc />
public bool HasAssigned(int documentId, bool includeWildcards = false)
=> documentId > 0 && GetAssigned(documentId, includeWildcards).Any();
/// <inheritdoc />
public string DefaultCulture { get; }
}
}

View File

@@ -4,13 +4,11 @@ using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;
using CSharpTest.Net.Collections;
using Newtonsoft.Json;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
@@ -1074,11 +1072,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
var defaultCulture = _defaultCultureAccessor.DefaultCulture;
var domainCache = new DomainCache(domainSnap, defaultCulture);
var domainHelper = new DomainHelper(domainCache, _siteDomainHelper);
return new PublishedSnapshot.PublishedSnapshotElements
{
ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainHelper, _globalSettings, _serviceContext.LocalizationService),
ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainCache, _globalSettings),
MediaCache = new MediaCache(previewDefault, mediaSnap, snapshotCache, elementsCache),
MemberCache = new MemberCache(previewDefault, snapshotCache, _serviceContext.MemberService, memberTypeCache, PublishedSnapshotAccessor, VariationContextAccessor, _umbracoContextAccessor, _entitySerializer),
DomainCache = domainCache,

View File

@@ -11,6 +11,7 @@ using Umbraco.Core.Services;
using Umbraco.Examine;
using Umbraco.Web.Composing;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
namespace Umbraco.Web
{
@@ -20,9 +21,12 @@ namespace Umbraco.Web
public static class PublishedContentExtensions
{
// see notes in PublishedElementExtensions
// (yes, this is not pretty, but works for now)
//
private static IPublishedValueFallback PublishedValueFallback => Current.PublishedValueFallback;
private static IPublishedSnapshot PublishedSnapshot => Current.PublishedSnapshot;
private static UmbracoContext UmbracoContext => Current.UmbracoContext;
private static ISiteDomainHelper SiteDomainHelper => Current.Factory.GetInstance<ISiteDomainHelper>();
#region IsComposedOf
@@ -186,6 +190,27 @@ namespace Umbraco.Web
return contents.Where(x => !x.ContentType.VariesByCulture() || x.HasCulture(culture));
}
/// <summary>
/// Gets the culture assigned to a document by domains, in the context of a current Uri.
/// </summary>
/// <param name="content">The document.</param>
/// <param name="current">An optional current Uri.</param>
/// <returns>The culture assigned to the document by domains.</returns>
/// <remarks>
/// <para>In 1:1 multilingual setup, a document contains several cultures (there is not
/// one document per culture), and domains, withing the context of a current Uri, assign
/// a culture to that document.</para>
/// </remarks>
public static string GetCultureFromDomains(this IPublishedContent content, Uri current = null)
{
var umbracoContext = UmbracoContext;
if (umbracoContext == null)
throw new InvalidOperationException("A current UmbracoContext is required.");
return DomainUtilities.GetCultureFromDomains(content.Id, content.Path, current, umbracoContext, SiteDomainHelper);
}
#endregion
#region Search

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -60,16 +59,14 @@ namespace Umbraco.Web.Routing
if (!node.HasProperty(Constants.Conventions.Content.UrlAlias))
yield break;
var domainHelper = umbracoContext.GetDomainHelper(_siteDomainHelper);
// look for domains, walking up the tree
var n = node;
var domainUris = domainHelper.DomainsForNode(n.Id, current, false);
var domainUris = DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainHelper, n.Id, current, false);
while (domainUris == null && n != null) // n is null at root
{
// move to parent node
n = n.Parent;
domainUris = n == null ? null : domainHelper.DomainsForNode(n.Id, current, excludeDefault: false);
domainUris = n == null ? null : DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainHelper, n.Id, current, excludeDefault: false);
}
// determine whether the alias property varies

View File

@@ -53,7 +53,7 @@ namespace Umbraco.Web.Routing
}
if (node != null)
{
var d = DomainHelper.FindWildcardDomainInPath(frequest.UmbracoContext.PublishedSnapshot.Domains.GetAll(true), node.Path, null);
var d = DomainUtilities.FindWildcardDomainInPath(frequest.UmbracoContext.PublishedSnapshot.Domains.GetAll(true), node.Path, null);
if (d != null)
errorCulture = d.Culture;
}

View File

@@ -33,7 +33,7 @@ namespace Umbraco.Web.Routing
public bool TryFindContent(PublishedRequest frequest)
{
var route = frequest.HasDomain
? frequest.Domain.ContentId + DomainHelper.PathRelativeToDomain(frequest.Domain.Uri, frequest.Uri.GetAbsolutePathDecoded())
? frequest.Domain.ContentId + DomainUtilities.PathRelativeToDomain(frequest.Domain.Uri, frequest.Uri.GetAbsolutePathDecoded())
: frequest.Uri.GetAbsolutePathDecoded();
var redirectUrl = _redirectUrlService.GetMostRecentRedirectUrl(route);

View File

@@ -28,7 +28,7 @@ namespace Umbraco.Web.Routing
{
string route;
if (frequest.HasDomain)
route = frequest.Domain.ContentId + DomainHelper.PathRelativeToDomain(frequest.Domain.Uri, frequest.Uri.GetAbsolutePathDecoded());
route = frequest.Domain.ContentId + DomainUtilities.PathRelativeToDomain(frequest.Domain.Uri, frequest.Uri.GetAbsolutePathDecoded());
else
route = frequest.Uri.GetAbsolutePathDecoded();

View File

@@ -38,7 +38,7 @@ namespace Umbraco.Web.Routing
var path = frequest.Uri.GetAbsolutePathDecoded();
if (frequest.HasDomain)
path = DomainHelper.PathRelativeToDomain(frequest.Domain.Uri, path);
path = DomainUtilities.PathRelativeToDomain(frequest.Domain.Uri, path);
// no template if "/"
if (path == "/")

View File

@@ -47,15 +47,13 @@ namespace Umbraco.Web.Routing
return null;
}
var domainHelper = umbracoContext.GetDomainHelper(_siteDomainHelper);
// extract domainUri and path
// route is /<path> or <domainRootId>/<path>
var pos = route.IndexOf('/');
var path = pos == 0 ? route : route.Substring(pos);
var domainUri = pos == 0
? null
: domainHelper.DomainForNode(int.Parse(route.Substring(0, pos)), current, culture);
: DomainUtilities.DomainForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainHelper, int.Parse(route.Substring(0, pos)), current, culture);
// assemble the url from domainUri (maybe null) and path
var url = AssembleUrl(domainUri, path, current, mode).ToString();
@@ -84,15 +82,13 @@ namespace Umbraco.Web.Routing
if (node == null)
yield break;
var domainHelper = umbracoContext.GetDomainHelper(_siteDomainHelper);
// look for domains, walking up the tree
var n = node;
var domainUris = domainHelper.DomainsForNode(n.Id, current, false);
var domainUris = DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainHelper, n.Id, current, false);
while (domainUris == null && n != null) // n is null at root
{
n = n.Parent; // move to parent node
domainUris = n == null ? null : domainHelper.DomainsForNode(n.Id, current, excludeDefault: true);
domainUris = n == null ? null : DomainUtilities.DomainsForNode(umbracoContext.PublishedSnapshot.Domains, _siteDomainHelper, n.Id, current, excludeDefault: true);
}
// no domains = exit

View File

@@ -22,7 +22,7 @@ namespace Umbraco.Web.Routing
{
try
{
Uri = DomainHelper.ParseUriFromDomainName(Name, currentUri);
Uri = DomainUtilities.ParseUriFromDomainName(Name, currentUri);
}
catch (UriFormatException)
{

View File

@@ -2,29 +2,69 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Web.PublishedCache; // published snapshot
using Umbraco.Web.PublishedCache;
namespace Umbraco.Web.Routing
{
/// <summary>
/// Provides utilities to handle domains.
/// </summary>
public class DomainHelper
public static class DomainUtilities
{
private readonly IDomainCache _domainCache;
private readonly ISiteDomainHelper _siteDomainHelper;
#region Document Culture
public DomainHelper(IDomainCache domainCache, ISiteDomainHelper siteDomainHelper)
/// <summary>
/// Gets the culture assigned to a document by domains, in the context of a current Uri.
/// </summary>
/// <param name="contentId">The document identifier.</param>
/// <param name="contentPath">The document path.</param>
/// <param name="current">An optional current Uri.</param>
/// <param name="umbracoContext">An Umbraco context.</param>
/// <param name="siteDomainHelper">The site domain helper.</param>
/// <returns>The culture assigned to the document by domains.</returns>
/// <remarks>
/// <para>In 1:1 multilingual setup, a document contains several cultures (there is not
/// one document per culture), and domains, withing the context of a current Uri, assign
/// a culture to that document.</para>
/// </remarks>
internal static string GetCultureFromDomains(int contentId, string contentPath, Uri current, UmbracoContext umbracoContext, ISiteDomainHelper siteDomainHelper)
{
_domainCache = domainCache;
_siteDomainHelper = siteDomainHelper;
if (umbracoContext == null)
throw new InvalidOperationException("A current UmbracoContext is required.");
if (current == null)
current = umbracoContext.CleanedUmbracoUrl;
// get the published route, else the preview route
// if both are null then the content does not exist
var route = umbracoContext.Content.GetRouteById(contentId) ??
umbracoContext.Content.GetRouteById(true, contentId);
if (route == null)
return null;
var pos = route.IndexOf('/');
var domain = pos == 0
? null
: DomainForNode(umbracoContext.Domains, siteDomainHelper, int.Parse(route.Substring(0, pos)), current);
var rootContentId = domain?.ContentId ?? -1;
var wcDomain = FindWildcardDomainInPath(umbracoContext.Domains.GetAll(true), contentPath, rootContentId);
if (wcDomain != null) return wcDomain.Culture.Name;
if (domain != null) return domain.Culture.Name;
return umbracoContext.Domains.DefaultCulture;
}
#region Domain for Node
#endregion
#region Domain for Document
/// <summary>
/// Finds the domain for the specified node, if any, that best matches a specified uri.
/// </summary>
/// <param name="domainCache">A domain cache.</param>
/// <param name="siteDomainHelper">The site domain helper.</param>
/// <param name="nodeId">The node identifier.</param>
/// <param name="current">The uri, or null.</param>
/// <param name="culture">The culture, or null.</param>
@@ -35,14 +75,14 @@ namespace Umbraco.Web.Routing
/// <para>If culture is null, uses the default culture for the installation instead. Otherwise,
/// will try with the specified culture, else return null.</para>
/// </remarks>
internal DomainAndUri DomainForNode(int nodeId, Uri current, string culture = null)
internal static DomainAndUri DomainForNode(IDomainCache domainCache, ISiteDomainHelper siteDomainHelper, int nodeId, Uri current, string culture = null)
{
// be safe
if (nodeId <= 0)
return null;
// get the domains on that node
var domains = _domainCache.GetAssigned(nodeId, false).ToArray();
var domains = domainCache.GetAssigned(nodeId).ToArray();
// none?
if (domains.Length == 0)
@@ -50,37 +90,28 @@ namespace Umbraco.Web.Routing
// else filter
// it could be that none apply (due to culture)
return SelectDomain(domains, current, culture, _domainCache.DefaultCulture,
(cdomainAndUris, ccurrent, cculture, cdefaultCulture) => _siteDomainHelper.MapDomain(cdomainAndUris, ccurrent, cculture, cdefaultCulture));
}
/// <summary>
/// Gets a value indicating whether a specified node has domains.
/// </summary>
/// <param name="nodeId">The node identifier.</param>
/// <returns>True if the node has domains, else false.</returns>
internal bool NodeHasDomains(int nodeId)
{
return nodeId > 0 && _domainCache.GetAssigned(nodeId, false).Any();
return SelectDomain(domains, current, culture, domainCache.DefaultCulture, siteDomainHelper.MapDomain);
}
/// <summary>
/// Find the domains for the specified node, if any, that match a specified uri.
/// </summary>
/// <param name="domainCache">A domain cache.</param>
/// <param name="siteDomainHelper">The site domain helper.</param>
/// <param name="nodeId">The node identifier.</param>
/// <param name="current">The uri, or null.</param>
/// <param name="excludeDefault">A value indicating whether to exclude the current/default domain. True by default.</param>
/// <returns>The domains and their uris, that match the specified uri, else null.</returns>
/// <remarks>If at least a domain is set on the node then the method returns the domains that
/// best match the specified uri, else it returns null.</remarks>
internal IEnumerable<DomainAndUri> DomainsForNode(int nodeId, Uri current, bool excludeDefault = true)
internal static IEnumerable<DomainAndUri> DomainsForNode(IDomainCache domainCache, ISiteDomainHelper siteDomainHelper, int nodeId, Uri current, bool excludeDefault = true)
{
// be safe
if (nodeId <= 0)
return null;
// get the domains on that node
var domains = _domainCache.GetAssigned(nodeId, false).ToArray();
var domains = domainCache.GetAssigned(nodeId).ToArray();
// none?
if (domains.Length == 0)
@@ -90,7 +121,7 @@ namespace Umbraco.Web.Routing
var domainAndUris = SelectDomains(domains, current).ToArray();
// filter
return _siteDomainHelper.MapDomains(domainAndUris, current, excludeDefault, null, _domainCache.DefaultCulture).ToArray();
return siteDomainHelper.MapDomains(domainAndUris, current, excludeDefault, null, domainCache.DefaultCulture).ToArray();
}
#endregion
@@ -252,7 +283,7 @@ namespace Umbraco.Web.Routing
}
/// <summary>
/// Parses a domain name into a URI.
/// Parses a domain name into a URI.
/// </summary>
/// <param name="domainName">The domain name to parse</param>
/// <param name="currentUri">The currently requested URI. If the domain name is relative, the authority of URI will be used.</param>

View File

@@ -284,7 +284,7 @@ namespace Umbraco.Web.Routing
var defaultCulture = domainsCache.DefaultCulture;
// try to find a domain matching the current request
var domainAndUri = DomainHelper.SelectDomain(domains, request.Uri, defaultCulture: defaultCulture);
var domainAndUri = DomainUtilities.SelectDomain(domains, request.Uri, defaultCulture: defaultCulture);
// handle domain - always has a contentId and a culture
if (domainAndUri != null)
@@ -328,7 +328,7 @@ namespace Umbraco.Web.Routing
var nodePath = request.PublishedContent.Path;
_logger.Debug<PublishedRouter>("{TracePrefix}Path={NodePath}", tracePrefix, nodePath);
var rootNodeId = request.HasDomain ? request.Domain.ContentId : (int?)null;
var domain = DomainHelper.FindWildcardDomainInPath(request.UmbracoContext.PublishedSnapshot.Domains.GetAll(true), nodePath, rootNodeId);
var domain = DomainUtilities.FindWildcardDomainInPath(request.UmbracoContext.PublishedSnapshot.Domains.GetAll(true), nodePath, rootNodeId);
// always has a contentId and a culture
if (domain != null)

View File

@@ -1137,7 +1137,7 @@
<Compile Include="Routing\ContentFinderByUrlAlias.cs" />
<Compile Include="Routing\ContentFinderByIdPath.cs" />
<Compile Include="TypeLoaderExtensions.cs" />
<Compile Include="Routing\DomainHelper.cs" />
<Compile Include="Routing\DomainUtilities.cs" />
<Compile Include="Routing\PublishedRequest.cs" />
<Compile Include="Routing\IContentFinder.cs" />
<Compile Include="Properties\AssemblyInfo.cs">

View File

@@ -3,12 +3,10 @@ using System.Collections.Generic;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Runtime;
using Umbraco.Web.Security;
namespace Umbraco.Web
@@ -20,7 +18,6 @@ namespace Umbraco.Web
{
private readonly IGlobalSettings _globalSettings;
private readonly Lazy<IPublishedSnapshot> _publishedSnapshot;
private DomainHelper _domainHelper;
private string _previewToken;
private bool? _previewing;
@@ -107,9 +104,6 @@ namespace Umbraco.Web
/// </summary>
public IPublishedSnapshot PublishedSnapshot => _publishedSnapshot.Value;
// for unit tests
internal bool HasPublishedSnapshot => _publishedSnapshot.IsValueCreated;
/// <summary>
/// Gets the published content cache.
/// </summary>
@@ -162,20 +156,6 @@ namespace Umbraco.Web
/// </summary>
public IVariationContextAccessor VariationContextAccessor { get; }
/// <summary>
/// Creates and caches an instance of a DomainHelper
/// </summary>
/// <remarks>
/// We keep creating new instances of DomainHelper, it would be better if we didn't have to do that so instead we can
/// have one attached to the UmbracoContext. This method accepts an external ISiteDomainHelper otherwise the UmbracoContext
/// ctor will have to have another parameter added only for this one method which is annoying and doesn't make a ton of sense
/// since the UmbracoContext itself doesn't use this.
///
/// TODO: The alternative is to have a IDomainHelperAccessor singleton which is cached per UmbracoContext
/// </remarks>
internal DomainHelper GetDomainHelper(ISiteDomainHelper siteDomainHelper)
=> _domainHelper ?? (_domainHelper = new DomainHelper(PublishedSnapshot.Domains, siteDomainHelper));
/// <summary>
/// Gets a value indicating whether the request has debugging enabled
/// </summary>

View File

@@ -809,11 +809,5 @@ namespace Umbraco.Web
}
#endregion
}
}