public static Sitemap BuildSitemap(Site site, ContentEnvironment environment, Func <CmsPage, bool> sitemapTrim) { var siteStructure = SiteStructureMapBuilder.BuildStructureMap(site); var pageRepostiory = new CmsPageRepository(); var allPages = pageRepostiory .FindContentVersions(null, environment) .Result .Where(sitemapTrim) .ToDictionary(x => x.ContentId); var sitemap = new Sitemap(); if (site.HomepageId != null && allPages.ContainsKey(site.HomepageId.Value)) { sitemap.HomePage = allPages[site.HomepageId.Value]; } AttachChildNodes(sitemap, siteStructure, string.Empty, allPages); return(sitemap); }
public Requests.CmsPageRequest Build(IHttpRequest httpRequest) { var routeRaw = httpRequest.QueryString[PageDesignerUriComponents.PageId]; var environmentRaw = httpRequest.QueryString[PageDesignerUriComponents.ContentEnvironment]; var contentVersionRaw = httpRequest.QueryString[PageDesignerUriComponents.ContentVersion]; var viewModeRaw = httpRequest.QueryString[PageDesignerUriComponents.ViewMode]; var siteRaw = httpRequest.QueryString[PageDesignerUriComponents.SiteId]; PageRenderMode pageRenderMode = PageRenderMode.Readonly; if (!string.IsNullOrWhiteSpace(viewModeRaw)) { pageRenderMode = (PageRenderMode)Enum.Parse(typeof(PageRenderMode), viewModeRaw, true); } ContentEnvironment env = ContentEnvironment.Live; if (!string.IsNullOrWhiteSpace(environmentRaw)) { env = (ContentEnvironment)Enum.Parse(typeof(ContentEnvironment), environmentRaw, true); } else { if (pageRenderMode == PageRenderMode.PageDesigner) { env = ContentEnvironment.Draft; } } decimal contentVersion = 0; if (!string.IsNullOrWhiteSpace(contentVersionRaw)) { contentVersion = Convert.ToDecimal(contentVersionRaw); } var routeContext = new Requests.CmsPageRequest(); routeContext.PageRenderMode = pageRenderMode; SiteRoute route; if (!string.IsNullOrWhiteSpace(routeRaw)) { route = new ContentPageRoute { Authority = UriAuthorityFilter.Any, PageId = new Guid(routeRaw), SiteId = new Guid(siteRaw), }; } else { var success = CmsRoutes.Current.TryResolveRoute(httpRequest.Uri, out route); } routeContext.Route = route; if (route?.PageId == null) { return(routeContext); } var cmsPageVersions = new CmsPageRepository().FindContentVersions(By.ContentId(route.PageId.Value), env).Result; if (env == ContentEnvironment.Archive) { routeContext.CmsPage = cmsPageVersions.Single(x => x.ContentVersion == contentVersion); } else { routeContext.CmsPage = cmsPageVersions.Single(); } return(routeContext); }
public async Task <IReadOnlyCollection <TVersionedContentEntity> > FindContentVersions(BooleanExpression condition, ContentEnvironment version = ContentEnvironment.Live) { //todo: resolve <T> from metadata. var filter = SqlTranslator.Build(condition, typeof(TVersionedContentEntity)); var contentItems = await Orm.FindContentVersions <TVersionedContentEntity>(filter, version); //if (SecurityModel != null) // foreach (var contentItem in contentItems) // { // //todo: move attribute descriptions to extensibility // var api = RepositoryExtensions.GetRepositoryAttribute(this); // var permissionSet = SecurityModel.CalculatePermissions(new SecurityQuery{ItemId=contentItem.ContentId,RepositoryApiId = api.TypeUid}); // PermissionSetEvaluator.Assert(permissionSet, KnownPrivilegeNames.Read); // } return(contentItems); }
IReadOnlyCollection <VersionedContentEntity> IVersionedContentRepository.FindContentVersions(BooleanExpression condition, ContentEnvironment version) { return(this.FindContentVersions(condition, version).Result.Cast <VersionedContentEntity>().ToList()); }
public async Task <IReadOnlyCollection <T> > FindContentVersions <T>(SqlFilter condition, ContentEnvironment version) where T : VersionedContentEntity, new() { string partitionCondition = null; if (version != ContentEnvironment.Any) { partitionCondition = $"PartitionKey = '{version}'"; } var allConditions = new[] { condition.Filter, partitionCondition }.Where(x => !string.IsNullOrWhiteSpace(x)); var joinedCondition = string.Join(" and ", allConditions); //todo : not secure joinedCondition = NoParameterizationTerribleHack(condition, joinedCondition); return(await Task.FromResult(FindContentImpl <T>(joinedCondition))); }