示例#1
0
        /// <summary>
        /// Tries to find the document matching the request, by running the IPublishedContentFinder instances.
        /// </summary>
        /// <exception cref="InvalidOperationException">There is no finder collection.</exception>
        internal bool FindPublishedContent(IPublishedRequestBuilder request)
        {
            const string tracePrefix = "FindPublishedContent: ";

            // look for the document
            // the first successful finder, if any, will set this.PublishedContent, and may also set this.Template
            // some finders may implement caching
            using (_profilingLogger.DebugDuration <PublishedRouter>(
                       $"{tracePrefix}Begin finders",
                       $"{tracePrefix}End finders"))
            {
                // iterate but return on first one that finds it
                var found = _contentFinders.Any(finder =>
                {
                    _logger.LogDebug("Finder {ContentFinderType}", finder.GetType().FullName);
                    return(finder.TryFindContent(request));
                });

                _logger.LogDebug(
                    "Found? {Found}, Content: {PublishedContentId}, Template: {TemplateAlias}, Domain: {Domain}, Culture: {Culture}, StatusCode: {StatusCode}",
                    found,
                    request.HasPublishedContent() ? request.PublishedContent.Id : "NULL",
                    request.HasTemplate() ? request.Template?.Alias : "NULL",
                    request.HasDomain() ? request.Domain.ToString() : "NULL",
                    request.Culture ?? "NULL",
                    request.ResponseStatusCode);

                return(found);
            }
        }
示例#2
0
    private async Task RouteRequestInternalAsync(IPublishedRequestBuilder builder, bool skipContentFinders = false)
    {
        // if request builder was already flagged to redirect then return
        // whoever called us is in charge of actually redirecting
        if (builder.IsRedirect())
        {
            return;
        }

        // set the culture
        SetVariationContext(builder.Culture);

        var foundContentByFinders = false;

        // Find the published content if it's not assigned.
        // This could be manually assigned with a custom route handler, etc...
        // which in turn could call this method
        // to setup the rest of the pipeline but we don't want to run the finders since there's one assigned.
        if (!builder.HasPublishedContent() && !skipContentFinders)
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug("FindPublishedContentAndTemplate: Path={UriAbsolutePath}", builder.Uri.AbsolutePath);
            }

            // run the document finders
            foundContentByFinders = await FindPublishedContent(builder);
        }

        // if we are not a redirect
        if (!builder.IsRedirect())
        {
            // handle not-found, redirects, access...
            await HandlePublishedContent(builder);

            // find a template
            FindTemplate(builder, foundContentByFinders);

            // handle umbracoRedirect
            FollowExternalRedirect(builder);

            // handle wildcard domains
            HandleWildcardDomains(builder);

            // set the culture  -- again, 'cos it might have changed due to a finder or wildcard domain
            SetVariationContext(builder.Culture);
        }

        // trigger the routing request (used to be called Prepared) event - at that point it is still possible to change about anything
        // even though the request might be flagged for redirection - we'll redirect _after_ the event
        var routingRequest = new RoutingRequestNotification(builder);
        await _eventAggregator.PublishAsync(routingRequest);

        // we don't take care of anything so if the content has changed, it's up to the user
        // to find out the appropriate template
    }
示例#3
0
    /// <summary>
    ///     Tries to find the document matching the request, by running the IPublishedContentFinder instances.
    /// </summary>
    /// <exception cref="InvalidOperationException">There is no finder collection.</exception>
    internal async Task <bool> FindPublishedContent(IPublishedRequestBuilder request)
    {
        const string tracePrefix = "FindPublishedContent: ";

        // look for the document
        // the first successful finder, if any, will set this.PublishedContent, and may also set this.Template
        // some finders may implement caching
        DisposableTimer?profilingScope = null;

        try
        {
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                profilingScope = _profilingLogger.DebugDuration <PublishedRouter>(
                    $"{tracePrefix}Begin finders",
                    $"{tracePrefix}End finders");
            }

            // iterate but return on first one that finds it
            var found = false;
            foreach (IContentFinder contentFinder in _contentFinders)
            {
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug("Finder {ContentFinderType}", contentFinder.GetType().FullName);
                }

                found = await contentFinder.TryFindContent(request);

                if (found)
                {
                    break;
                }
            }

            if (_logger.IsEnabled(LogLevel.Debug))
            {
                _logger.LogDebug(
                    "Found? {Found}, Content: {PublishedContentId}, Template: {TemplateAlias}, Domain: {Domain}, Culture: {Culture}, StatusCode: {StatusCode}",
                    found,
                    request.HasPublishedContent() ? request.PublishedContent?.Id : "NULL",
                    request.HasTemplate() ? request.Template?.Alias : "NULL",
                    request.HasDomain() ? request.Domain?.ToString() : "NULL",
                    request.Culture ?? "NULL",
                    request.ResponseStatusCode);
            }

            return(found);
        }
        finally
        {
            profilingScope?.Dispose();
        }
    }
示例#4
0
    /// <summary>
    ///     This method finalizes/builds the PCR with the values assigned.
    /// </summary>
    /// <returns>
    ///     Returns false if the request was not successfully configured
    /// </returns>
    /// <remarks>
    ///     This method logic has been put into it's own method in case developers have created a custom PCR or are assigning
    ///     their own values
    ///     but need to finalize it themselves.
    /// </remarks>
    internal IPublishedRequest BuildRequest(IPublishedRequestBuilder builder)
    {
        IPublishedRequest result = builder.Build();

        if (!builder.HasPublishedContent())
        {
            return(result);
        }

        // set the culture -- again, 'cos it might have changed in the event handler
        SetVariationContext(result.Culture);

        return(result);
    }
示例#5
0
    private async Task <IPublishedRequest> TryRouteRequest(IPublishedRequestBuilder request)
    {
        FindDomain(request);

        if (request.IsRedirect())
        {
            return(request.Build());
        }

        if (request.HasPublishedContent())
        {
            return(request.Build());
        }

        await FindPublishedContent(request);

        return(request.Build());
    }
示例#6
0
        private IPublishedRequest TryRouteRequest(IPublishedRequestBuilder request)
        {
            FindDomain(request);

            if (request.IsRedirect())
            {
                return(request.Build());
            }

            if (request.HasPublishedContent())
            {
                return(request.Build());
            }

            FindPublishedContent(request);

            return(request.Build());
        }