public DefaultUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper)
 {
     _requestSettings  = requestSettings;
     _logger           = logger;
     _globalSettings   = globalSettings;
     _siteDomainHelper = siteDomainHelper;
 }
        // initialize a PublishedContentCache instance with
        // an XmlStore containing the master xml
        // an IAppCache that should be at request-level
        // a RoutesCache - need to cleanup that one
        // a preview token string (or null if not previewing)
        public PublishedContentCache(
            XmlStore xmlStore,        // an XmlStore containing the master xml
            IDomainCache domainCache, // an IDomainCache implementation
            IAppCache appCache,       // an IAppCache that should be at request-level
            IGlobalSettings globalSettings,
            ISiteDomainHelper siteDomainHelper,
            IUmbracoContextAccessor umbracoContextAccessor,
            PublishedContentTypeCache contentTypeCache, // a PublishedContentType cache
            RoutesCache routesCache,                    // a RoutesCache
            string previewToken)                        // a preview token string (or null if not previewing)
            : base(previewToken.IsNullOrWhiteSpace() == false)
        {
            _appCache               = appCache;
            _globalSettings         = globalSettings;
            _umbracoContextAccessor = umbracoContextAccessor;
            _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

            if (previewToken.IsNullOrWhiteSpace() == false)
            {
                _previewContent = new PreviewContent(_xmlStore, previewToken);
            }
        }
        private PublishedSnapshotService(ServiceContext serviceContext,
                                         IPublishedContentTypeFactory publishedContentTypeFactory,
                                         IScopeProvider scopeProvider,
                                         ICacheProvider requestCache,
                                         IEnumerable <IUrlSegmentProvider> segmentProviders,
                                         IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
                                         IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
                                         IDefaultCultureAccessor defaultCultureAccessor,
                                         ILogger logger,
                                         IGlobalSettings globalSettings,
                                         ISiteDomainHelper siteDomainHelper,
                                         PublishedContentTypeCache contentTypeCache,
                                         MainDom mainDom,
                                         bool testing, bool enableRepositoryEvents)
            : base(publishedSnapshotAccessor, variationContextAccessor)
        {
            _routesCache = new RoutesCache();
            _publishedContentTypeFactory = publishedContentTypeFactory;
            _contentTypeCache            = contentTypeCache
                                           ?? new PublishedContentTypeCache(serviceContext.ContentTypeService, serviceContext.MediaTypeService, serviceContext.MemberTypeService, publishedContentTypeFactory, logger);

            _xmlStore = new XmlStore(serviceContext, scopeProvider, _routesCache,
                                     _contentTypeCache, segmentProviders, publishedSnapshotAccessor, mainDom, testing, enableRepositoryEvents,
                                     documentRepository, mediaRepository, memberRepository, globalSettings);

            _domainService          = serviceContext.DomainService;
            _memberService          = serviceContext.MemberService;
            _mediaService           = serviceContext.MediaService;
            _userService            = serviceContext.UserService;
            _defaultCultureAccessor = defaultCultureAccessor;

            _requestCache     = requestCache;
            _globalSettings   = globalSettings;
            _siteDomainHelper = siteDomainHelper;
        }
 // used in some tests
 internal PublishedSnapshotService(ServiceContext serviceContext,
                                   IPublishedContentTypeFactory publishedContentTypeFactory,
                                   IScopeProvider scopeProvider,
                                   ICacheProvider requestCache,
                                   IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
                                   IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
                                   IDefaultCultureAccessor defaultCultureAccessor,
                                   ILogger logger,
                                   IGlobalSettings globalSettings,
                                   ISiteDomainHelper siteDomainHelper,
                                   PublishedContentTypeCache contentTypeCache,
                                   MainDom mainDom,
                                   bool testing, bool enableRepositoryEvents)
     : this(serviceContext, publishedContentTypeFactory, scopeProvider, requestCache, Enumerable.Empty <IUrlSegmentProvider>(),
            publishedSnapshotAccessor, variationContextAccessor,
            documentRepository, mediaRepository, memberRepository,
            defaultCultureAccessor,
            logger, globalSettings, siteDomainHelper, contentTypeCache, mainDom, testing, enableRepositoryEvents)
 {
 }
Ejemplo n.º 5
0
        /// <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>
        /// <returns>The domain and its uri, if any, that best matches the specified uri and culture, else null.</returns>
        /// <remarks>
        /// <para>If at least a domain is set on the node then the method returns the domain that
        /// best matches the specified uri and culture, else it returns null.</para>
        /// <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 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).ToArray();

            // none?
            if (domains.Length == 0)
            {
                return(null);
            }

            // else filter
            // it could be that none apply (due to culture)
            return(SelectDomain(domains, current, culture, domainCache.DefaultCulture, siteDomainHelper.MapDomain));
        }
Ejemplo n.º 6
0
 // used in WebBootManager + tests
 public XmlPublishedSnapshotService(ServiceContext serviceContext,
                                    IPublishedContentTypeFactory publishedContentTypeFactory,
                                    IScopeProvider scopeProvider,
                                    IAppCache requestCache,
                                    IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
                                    IUmbracoContextAccessor umbracoContextAccessor,
                                    IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
                                    IDefaultCultureAccessor defaultCultureAccessor,
                                    ILogger logger,
                                    IGlobalSettings globalSettings,
                                    ISiteDomainHelper siteDomainHelper,
                                    IEntityXmlSerializer entitySerializer,
                                    MainDom mainDom,
                                    bool testing = false, bool enableRepositoryEvents = true)
     : this(serviceContext, publishedContentTypeFactory, scopeProvider, requestCache,
            publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor,
            documentRepository, mediaRepository, memberRepository,
            defaultCultureAccessor,
            logger, globalSettings, siteDomainHelper, entitySerializer, null, mainDom, testing, enableRepositoryEvents)
 {
     _umbracoContextAccessor = umbracoContextAccessor;
 }
Ejemplo n.º 7
0
 public DomainHelper(IDomainCache domainCache, ISiteDomainHelper siteDomainHelper)
 {
     _domainCache      = domainCache;
     _siteDomainHelper = siteDomainHelper;
 }
 public DateFormattedUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper)
     : base(requestSettings, logger, globalSettings, siteDomainHelper)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="publishedSnapshotAccessor">The current published snapshot accessor.</param>
 /// <param name="siteDomainHelper">The current site domain helper.</param>
 public SpaDomainRepository(IPublishedSnapshotAccessor publishedSnapshotAccessor, ISiteDomainHelper siteDomainHelper)
 {
     _publishedSnapshotAccessor = publishedSnapshotAccessor;
     _siteDomainHelper          = siteDomainHelper;
 }
Ejemplo n.º 10
0
 /// <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>
 /// Sets the site domain helper.
 /// </summary>
 /// <param name="composition">The composition.</param>
 /// <param name="helper">A helper.</param>
 public static void SetSiteDomainHelper(this Composition composition, ISiteDomainHelper helper)
 {
     composition.RegisterUnique(_ => helper);
 }
Ejemplo n.º 12
0
 public AliasUrlProvider(IGlobalSettings globalSettings, IRequestHandlerSection requestConfig, ISiteDomainHelper siteDomainHelper)
 {
     _globalSettings   = globalSettings;
     _requestConfig    = requestConfig;
     _siteDomainHelper = siteDomainHelper;
 }
Ejemplo n.º 13
0
        /// <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)
        {
            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);
        }
Ejemplo n.º 14
0
        /// <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 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).ToArray();

            // none?
            if (domains.Length == 0)
            {
                return(null);
            }

            // get the domains and their uris
            var domainAndUris = SelectDomains(domains, current).ToArray();

            // filter
            return(siteDomainHelper.MapDomains(domainAndUris, current, excludeDefault, null, domainCache.DefaultCulture).ToArray());
        }
Ejemplo n.º 15
0
 public VirtualNodesUrlProvider(IRequestHandlerSection requestSettings, ILogger logger, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper)
     : base(requestSettings, logger, globalSettings, siteDomainHelper)
 {
     _requestSettings = requestSettings;
 }