U4-3753 - refactor
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Web.Models
|
||||
@@ -18,10 +19,30 @@ namespace Umbraco.Web.Models
|
||||
/// <returns>The culture that would be selected to render the content.</returns>
|
||||
public static CultureInfo GetCulture(this IContent content, Uri current = null)
|
||||
{
|
||||
var route = UmbracoContext.Current.ContentCache.GetRouteById(content.Id); // cached
|
||||
return GetCulture(UmbracoContext.Current,
|
||||
ApplicationContext.Current.Services.DomainService, ApplicationContext.Current.Services.LocalizationService,
|
||||
content.Id, content.Path,
|
||||
current);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the culture that would be selected to render a specified content,
|
||||
/// within the context of a specified current request.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">An <see cref="UmbracoContext"/> instance.</param>
|
||||
/// <param name="domainService">An <see cref="IDomainService"/> implementation.</param>
|
||||
/// <param name="localizationService">An <see cref="ILocalizationService"/> implementation.</param>
|
||||
/// <param name="contentId">The content identifier.</param>
|
||||
/// <param name="contentPath">The content path.</param>
|
||||
/// <param name="current">The request Uri.</param>
|
||||
/// <returns>The culture that would be selected to render the content.</returns>
|
||||
public static CultureInfo GetCulture(UmbracoContext umbracoContext, IDomainService domainService, ILocalizationService localizationService,
|
||||
int contentId, string contentPath, Uri current)
|
||||
{
|
||||
var route = umbracoContext.ContentCache.GetRouteById(contentId); // cached
|
||||
var pos = route.IndexOf('/');
|
||||
|
||||
var domainHelper = new DomainHelper(ApplicationContext.Current.Services.DomainService);
|
||||
var domainHelper = new DomainHelper(domainService);
|
||||
|
||||
var domain = pos == 0
|
||||
? null
|
||||
@@ -29,11 +50,11 @@ namespace Umbraco.Web.Models
|
||||
|
||||
if (domain == null)
|
||||
{
|
||||
var defaultLanguage = ApplicationContext.Current.Services.LocalizationService.GetAllLanguages().FirstOrDefault();
|
||||
var defaultLanguage = localizationService.GetAllLanguages().FirstOrDefault();
|
||||
return defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.IsoCode);
|
||||
}
|
||||
|
||||
var wcDomain = DomainHelper.FindWildcardDomainInPath(ApplicationContext.Current.Services.DomainService.GetAll(true), content.Path, domain.RootContent.Id);
|
||||
var wcDomain = DomainHelper.FindWildcardDomainInPath(domainService.GetAll(true), contentPath, domain.RootContent.Id);
|
||||
return wcDomain == null
|
||||
? new CultureInfo(domain.Language.IsoCode)
|
||||
: new CultureInfo(wcDomain.Language.IsoCode);
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Web;
|
||||
using Examine.LuceneEngine.SearchCriteria;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Web.Routing;
|
||||
@@ -1896,27 +1897,12 @@ namespace Umbraco.Web
|
||||
/// <returns>The culture that would be selected to render the content.</returns>
|
||||
public static CultureInfo GetCulture(this IPublishedContent content, Uri current = null)
|
||||
{
|
||||
var route = UmbracoContext.Current.ContentCache.GetRouteById(content.Id); // cached
|
||||
var pos = route.IndexOf('/');
|
||||
|
||||
var domainHelper = new DomainHelper(ApplicationContext.Current.Services.DomainService);
|
||||
|
||||
var domain = pos == 0
|
||||
? null
|
||||
: domainHelper.DomainForNode(int.Parse(route.Substring(0, pos)), current).UmbracoDomain;
|
||||
|
||||
if (domain == null)
|
||||
{
|
||||
var defaultLanguage = ApplicationContext.Current.Services.LocalizationService.GetAllLanguages().FirstOrDefault();
|
||||
return defaultLanguage == null ? CultureInfo.CurrentUICulture : new CultureInfo(defaultLanguage.IsoCode);
|
||||
}
|
||||
|
||||
var wcDomain = DomainHelper.FindWildcardDomainInPath(ApplicationContext.Current.Services.DomainService.GetAll(true), content.Path, domain.RootContent.Id);
|
||||
return wcDomain == null
|
||||
? new CultureInfo(domain.Language.IsoCode)
|
||||
: new CultureInfo(wcDomain.Language.IsoCode);
|
||||
return Models.ContentExtensions.GetCulture(UmbracoContext.Current,
|
||||
ApplicationContext.Current.Services.DomainService, ApplicationContext.Current.Services.LocalizationService,
|
||||
content.Id, content.Path,
|
||||
current);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,6 +281,7 @@
|
||||
<Compile Include="ITagQuery.cs" />
|
||||
<Compile Include="ITypedPublishedContentQuery.cs" />
|
||||
<Compile Include="IUmbracoComponentRenderer.cs" />
|
||||
<Compile Include="Models\ContentExtensions.cs" />
|
||||
<Compile Include="Models\LegacyConvertedNode.cs" />
|
||||
<Compile Include="Models\LegacyConvertedNodeProperty.cs" />
|
||||
<Compile Include="Models\Mapping\RelationModelMapper.cs" />
|
||||
|
||||
Reference in New Issue
Block a user