/// <summary> /// Indicates whether the specified url matches this routing rule. /// </summary> /// <param name="url">The url to test</param> /// <param name="pageRoute">The page route already matched to this url.</param> public bool MatchesRule(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } var routingPart = GetRoutingPart(url, pageRoute); if (string.IsNullOrEmpty(routingPart)) { return(false); } var isMatch = IntParser.ParseOrDefault(routingPart) > 0; return(isMatch); }
/// <summary> /// Gets the current publish state of the route at the current /// moment in time. In the case of custom entity routes, the publish /// state from both the page and the custom entity is combined so that /// the route can only be published if both entities are published. /// </summary> public PublishState GetPublishState() { var publishState = PageRoute.GetPublishState(); if (CustomEntityRoute != null) { var publishDate = publishState.PublishDate; var publishStatus = PageRoute.PublishStatus; if (CustomEntityRoute.PublishDate > publishDate) { publishDate = CustomEntityRoute.PublishDate; } if (publishStatus == PublishStatus.Published && CustomEntityRoute.PublishStatus == PublishStatus.Unpublished) { publishStatus = PublishStatus.Unpublished; } publishState = new PublishState(publishStatus, publishDate); } return(publishState); }
/// <summary> /// Returns a query that can be used to look up the CustomEntityRoute relating /// to the matched entity. Throws an exception if the MatchesRule returns false, so /// check this before calling this method. /// </summary> /// <param name="url">The url to parse custom entity key data from</param> /// <param name="pageRoute">The page route matched to the url</param> /// <returns>An IQuery object that can used to query for the CustomEntityRoute</returns> public IQuery <CustomEntityRoute> ExtractRoutingQuery(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } if (!MatchesRule(url, pageRoute)) { throw new ArgumentException(nameof(url) + $" does not match the specified page route. {nameof(ExtractRoutingQuery)} can only be called after a successful page route match.", nameof(url)); } var routingPart = GetRoutingPart(url, pageRoute); var customEntityId = IntParser.ParseOrDefault(routingPart); var query = new GetCustomEntityRouteByPathQuery(); query.CustomEntityDefinitionCode = pageRoute.CustomEntityDefinitionCode; query.CustomEntityId = customEntityId; if (pageRoute.Locale != null) { query.LocaleId = pageRoute.Locale.LocaleId; } return(query); }
/// <summary> /// Indicates whether the specified url matches this routing rule. /// </summary> /// <param name="url">The url to test</param> /// <param name="pageRoute">The page route already matched to this url.</param> public bool MatchesRule(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } var routingPart = GetRoutingPart(url, pageRoute); if (string.IsNullOrEmpty(routingPart)) { return(false); } var match = Regex.Match(routingPart, ROUTE_REGEX); if (!match.Success) { return(false); } var isMatch = IntParser.ParseOrDefault(match.Groups[1].Value) > 0; return(isMatch); }
private PageDetails Map( PageVersion dbPageVersion, ICollection <PageRegionDetails> regions, PageRoute pageRoute ) { var page = new PageDetails(); page.PageId = dbPageVersion.PageId; page.PageRoute = pageRoute; page.AuditData = _auditDataMapper.MapCreateAuditData(dbPageVersion.Page); page.Tags = dbPageVersion .Page .PageTags .Select(t => t.Tag.TagText) .OrderBy(t => t) .ToList(); page.LatestVersion = new PageVersionDetails() { MetaDescription = dbPageVersion.MetaDescription, PageVersionId = dbPageVersion.PageVersionId, ShowInSiteMap = !dbPageVersion.ExcludeFromSitemap, Title = dbPageVersion.Title, WorkFlowStatus = (WorkFlowStatus)dbPageVersion.WorkFlowStatusId }; page.LatestVersion.OpenGraph = _openGraphDataMapper.Map(dbPageVersion); page.LatestVersion.Template = _pageTemplateMapper.Map(dbPageVersion.PageTemplate); page.LatestVersion.Regions = regions; return(page); }
/// <summary> /// Indicates whether the specified url matches this routing rule. /// </summary> /// <param name="url">The url to test</param> /// <param name="pageRoute">The page route already matched to this url.</param> public bool MatchesRule(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } var routingPart = GetRoutingPart(url, pageRoute); if (string.IsNullOrEmpty(routingPart)) { return(false); } var isMatch = Regex.IsMatch(routingPart, ROUTE_REGEX); return(isMatch); }
/// <summary> /// Indicates whether the specified url matches this routing rule. /// </summary> /// <param name="url">The url to test</param> /// <param name="pageRoute">The page route already matched to this url.</param> public bool MatchesRule(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } var slugUrlPart = GetRoutingPart(url, pageRoute); if (string.IsNullOrEmpty(slugUrlPart)) { return(false); } var isMatch = Regex.IsMatch(slugUrlPart, RegexLibary.SlugCaseInsensitive); return(isMatch); }
public string MakeUrl(PageRoute pageRoute, CustomEntityRoute entityRoute) { Condition.Requires(pageRoute).IsNotNull(); Condition.Requires(entityRoute).IsNotNull(); return(pageRoute.FullPath.Replace(RouteFormat, entityRoute.UrlSlug)); }
public string MakeUrl(PageRoute pageRoute, CustomEntityRoute entityRoute) { Condition.Requires(pageRoute).IsNotNull(); Condition.Requires(entityRoute).IsNotNull(); return(pageRoute.FullPath .Replace("{Id}", entityRoute.CustomEntityId.ToString()) .Replace("{UrlSlug}", entityRoute.UrlSlug)); }
private PageRoutingInfo ToRoutingInfo(PageRoute pageRoute, CustomEntityRoute customEntityRoute = null, ICustomEntityRoutingRule rule = null) { return(new PageRoutingInfo() { PageRoute = pageRoute, CustomEntityRoute = customEntityRoute, CustomEntityRouteRule = rule }); }
/// <summary> /// Determines if the <paramref name="user"/> violates any access rules /// for this route. If the user cannot access the route then a rule viloation /// is returned. The user may violate several rules in the page and directory /// tree but only the most specific rule set is returned, starting with the page and /// then working back up through the directory tree. /// </summary> /// <param name="user">The <see cref="IUserContext"/> to check against access rules.</param> /// <returns> /// If any rules are violated, then the most specific rule is returned; /// otherwise <see langword="null"/>. /// </returns> public EntityAccessRuleSet ValidateAccess(IUserContext user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } EntityInvalidOperationException.ThrowIfNull(this, r => r.PageRoute); return(PageRoute.ValidateAccess(user)); }
/// <summary> /// Transforms the routing specified routing information into a full, relative url. /// </summary> /// <param name="pageRoute">The matched page route for the url</param> /// <param name="entityRoute">The matched custom entity route for the url</param> /// <returns>Full, relative url</returns> public string MakeUrl(PageRoute pageRoute, CustomEntityRoute entityRoute) { if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } if (entityRoute == null) { throw new ArgumentNullException(nameof(entityRoute)); } return(pageRoute.FullPath.Replace(RouteFormat, entityRoute.UrlSlug)); }
/// <summary> /// Transforms the routing specified routing information into a full, relative url. /// </summary> /// <param name="pageRoute">The matched page route for the url</param> /// <param name="entityRoute">The matched custom entity route for the url</param> /// <returns>Full, relative url</returns> public string MakeUrl(PageRoute pageRoute, CustomEntityRoute entityRoute) { if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } if (entityRoute == null) { throw new ArgumentNullException(nameof(entityRoute)); } return(pageRoute.FullUrlPath .Replace("{Id}", entityRoute.CustomEntityId.ToString()) .Replace("{UrlSlug}", entityRoute.UrlSlug)); }
public bool MatchesRule(string url, PageRoute pageRoute) { Condition.Requires(url).IsNotNullOrWhiteSpace(); Condition.Requires(pageRoute).IsNotNull(); var slugUrlPart = GetRoutingPart(url, pageRoute); if (string.IsNullOrEmpty(slugUrlPart)) { return(false); } var isMatch = Regex.IsMatch(slugUrlPart, RegexLibary.SlugCaseInsensitive); return(isMatch); }
public bool MatchesRule(string url, PageRoute pageRoute) { Condition.Requires(url).IsNotNullOrWhiteSpace(); Condition.Requires(pageRoute).IsNotNull(); var routingPart = GetRoutingPart(url, pageRoute); if (string.IsNullOrEmpty(routingPart)) { return(false); } var isMatch = Regex.IsMatch(routingPart, ROUTE_REGEX); return(isMatch); }
/// <summary> /// Determines if the page is published at this moment in time, /// checking the page and custom entity (if available) published status, the publish date /// and checking to make sure there is a published version. /// </summary> public bool IsPublished() { if (PageRoute == null) { throw new InvalidOperationException($"Cannot call {nameof(IsPublished)} if the {nameof(PageRoute)} property is null."); } var isPublished = PageRoute.IsPublished(); if (isPublished && CustomEntityRoute != null) { isPublished = CustomEntityRoute.IsPublished(); } return(isPublished); }
/// <summary> /// Extracts the custom entity routing part of the path from /// a <paramref name="url"/> e.g. url "/my-path/123" with Pageroute /// "/my-path/{id}" will return "123". /// </summary> private string GetRoutingPart(string url, PageRoute pageRoute) { if (pageRoute.FullUrlPath.IndexOf(RouteFormat) == -1) { return(null); } var pathRoot = pageRoute.FullUrlPath.Replace(RouteFormat, string.Empty); // if not found or there are other parameters in the route path not resolved. if (pathRoot.Contains('{')) { return(null); } return(url.Substring(pathRoot.Length - 1).Trim('/')); }
/// <summary> /// Genric mapper for objects that inherit from PageRenderSummary. /// </summary> /// <param name="dbPageVersion">PageVersion record from the database. Must include the OpenGraphImageAsset property.</param> /// <param name="pageRoute">The page route to map to the new object.</param> public T Map <T>(PageVersion dbPageVersion, PageRoute pageRoute) where T : PageRenderSummary, new() { if (dbPageVersion == null) { throw new ArgumentNullException(nameof(dbPageVersion)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } var page = MapInternal <T>(dbPageVersion); page.PageRoute = pageRoute; return(page); }
/// <summary> /// Maps the main properties on a PageRenderDetails including /// page regions, but does not map the page block data. /// </summary> /// <param name="dbPageVersion"> /// PageVersion record from the database. Must include the /// OpenGraphImageAsset, PageTemplate and PageTemplate.PageTemplateRegions /// properties. /// </param> /// <param name="pageRoute"> /// The page route to map to the new object. /// </param> public PageRenderDetails Map( PageVersion dbPageVersion, PageRoute pageRoute ) { if (dbPageVersion == null) { throw new ArgumentNullException(nameof(dbPageVersion)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } var page = _pageRenderSummaryMapper.Map <PageRenderDetails>(dbPageVersion, pageRoute); MapInternal(dbPageVersion, page); return(page); }
public IQuery <CustomEntityRoute> ExtractRoutingQuery(string url, PageRoute pageRoute) { Condition.Requires(url).IsNotNullOrWhiteSpace(); Condition.Requires(pageRoute).IsNotNull(); Condition.Requires(MatchesRule(url, pageRoute)).IsTrue(); var slugUrlPart = GetRoutingPart(url, pageRoute); var query = new GetCustomEntityRouteByPathQuery() { CustomEntityDefinitionCode = pageRoute.CustomEntityDefinitionCode, UrlSlug = slugUrlPart }; if (pageRoute.Locale != null) { query.LocaleId = pageRoute.Locale.LocaleId; } return(query); }
public IQuery <CustomEntityRoute> ExtractRoutingQuery(string url, PageRoute pageRoute) { Condition.Requires(url).IsNotNullOrWhiteSpace(); Condition.Requires(pageRoute).IsNotNull(); Condition.Requires(MatchesRule(url, pageRoute)).IsTrue(); var routingPart = GetRoutingPart(url, pageRoute); var match = Regex.Match(routingPart, ROUTE_REGEX); var query = new GetCustomEntityRouteByPathQuery(); query.CustomEntityDefinitionCode = pageRoute.CustomEntityDefinitionCode; query.CustomEntityId = Convert.ToInt32(match.Groups[1].Value); if (pageRoute.Locale != null) { query.LocaleId = pageRoute.Locale.LocaleId; } return(query); }
/// <summary> /// Returns a query that can be used to look up the CustomEntityRoute relating /// to the matched entity. Throws an exception if the MatchesRule returns false, so /// check this before calling this method. /// </summary> /// <param name="url">The url to parse custom entity key data from</param> /// <param name="pageRoute">The page route matched to the url</param> /// <returns>An IQuery object that can used to query for the CustomEntityRoute</returns> public IQuery <CustomEntityRoute> ExtractRoutingQuery(string url, PageRoute pageRoute) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentEmptyException(nameof(url)); } if (pageRoute == null) { throw new ArgumentNullException(nameof(pageRoute)); } if (!MatchesRule(url, pageRoute)) { throw new ArgumentException(nameof(url) + $" does not match the specified page route. {nameof(ExtractRoutingQuery)} can only be called after a successful page route match.", nameof(url)); } var routingPart = GetRoutingPart(url, pageRoute); var match = Regex.Match(routingPart, ROUTE_REGEX); var query = new GetCustomEntityRouteByPathQuery(); query.CustomEntityDefinitionCode = pageRoute.CustomEntityDefinitionCode; query.CustomEntityId = Convert.ToInt32(match.Groups[1].Value); if (pageRoute.Locale != null) { query.LocaleId = pageRoute.Locale.LocaleId; } return(query); }