/// <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); } }
/// <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(); } }