/// <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 void FindPublishedContent()
        {
            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 <PublishedContentRequestEngine>(
                       string.Format("{0}Begin finders", tracePrefix),
                       string.Format("{0}End finders, {1}", tracePrefix, (_pcr.HasPublishedContent ? "a document was found" : "no document was found"))))
            {
                if (_routingContext.PublishedContentFinders == null)
                {
                    throw new InvalidOperationException("There is no finder collection.");
                }

                //iterate but return on first one that finds it
                var found = _routingContext.PublishedContentFinders.Any(finder => finder.TryFindContent(_pcr));
            }

            // indicate that the published content (if any) we have at the moment is the
            // one that was found by the standard finders before anything else took place.
            _pcr.SetIsInitialPublishedContent();
        }
Example #2
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 FindPublishedContentAsync()
        {
            //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

            if (_routingContext.PublishedContentFinders == null)
            {
                throw new InvalidOperationException("There is no finder collection.");
            }

            //iterate but return on first one that finds it
            foreach (var publishedContentFinder in _routingContext.PublishedContentFinders)
            {
                if (await publishedContentFinder.TryFindContentAsync(_pcr))
                {
                    break;
                }
            }

            // indicate that the published content (if any) we have at the moment is the
            // one that was found by the standard finders before anything else took place.
            _pcr.SetIsInitialPublishedContent();
        }