private static void PreloadContentTemplates() { try { QueryResult queryResult; var timer = new Stopwatch(); timer.Start(); using (new SystemAccount()) { queryResult = ContentQuery.Query( string.Format("+InTree:\"{0}\" +Depth:{1}", Repository.ContentTemplateFolderPath, RepositoryPath.GetDepth(Repository.ContentTemplateFolderPath) + 2), new QuerySettings { EnableAutofilters = false }); var templates = queryResult.Nodes.ToList(); } timer.Stop(); Logger.WriteInformation(string.Format("***** Content template preload time: {0} ******* Count: {1}", timer.Elapsed, queryResult.Count)); //Trace.WriteLine(string.Format(">>>>Preload: Content template preload time: {0} ******* Count: {1}", timer.Elapsed, queryResult.Count)); } catch (Exception ex) { Logger.WriteException(ex); } }
private static void PreloadContentTemplates() { try { QueryResult queryResult; var timer = new Stopwatch(); timer.Start(); using (new SystemAccount()) { queryResult = ContentQuery.Query(SafeQueries.PreloadContentTemplates, null, Repository.ContentTemplateFolderPath, RepositoryPath.GetDepth(Repository.ContentTemplateFolderPath) + 2); var templates = queryResult.Nodes.ToList(); } timer.Stop(); Logger.WriteInformation(Logger.EventId.NotDefined, string.Format("***** Content template preload time: {0} ******* Count: {1}", timer.Elapsed, queryResult.Count)); //Trace.WriteLine(string.Format(">>>>Preload: Content template preload time: {0} ******* Count: {1}", timer.Elapsed, queryResult.Count)); } catch (Exception ex) { Logger.WriteException(ex); } }
public static IEnumerable <Node> GetNewItemNodes(GenericContent content, ContentType[] contentTypes) { if (content == null) { throw new ArgumentNullException("content"); } var templatesAndTypes = new List <Node>(); if (contentTypes != null && contentTypes.Length == 0) { return(templatesAndTypes); } var notAllTypes = contentTypes != null && contentTypes.Length > 0 && contentTypes.Length < ContentType.GetContentTypes().Length; Node site = null; try { site = Node.GetAncestorOfNodeType(content, "Site"); } catch (InvalidOperationException) { //the user does not have enough permissions for one of the parents } Node currentWorkspace = null; try { currentWorkspace = Workspace.GetWorkspaceForNode(content); } catch (InvalidOperationException) { //the user does not have enough permissions for one of the parents } var wsTemplatePath = currentWorkspace == null ? string.Empty : RepositoryPath.Combine(currentWorkspace.Path, Repository.ContentTemplatesFolderName); var siteTemplatePath = site == null ? string.Empty : RepositoryPath.Combine(site.Path, Repository.ContentTemplatesFolderName); var currentContentTemplatePath = RepositoryPath.Combine(content.Path, Repository.ContentTemplatesFolderName); //the query is built on the assumption that all content //templates are placed under a "TypeName" folder in a //container called "ContentTemplates", meaning their //depth equals the depth of the container +2. var sbQueryText = new StringBuilder("+("); //add filter for workspace and site templates if (!string.IsNullOrEmpty(wsTemplatePath) && wsTemplatePath.CompareTo(currentContentTemplatePath) != 0) { sbQueryText.AppendFormat("(InTree:\"{0}\" AND Depth:{1}) OR", wsTemplatePath, RepositoryPath.GetDepth(wsTemplatePath) + 2); } if (!string.IsNullOrEmpty(siteTemplatePath) && siteTemplatePath.CompareTo(currentContentTemplatePath) != 0) { sbQueryText.AppendFormat(" (InTree:\"{0}\" AND Depth:{1}) OR", siteTemplatePath, RepositoryPath.GetDepth(siteTemplatePath) + 2); } //add filter for local and global templates sbQueryText.AppendFormat(" (InTree:\"{0}\" AND Depth:{1}) OR", currentContentTemplatePath, RepositoryPath.GetDepth(currentContentTemplatePath) + 2); sbQueryText.AppendFormat(" (InTree:\"{0}\" AND Depth:{1}))", Repository.ContentTemplateFolderPath, RepositoryPath.GetDepth(Repository.ContentTemplateFolderPath) + 2); //content type filter if (notAllTypes) { sbQueryText.AppendFormat(" +Type:({0})", string.Join(" ", contentTypes.Select(ct => ct.Name))); } sbQueryText.Append(" .REVERSESORT:Depth"); var templateResult = ContentQuery.Query(sbQueryText.ToString(), new QuerySettings { EnableAutofilters = FilterStatus.Disabled, EnableLifespanFilter = FilterStatus.Disabled }).Nodes.ToList(); var templatesNonGlobal = templateResult.Where(ct => !ct.Path.StartsWith(Repository.ContentTemplateFolderPath)).ToList(); var templatesGlobal = templateResult.Where(ct => ct.Path.StartsWith(Repository.ContentTemplateFolderPath)).ToList(); var addedTemplates = new Dictionary <string, List <string> >(); //add all local and ws/site level templates foreach (var localTemplate in templatesNonGlobal) { //query correction: if the query returned a type that we do not want, skip it if (notAllTypes && !contentTypes.Any(ct => ct.Name.CompareTo(localTemplate.ParentName) == 0)) { continue; } AddTemplate(templatesAndTypes, localTemplate, addedTemplates); } //add global templates foreach (var globalTemplate in templatesGlobal) { //query correction: if the query returned a type that we do not want, skip it if (notAllTypes && !contentTypes.Any(ct => ct.Name.CompareTo(globalTemplate.ParentName) == 0)) { continue; } AddTemplate(templatesAndTypes, globalTemplate, addedTemplates); } //add content types without a template if (contentTypes != null) { templatesAndTypes.AddRange(contentTypes.Where(contentType => !addedTemplates.ContainsKey(contentType.Name))); } return(templatesAndTypes); }
private static void PreloadContentTemplates() { try { QueryResult queryResult; var timer = new Stopwatch(); timer.Start(); using (new SystemAccount()) { queryResult = ContentQuery.Query(SafeQueries.PreloadContentTemplates, null, RepositoryStructure.ContentTemplateFolderPath, RepositoryPath.GetDepth(RepositoryStructure.ContentTemplateFolderPath) + 2); // ReSharper disable once UnusedVariable // this is a preload operation, we do not want to use the result var templates = queryResult.Nodes.ToList(); } timer.Stop(); SnLog.WriteInformation($"***** Content template preload time: {timer.Elapsed} ******* Count: {queryResult.Count}"); } catch (Exception ex) { SnLog.WriteException(ex); } }