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
{
internal class DomainCache : IDomainCache
{
private readonly IDomainService _domainService;
public DomainCache(IDomainService domainService, IDefaultCultureAccessor defaultCultureAccessor)
{
_domainService = domainService;
DefaultCulture = defaultCultureAccessor.DefaultCulture;
}
///
/// Returns all in the current domain cache including any domains that may be referenced by content items that are no longer published
///
///
///
public IEnumerable GetAll(bool includeWildcards)
{
return _domainService.GetAll(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));
}
///
/// Returns all assigned for the content id specified even if the content item is not published
///
///
///
///
public IEnumerable GetAssigned(int contentId, bool includeWildcards)
{
return _domainService.GetAssignedDomains(contentId, 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));
}
public string DefaultCulture { get; }
}
}