private PageRoutingHelper CreatePageRoutingHelper(int pageId, int pageVersionId, VisualEditorMode siteViewerMode) { var allRoutes = _queryExecutor.GetAll <PageRoute>(); var allDirectories = _queryExecutor.GetAll <WebDirectoryRoute>(); var currentRoute = allRoutes.Single(p => p.PageId == pageId); var router = new PageRoutingHelper(allRoutes, allDirectories, currentRoute, siteViewerMode, pageVersionId); return(router); }
private async Task <PageRoute[]> GetAllPageRoutesAsync(GetAllQuery <PageRoute> query, IExecutionContext executionContext) { var dbPages = await QueryPages().ToListAsync(); var dbPageVersions = await QueryPageVersions().ToListAsync(); var webDirectories = _queryExecutor.GetAll <WebDirectoryRoute>(executionContext).ToDictionary(d => d.WebDirectoryId); var templates = await GetPageTemplates().ToDictionaryAsync(t => t.PageTemplateId); var routes = Map(dbPages, dbPageVersions, webDirectories, templates, executionContext); return(routes.ToArray()); }
private IDictionary <int, IEnumerable <PageRoutingInfo> > Map(IExecutionContext executionContext, List <IdQueryResult> idSets, Dictionary <int, CustomEntityRoute> customEntityRoutes, IDictionary <int, PageRoute> pageRoutes) { var allRules = _queryExecutor.GetAll <ICustomEntityRoutingRule>(executionContext); var result = new List <PageRoutingInfo>(idSets.Count); foreach (var idSet in idSets) { var routingInfo = new PageRoutingInfo(); routingInfo.PageRoute = pageRoutes.GetOrDefault(idSet.PageId); EntityNotFoundException.ThrowIfNull(routingInfo.PageRoute, idSet.PageId); routingInfo.CustomEntityRoute = customEntityRoutes.GetOrDefault(idSet.CustomEntityId); EntityNotFoundException.ThrowIfNull(routingInfo.CustomEntityRoute, idSet.PageId); routingInfo.CustomEntityRouteRule = allRules.FirstOrDefault(r => r.RouteFormat == routingInfo.PageRoute.UrlPath); result.Add(routingInfo); } return(result .GroupBy(r => r.CustomEntityRoute.CustomEntityId) .ToDictionary(g => g.Key, g => g.AsEnumerable())); }
/// <summary> /// Finishes off bulk mapping of tags and page routes in a PageSummary object /// </summary> public void Map(IEnumerable <PageSummary> pages) { var routes = _queryExecutor.GetAll <PageRoute>(); var ids = pages .Select(p => p.PageId) .ToArray(); var pageTags = _dbContext .PageTags .AsNoTracking() .Where(p => ids.Contains(p.PageId)) .Select(t => new { PageId = t.PageId, Tag = t.Tag.TagText }) .ToList(); foreach (var page in pages) { var pageRoute = routes.SingleOrDefault(r => r.PageId == page.PageId); EntityNotFoundException.ThrowIfNull(pageRoute, page.PageId); Mapper.Map(pageRoute, page); page.Tags = pageTags .Where(t => t.PageId == page.PageId) .Select(t => t.Tag) .ToArray(); } }
public PageRoute Execute(GetByIdQuery <PageRoute> query, IExecutionContext executionContext) { var result = _queryExecutor .GetAll <PageRoute>() .SingleOrDefault(p => p.PageId == query.Id); return(result); }
public ActiveLocale Execute(GetByIdQuery <ActiveLocale> query, IExecutionContext executionContext) { var result = _queryExecutor .GetAll <ActiveLocale>() .SingleOrDefault(l => l.LocaleId == query.Id); return(result); }
public IEnumerable <PageRoute> Execute(GetPageRoutesByWebDirectoryIdQuery query, IExecutionContext executionContext) { var result = _queryExecutor .GetAll <PageRoute>(executionContext) .Where(p => p.WebDirectory.WebDirectoryId == query.WebDirectoryId); return(result); }
public WebDirectoryRoute Execute(GetByIdQuery <WebDirectoryRoute> query, IExecutionContext executionContext) { var result = _queryExecutor .GetAll <WebDirectoryRoute>() .SingleOrDefault(l => l.WebDirectoryId == query.Id); return(result); }
private PageRoutingHelper CreatePageRoutingHelper( PageViewModelBuilderParameters mappingParameters ) { var allRoutes = _queryExecutor.GetAll <PageRoute>(); var allDirectories = _queryExecutor.GetAll <WebDirectoryRoute>(); var currentRoute = allRoutes.Single(p => p.PageId == mappingParameters.PageModel.PageId); var router = new PageRoutingHelper( allRoutes, allDirectories, currentRoute, mappingParameters.VisualEditorMode, mappingParameters.PageModel.PageVersionId ); return(router); }
public IDictionary <int, PageRoute> Execute(GetByIdRangeQuery <PageRoute> query, IExecutionContext executionContext) { var result = _queryExecutor .GetAll <PageRoute>(executionContext) .Where(r => query.Ids.Contains(r.PageId)) .ToDictionary(r => r.PageId); return(result); }
public async Task <PageRoutingInfo> ExecuteAsync(GetPageRoutingInfoByPathQuery query, IExecutionContext executionContext) { // Deal with malformed query if (!string.IsNullOrWhiteSpace(query.Path) && !Uri.IsWellFormedUriString(query.Path, UriKind.Relative)) { return(null); } var path = _pathHelper.StandardisePath(query.Path); var allRoutes = await _queryExecutor.GetAllAsync <PageRoute>(executionContext); // Rather than starts with, do a regex replacement here with the path // E.g. /styuff/{slug} is not matching /styff/winterlude var pageRoutes = allRoutes .Where(r => r.FullPath.Equals(path) || (r.PageType == PageType.CustomEntityDetails && IsCustomRoutingMatch(path, r.FullPath))) .Where(r => query.IncludeUnpublished || r.IsPublished) .Where(r => r.Locale == null || MatchesLocale(r.Locale, query.LocaleId)) .OrderByDescending(r => r.FullPath.Equals(path)) .ThenByDescending(r => MatchesLocale(r.Locale, query.LocaleId)) .ToList(); PageRoutingInfo result = null; // Exact match if (pageRoutes.Any() && pageRoutes[0].PageType != PageType.CustomEntityDetails) { result = ToRoutingInfo(pageRoutes[0]); } else { var allRules = _queryExecutor.GetAll <ICustomEntityRoutingRule>(executionContext); // I'm only anticipating a single rule to match at the moment, but eventually there might be multiple rules to match e.g. categories page foreach (var pageRoute in pageRoutes) { // Find a routing rule, matching higher priorities first var rule = allRules .Where(r => r.MatchesRule(query.Path, pageRoute)) .OrderBy(r => r.Priority) .ThenBy(r => r.RouteFormat.Length) .FirstOrDefault(); if (rule != null) { var customEntityRouteQuery = rule.ExtractRoutingQuery(query.Path, pageRoute); var customEntityRoute = await _queryExecutor.ExecuteAsync(customEntityRouteQuery, executionContext); if (customEntityRoute != null && (query.IncludeUnpublished || customEntityRoute.Versions.HasPublishedVersion())) { return(ToRoutingInfo(pageRoute, customEntityRoute, rule)); } } } } return(result); }
public IEnumerable <CustomEntityRenderSummary> MapSummaries( ICollection <CustomEntityVersion> dbResults, IExecutionContext executionContext) { var routingsQuery = GetPageRoutingQuery(dbResults); var allRoutings = _queryExecutor.Execute(routingsQuery, executionContext); var allLocales = _queryExecutor.GetAll <ActiveLocale>(executionContext); return(Map(dbResults, allRoutings, allLocales)); }
public CustomEntityRenderDetails Execute(GetCustomEntityRenderDetailsByIdQuery query, IExecutionContext executionContext) { var dbResult = QueryCustomEntity(query).FirstOrDefault(); var entity = MapCustomEntity(dbResult); entity.Sections = QuerySections(query).ToList(); var dbModules = QueryModules(entity).ToList(); var allModuleTypes = _queryExecutor.GetAll <PageModuleTypeSummary>(executionContext); _entityVersionPageModuleMapper.MapSections(dbModules, entity.Sections, allModuleTypes, query.WorkFlowStatus); var routingQuery = new GetPageRoutingInfoByCustomEntityIdQuery(dbResult.CustomEntityId); var routing = _queryExecutor.Execute(routingQuery, executionContext); entity.DetailsPageUrls = MapPageRoutings(routing, dbResult); return(entity); }
public IEnumerable <PageSectionDetails> Execute(GetPageSectionDetailsByPageVersionIdQuery query, IExecutionContext executionContext) { var sections = GetSections(query).ToList(); var dbModules = QueryModules(query).ToList(); var allModuleTypes = _queryExecutor.GetAll <PageModuleTypeSummary>(executionContext); MapSections(sections, dbModules, allModuleTypes); return(sections); }
public ActiveLocale Execute(GetActiveLocaleByIETFLanguageTagQuery query, IExecutionContext executionContext) { if (!IsTagValid(query.IETFLanguageTag)) { return(null); } var result = _queryExecutor .GetAll <ActiveLocale>() .SingleOrDefault(l => l.IETFLanguageTag.Equals(query.IETFLanguageTag, StringComparison.OrdinalIgnoreCase)); return(result); }
public IDictionary <int, PageRenderDetails> Execute(GetPageRenderDetailsByIdRangeQuery query, IExecutionContext executionContext) { var dbPages = QueryPages(query).ToList(); var pages = Mapper.Map <List <PageRenderDetails> >(dbPages); var pageRoutes = _queryExecutor.GetByIdRange <PageRoute>(GetAllPageIds(pages), executionContext); MapPageRoutes(pages, pageRoutes); var dbModules = QueryModules(pages).ToList(); var allModuleTypes = _queryExecutor.GetAll <PageModuleTypeSummary>(executionContext); _entityVersionPageModuleMapper.MapSections(dbModules, pages.SelectMany(p => p.Sections), allModuleTypes, query.WorkFlowStatus); return(pages.ToDictionary(d => d.PageId)); }
public PageRenderDetails Execute(GetPageRenderDetailsByIdQuery query, IExecutionContext executionContext) { var dbPage = QueryPage(query).FirstOrDefault(); if (dbPage == null) { return(null); } var page = Mapper.Map <PageRenderDetails>(dbPage); page.PageRoute = _queryExecutor.GetById <PageRoute>(page.PageId, executionContext); var dbModules = QueryModules(page).ToList(); var allModuleTypes = _queryExecutor.GetAll <PageModuleTypeSummary>(executionContext); _entityVersionPageModuleMapper.MapSections(dbModules, page.Sections, allModuleTypes, query.WorkFlowStatus); return(page); }
public CustomEntityDefinitionMicroSummary Execute(GetCustomEntityDefinitionMicroSummaryByDisplayModelTypeQuery query, IExecutionContext executionContext) { var dataModelType = query.DisplayModelType .GetInterfaces() .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(ICustomEntityDisplayModel <>)) .Select(i => i.GetGenericArguments().Single()) .SingleOrDefault(); if (dataModelType == null) { throw new ArgumentException("query.DisplayModelType is not of type ICustomEntityDisplayModel<>"); } var definition = _queryExecutor .GetAll <CustomEntityDefinitionSummary>(executionContext) .FirstOrDefault(d => d.DataModelType == dataModelType); var microSummary = Mapper.Map <CustomEntityDefinitionMicroSummary>(definition); return(microSummary); }
public IEnumerable <RewriteRuleSummary> GetAllRewriteRuleSummaries(IExecutionContext executionContext = null) { return(_queryExecutor.GetAll <RewriteRuleSummary>(executionContext)); }
public RewriteRuleSummary Execute(GetRewriteRuleByPathQuery query, IExecutionContext executionContext) { var rules = _queryExecutor.GetAll <RewriteRuleSummary>(); return(FindRule(query, rules)); }
/// <remarks> /// This has just been copied with slight modification from PagesController and /// needs to be refactored. /// </remarks> public IEnumerable <PageSearchResult> Execute(SearchPagesQuery query, IExecutionContext executionContext) { if (string.IsNullOrWhiteSpace(query.Text)) { yield break; } var isAuthenticated = executionContext.UserContext.UserId.HasValue; // TODO: Search results should look at page titles as well as module content // Find any page versions that match by title // TODO: Ignore small words like 'of' and 'the' var titleMatchesPageVersions = _dbContext .Pages .Where(p => !p.IsDeleted && p.PageVersions.Any(pv => !pv.IsDeleted && isAuthenticated ? true : pv.WorkFlowStatusId == (int)WorkFlowStatus.Published) && !query.LocaleId.HasValue || p.LocaleId == query.LocaleId && p.PageTypeId == (int)PageType.Generic ) .Select(p => p.PageVersions .OrderByDescending(v => v.CreateDate) .First(pv => !pv.IsDeleted && isAuthenticated ? true : pv.WorkFlowStatusId == (int)WorkFlowStatus.Published) ) .ToList() .Where(v => v.Title.Contains(query.Text) || v.Title.ToLower().Split(new char[] { ' ' }).Intersect(query.Text.ToLower().Split(new char[] { ' ' })).Any() ) ; // TODO: Search should split the search term and lookup individual words as well (and rank them less strongly) // Get a list of ALL the page modules for live pages - we'll search through these for any matches var pageModules = _dbContext .PageVersionModules .Include(m => m.PageModuleType) .Where(m => !m.PageVersion.IsDeleted) .Where(m => !m.PageVersion.Page.IsDeleted) .Where(m => isAuthenticated ? true : m.PageVersion.WorkFlowStatusId == (int)WorkFlowStatus.Published) .Where(m => !query.LocaleId.HasValue || m.PageVersion.Page.LocaleId == query.LocaleId) .Where(m => m.PageVersion.Page.PageTypeId == (int)PageType.Generic) .ToList(); // This will store a list of matches for each module var matches = new Dictionary <PageVersionModule, List <string> >(); foreach (var pageModule in pageModules.Where(p => !string.IsNullOrEmpty(query.Text))) { var dataProvider = _moduleDisplayDataFactory.MapDisplayModel(pageModule.PageModuleType.FileName, pageModule, WorkFlowStatusQuery.Published); Type dataProviderType = dataProvider.GetType(); // If this module is searchable - ie there is content to search // TODO: Module Searching //if (dataProvider is ISearchable) //{ var props = dataProviderType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(SearchableAttribute))); foreach (var prop in props) { string str = _htmlSanitizer.StripHtml(((string)prop.GetValue(dataProvider, null))); if (str.IndexOf(query.Text ?? "", StringComparison.InvariantCultureIgnoreCase) > -1) { if (!matches.ContainsKey(pageModule)) { matches[pageModule] = new List <string>(); } int index = str.ToLower().IndexOf(query.Text.ToLower()); int startIndex = index - 100; while (startIndex < 0) { startIndex++; } int length = (index - startIndex) + query.Text.Length + 100; while ((startIndex + length) > str.Length) { length--; } var matchStr = str.Substring(startIndex, length); // Stop the string at the last space if ((startIndex + length) < str.Length - 1 && matchStr.LastIndexOf(" ") > -1) { matchStr = matchStr.Substring(0, matchStr.LastIndexOf(" ")) + " …"; } // Stop the string at the first space if (startIndex > 0 && matchStr.IndexOf(" ") > -1) { matchStr = "… " + matchStr.Substring(matchStr.IndexOf(" ") + 1); } // Highlight the search term matchStr = Regex.Replace(matchStr, query.Text, @"<b>$0</b>", RegexOptions.IgnoreCase); matches[pageModule].Add(matchStr); } } //} } // This is a list of pageversions matches to the number of matches var pageVersionMatches = matches .OrderByDescending(m => m.Value.Count) .GroupBy(m => m.Key.PageVersion.PageVersionId) .ToDictionary( g => g.First().Key.PageVersion, g => g.First().Value.Select(m => (IHtmlString) new HtmlString(m)) ); // Add any pages matched by title to the list of matches foreach (var pageVersion in titleMatchesPageVersions) { if (!pageVersionMatches.ContainsKey(pageVersion)) { pageVersionMatches.Add(pageVersion, null); } } var searchResults = new List <PageSearchResult>(); var pageroutes = _queryExecutor.GetAll <PageRoute>(); foreach (var pageVersionMatch in pageVersionMatches .OrderByDescending(m => titleMatchesPageVersions.Contains(m.Key)) .ThenByDescending(m => m.Value == null ? 0 : m.Value.Count())) { var version = pageVersionMatch.Key; var route = pageroutes.SingleOrDefault(r => r.PageId == version.PageId); if (route != null) { var result = new PageSearchResult(); result.FoundText = pageVersionMatch.Value == null ? new HtmlString(version.MetaDescription) : pageVersionMatch.Value.First(); result.Title = version.Title; result.Url = route.FullPath; yield return(result); } } }
public IEnumerable <PageModuleTypeSummary> GetAllPageModuleTypeSummaries(IExecutionContext executionContext = null) { return(_queryExecutor.GetAll <PageModuleTypeSummary>(executionContext)); }
public IEnumerable <CustomEntityDefinitionMicroSummary> GetAllCustomEntityDefinitionMicroSummaries(IExecutionContext executionContext = null) { return(_queryExecutor.GetAll <CustomEntityDefinitionMicroSummary>(executionContext)); }
/// <summary> /// Returns all web directories as WebDirectoryRoute objects. The results of this query are cached. /// </summary> /// <param name="executionContext">Optional execution context to use when executing the query. Useful if you need to temporarily elevate your permission level.</param> public IEnumerable <WebDirectoryRoute> GetAllWebDirectoryRoutes(IExecutionContext executionContext = null) { return(_queryExecutor.GetAll <WebDirectoryRoute>(executionContext)); }
public IEnumerable <PageRoute> GetAllPageRoutes(IExecutionContext executionContext = null) { return(_queryExecutor.GetAll <PageRoute>(executionContext)); }
public PageModuleTypeSummary Execute(GetByIdQuery <PageModuleTypeSummary> query, IExecutionContext executionContext) { return(_queryExecutor .GetAll <PageModuleTypeSummary>() .SingleOrDefault(t => t.PageModuleTypeId == query.Id)); }