2016-05-26 17:12:04 +02:00
using System.Collections.Generic ;
using System.Globalization ;
using System.Linq ;
using Umbraco.Web.Routing ;
using Umbraco.Core ;
using Umbraco.Core.Services ;
namespace Umbraco.Web.PublishedCache.XmlPublishedCache
{
2018-04-24 13:07:18 +10:00
internal class DomainCache : IDomainCache
2016-05-26 17:12:04 +02:00
{
private readonly IDomainService _domainService ;
2018-04-30 21:29:49 +02:00
public DomainCache ( IDomainService domainService , IDefaultCultureAccessor defaultCultureAccessor )
2016-05-26 17:12:04 +02:00
{
_domainService = domainService ;
2018-04-30 21:29:49 +02:00
DefaultCulture = defaultCultureAccessor . DefaultCulture ;
2016-05-26 17:12:04 +02:00
}
2018-05-02 14:52:00 +10:00
/// <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
/// </summary>
/// <param name="includeWildcards"></param>
/// <returns></returns>
2016-05-26 17:12:04 +02:00
public IEnumerable < Domain > GetAll ( bool includeWildcards )
{
return _domainService . GetAll ( includeWildcards )
. Where ( x = > x . RootContentId . HasValue & & x . LanguageIsoCode . IsNullOrWhiteSpace ( ) = = false )
2018-04-26 16:03:08 +02:00
. Select ( x = > new Domain ( x . Id , x . DomainName , x . RootContentId . Value , CultureInfo . GetCultureInfo ( x . LanguageIsoCode ) , x . IsWildcard ) ) ;
2016-05-26 17:12:04 +02:00
}
2018-05-02 14:52:00 +10:00
/// <summary>
/// Returns all assigned <see cref="Domain"/> for the content id specified even if the content item is not published
/// </summary>
/// <param name="contentId"></param>
/// <param name="includeWildcards"></param>
/// <returns></returns>
2016-05-26 17:12:04 +02:00
public IEnumerable < Domain > GetAssigned ( int contentId , bool includeWildcards )
{
return _domainService . GetAssignedDomains ( contentId , includeWildcards )
. Where ( x = > x . RootContentId . HasValue & & x . LanguageIsoCode . IsNullOrWhiteSpace ( ) = = false )
2018-04-26 16:03:08 +02:00
. Select ( x = > new Domain ( x . Id , x . DomainName , x . RootContentId . Value , CultureInfo . GetCultureInfo ( x . LanguageIsoCode ) , x . IsWildcard ) ) ;
2016-05-26 17:12:04 +02:00
}
2018-04-26 16:03:08 +02:00
public string DefaultCulture { get ; }
2016-05-26 17:12:04 +02:00
}
}