public override QueryResult GetChildren(string text, QuerySettings settings, bool getAllChildren) { if (!string.IsNullOrEmpty(Query) || !string.IsNullOrEmpty(text)) { var cq = ContentQuery.CreateQuery(Query); if (EnableAutofilters != FilterStatus.Default) cq.Settings.EnableAutofilters = (EnableAutofilters == FilterStatus.Enabled); if (EnableLifespanFilter != FilterStatus.Default) cq.Settings.EnableLifespanFilter = (EnableLifespanFilter == FilterStatus.Enabled); if (settings != null) cq.Settings = settings; if ((cq.IsContentQuery || string.IsNullOrEmpty(this.Query)) && !string.IsNullOrEmpty(text)) cq.AddClause(text); if (cq.IsContentQuery) { //add SmartFolder's own children (with an Or clause) var excapedPath = this.Path.Replace("(", "\\(").Replace(")", "\\)"); cq.AddClause((getAllChildren ? string.Format("InTree:\"{0}\"", excapedPath) : string.Format("InFolder:\"{0}\"", excapedPath)), ChainOperator.Or); } else cq.AddClause(new IntExpression(IntAttribute.ParentId, ValueOperator.Equal, this.Id), ChainOperator.Or); var result = cq.Execute(); return result; } return QueryResult.Empty; }
/// <summary> /// Gets the groups. /// </summary> /// <returns>List of group nodes.</returns> private List<Node> GetGroups() { var groups = new List<Node>(); if (!String.IsNullOrEmpty(GroupQuery)) { var sort = new[] { new SortInfo { FieldName = "Name" } }; var settings = new QuerySettings {EnableAutofilters = false, EnableLifespanFilter = false, Sort = sort}; var query = new ContentQuery { Text = GroupQuery, Settings = settings}; query.AddClause(string.Format("-Name:({0})", string.Join(" ", RepositoryConfiguration.SpecialGroupNames))); var results = query.Execute(); groups.AddRange(results.Nodes); } return groups; }
/// <summary> /// Returns all members from workspace local groups /// </summary> public IEnumerable<IUser> GetWorkspaceMembers() { var members = new List<IUser>(); var groupFolderPath = RepositoryPath.Combine(this.Path, LocalGroupsFolderName); var settings = new SenseNet.Search.QuerySettings { EnableAutofilters = false }; var workspaceGroups = SenseNet.Search.ContentQuery.Query("+TypeIs:Group +InTree:\"" + groupFolderPath + "\"", settings).Nodes; foreach (var group in workspaceGroups.OfType<IGroup>()) { members.AddRange(group.Members.OfType<IUser>()); } return members.Distinct(); }
/// <summary> /// Returns all members from workspace local groups /// </summary> public IEnumerable <IUser> GetWorkspaceMembers() { var members = new List <IUser>(); var groupFolderPath = RepositoryPath.Combine(this.Path, LocalGroupsFolderName); var settings = new SenseNet.Search.QuerySettings { EnableAutofilters = false }; var workspaceGroups = SenseNet.Search.ContentQuery.Query("+TypeIs:Group +InTree:\"" + groupFolderPath + "\"", settings).Nodes; foreach (var group in workspaceGroups.OfType <IGroup>()) { members.AddRange(group.Members.OfType <IUser>()); } return(members.Distinct()); }
// ======================================================================================== static methods public static IEnumerable<WorkspaceGroupList> GetWorkspaceGroupLists(User user) { // 1. query groups under workspaces var settings = new QuerySettings { EnableAutofilters = false }; var groups = SenseNet.Search.ContentQuery.Query("+TypeIs:Group +Workspace:*", settings).Nodes; // 2. select groups in which the current user is a member (Owner, Editor) var wsGroups = groups.Select(g => new WorkspaceGroup { Workspace = (g as SenseNet.ContentRepository.Group).Workspace, Group = (g as SenseNet.ContentRepository.Group) }); wsGroups = wsGroups.Where(wsg => user.IsInGroup(wsg.Group)); // 3. group by workspaces var wsGroupLists = from wsg in wsGroups orderby wsg.Workspace.DisplayName group wsg by wsg.Workspace into w select new WorkspaceGroupList { Workspace = w.Key, Groups = w }; return wsGroupLists; }
/// <summary> /// Returns all members from workspace local groups /// </summary> public IEnumerable <IUser> GetWorkspaceMembers() { var members = new List <IUser>(); var groupFolderPath = RepositoryPath.Combine(this.Path, LocalGroupsFolderName); var settings = new SenseNet.Search.QuerySettings { EnableAutofilters = FilterStatus.Disabled }; var workspaceGroups = SenseNet.Search.ContentQuery.Query(SafeQueries.InTreeAndTypeIs, settings, groupFolderPath, typeof(Group).Name).Nodes; foreach (var group in workspaceGroups.OfType <IGroup>()) { members.AddRange(group.Members.OfType <IUser>()); } return(members.Distinct()); }
private Stream GetXml(bool withChildren, string queryFilter, QuerySettings querySettings, SerializationOptions options) { if (options == null) options = SerializationOptions.Default; var stream = new MemoryStream(); var writer = XmlWriter.Create(stream, new XmlWriterSettings { Indent = true }); writer.WriteStartDocument(); //if a filter or query settings is present, we have to filter children if (!string.IsNullOrEmpty(queryFilter) || querySettings != null) WriteXml(writer, queryFilter, querySettings, options); else WriteXml(writer, withChildren, options); writer.Flush(); stream.Position = 0; return stream; }
/* ====================================================================================================== Methods */ protected override void OnInit(EventArgs e) { if (ShowExecutionTime) Timer.Start(); UITools.AddScript("$skin/scripts/sn/SN.KPIViewDropDown.js"); // setup views list // the source list is built up from a query var sortinfo = new List<SortInfo>() { new SortInfo() { FieldName = "Name", Reverse = false } }; var settings = new QuerySettings() { EnableAutofilters = false, Sort = sortinfo }; var query = ContentQuery.CreateQuery(string.Format("InFolder:\"{0}\"", kpiSourcePath), settings); var result = query.Execute(); var viewList = new StringBuilder(); // collect kpi views from under sources foreach (Node node in result.Nodes) { var c = SenseNet.ContentRepository.Content.Create(node); c.ChildrenQuerySettings = new QuerySettings() { EnableAutofilters = false, Sort = sortinfo }; foreach (var child in c.Children) { viewList.Append(string.Concat("{ sourceName: '",node.Name,"', viewName: '",child.Name,"'},")); } } var viewListStr = string.Concat('[',viewList.ToString().TrimEnd(','),']'); string script = string.Format("SN.KPIViewDropDown.init('{0}','{1}',{2});", masterDropdownCss, slaveDropdownCss, viewListStr); UITools.RegisterStartupScript("KPIViewDropDownScript", script, this.Page); if (ShowExecutionTime) Timer.Stop(); base.OnInit(e); }
public static int GetCommentCount(int parentId) { var parent = NodeHead.Get(parentId); if (parent == null) return -1; var commentFolderPath = RepositoryPath.Combine(parent.Path, "Comments"); var queryText = string.Format("+InFolder:\"{0}\" +Type:Comment .COUNTONLY", commentFolderPath); var settings = new QuerySettings { EnableAutofilters = false }; var result = ContentQuery.Query(queryText, settings); return result.Count; }
public static ContentQuery CreateQuery(string text, QuerySettings settings) { return new ContentQuery { Text = text, Settings = settings }; }
public static string GetWallPostsMarkup(string contextPath, List<PostInfo> posts) { if (posts.Count == 0) return string.Empty; // create query for comments and likes var csb = new StringBuilder(); foreach (var postInfo in posts) { if (postInfo.IsJournal) continue; csb.Append("\"" + postInfo.Path + "\" "); } var paths = csb.ToString().Trim(); List<Node> allComments; List<Node> allLikes; if (string.IsNullOrEmpty(paths)) // only non-persisted journal posts are there to show (no comments or likes) { allComments = new List<Node>(); allLikes = new List<Node>(); } else { var commentsAndLikesQuery = "+TypeIs:(Comment Like) +InTree:(" + paths + ")"; var settings = new QuerySettings() { EnableAutofilters = false }; var allCommentsAndLikes = ContentQuery.Query(commentsAndLikesQuery, settings).Nodes.ToList(); var commentNodeTypeId = NodeType.GetByName("Comment").Id; var likeTypeId = NodeType.GetByName("Like").Id; allComments = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList(); allLikes = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList(); } var bigPostMarkupStr = GetBigPostMarkupStr(); var smallPostMarkupStr = GetSmallPostMarkupStr(); var commentMarkupStr = GetCommentMarkupStr(); var commentSectionStr = GetCommentSectionMarkupStr(); PostInfo prevPost = null; var sb = new StringBuilder(); foreach (var postInfo in posts) { // get comments and likes for post CommentInfo commentInfo; LikeInfo likeInfo; if (postInfo.IsJournal) { commentInfo = new CommentInfo(); likeInfo = new LikeInfo(); } else { var commentsForPost = allComments.Where(c => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(c.Path)) == postInfo.Path).ToList(); var likesForPostAndComments = allLikes.Where(l => l.Path.StartsWith(postInfo.Path)).ToList(); var likesForPost = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == postInfo.Path).ToList(); commentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr); likeInfo = new LikeInfo(likesForPost, postInfo.Id); } var drawBoundary = (prevPost != null) && (prevPost.Type != PostType.BigPost) && (postInfo.Type == PostType.BigPost); var markup = WallHelper.GetPostMarkup( postInfo.Type == PostType.BigPost ? bigPostMarkupStr : smallPostMarkupStr, commentSectionStr, postInfo, contextPath, commentInfo.HiddenCommentsMarkup, commentInfo.CommentsMarkup, commentInfo.CommentCount, likeInfo, drawBoundary); prevPost = postInfo; sb.Append(markup); } return sb.ToString(); }
public static QueryResult Query(string text, QuerySettings settings) { return CreateQuery(text, settings).Execute(ExecutionHint.None); }
protected override void CreateChildControls() { if (this.ContextNode == null) return; if (ShowExecutionTime) Timer.Start(); // gather posts for this content List<PostInfo> posts; using (new OperationTrace("Wall - Gather posts")) { posts = DataLayer.GetPostsForContent(this.ContextNode).ToList(); } string postsMarkup; using (new OperationTrace("Wall - Posts markup")) { postsMarkup = WallHelper.GetWallPostsMarkup(this.ContextNode.Path, posts); } CommentInfo contentCommentInfo; LikeInfo contentLikeInfo; using (new OperationTrace("Wall - Gather content comments")) { var commentsAndLikesQuery = "+TypeIs:(Comment Like) +InTree:\"" + this.ContextNode.Path + "\""; var settings = new QuerySettings() { EnableAutofilters = false }; var allCommentsAndLikes = ContentQuery.Query(commentsAndLikesQuery, settings).Nodes.ToList(); var commentNodeTypeId = NodeType.GetByName("Comment").Id; var likeTypeId = NodeType.GetByName("Like").Id; var commentsForPost = allCommentsAndLikes.Where(c => c.NodeTypeId == commentNodeTypeId).ToList(); var likesForPostAndComments = allCommentsAndLikes.Where(l => l.NodeTypeId == likeTypeId).ToList(); var likesForPost = likesForPostAndComments.Where(l => RepositoryPath.GetParentPath(RepositoryPath.GetParentPath(l.Path)) == this.ContextNode.Path).ToList(); var commentMarkupStr = WallHelper.GetCommentMarkupStr(); // get comments for this content contentCommentInfo = new CommentInfo(commentsForPost, likesForPostAndComments, commentMarkupStr); // get likes for this content contentLikeInfo = new LikeInfo(likesForPost, this.ContextNode.Id); } using (new OperationTrace("Wall - Content comments markup")) { var markupStr = WallHelper.GetContentWallMarkup( this.ContextNode, contentCommentInfo.HiddenCommentsMarkup, contentCommentInfo.CommentsMarkup, contentCommentInfo.CommentCount, contentLikeInfo, postsMarkup); this.Controls.Add(new Literal { Text = markupStr }); } if (ShowExecutionTime) Timer.Stop(); base.CreateChildControls(); this.ChildControlsCreated = true; }
public virtual QueryResult GetChildren(string text, QuerySettings settings, bool getAllChildren) { if (RepositoryInstance.ContentQueryIsAllowed) { var excapedPath = this.Path.Replace("(", "\\(").Replace(")", "\\)"); var query = ContentQuery.CreateQuery(getAllChildren ? string.Format("InTree:\"{0}\"", excapedPath) : string.Format("InFolder:\"{0}\"", excapedPath), settings); if (!string.IsNullOrEmpty(text)) query.AddClause(text); return query.Execute(); } else { var nqr = NodeQuery.QueryChildren(this.Path); return new QueryResult(nqr.Identifiers, nqr.Count); } }
public static ContentQuery CreateQuery(string text, QuerySettings settings) { return(new ContentQuery { Text = text, Settings = settings }); }
protected abstract void WriteXml(XmlWriter writer, string queryFilter, QuerySettings querySettings, SerializationOptions options);
public Stream GetXml(string queryFilter, QuerySettings querySettings, SerializationOptions options = null) { return GetXml(true, queryFilter, querySettings, options); }
protected override void WriteXml(XmlWriter writer, string queryFilter, QuerySettings querySettings, SerializationOptions options) { WriteXml(writer, false, options); }
public virtual QueryResult GetChildren(QuerySettings settings) { return GetChildren(string.Empty, settings); }
public virtual QueryResult GetChildren(string text, QuerySettings settings) { return GetChildren(text, settings, false); }
public static QueryResult Query(string text, QuerySettings settings) { return(CreateQuery(text, settings).Execute(ExecutionHint.None)); }
private void RemoveWorkflow() { // check if workflow is currently running var targetPath = RepositoryPath.Combine(this.ContextNode.Path, "Workflows/MailProcess"); var queryStr = "+TypeIs:MailProcessorWorkflow +InFolder:\"" + targetPath + "\" +WorkflowStatus:" + ((int)WorkflowStatusEnum.Running).ToString(); var settings = new QuerySettings { EnableAutofilters = false }; var runningWorkflow = ContentQuery.Query(queryStr, settings); if (runningWorkflow.Count > 0) { using (new SystemAccount()) { foreach (var wfnode in runningWorkflow.Nodes) { // abort and delete workflow var wf = wfnode as WorkflowHandlerBase; wf.ForceDelete(); } } } }
private static Dictionary<string, int> GetAllPortalObjects(ADObjectType objType) { var typeText = string.Empty; if (objType == ADObjectType.AllContainers) { typeText = string.Concat( "(TypeIs:", Common.GetNodeType(ADObjectType.OrgUnit).Name, " OR TypeIs:", Common.GetNodeType(ADObjectType.Container).Name, " OR TypeIs:", Common.GetNodeType(ADObjectType.Domain).Name, ")"); } else { typeText = string.Concat("TypeIs:", Common.GetNodeType(objType).Name); } var queryText = string.Concat(typeText, " AND InTree:/Root/IMS"); var settings = new QuerySettings { EnableAutofilters = false, EnableLifespanFilter = false }; var query = ContentQuery.CreateQuery(queryText, settings); var result = query.Execute(); var guidIdList = (from node in result.Nodes where !string.IsNullOrEmpty(node.GetProperty<string>("SyncGuid")) select new {Guid = node.GetProperty<string>("SyncGuid").ToLower(), ID = node.Id}); return guidIdList.ToDictionary(a => a.Guid, a => a.ID); }
public static IEnumerable<int> ExecuteRecursive(string queryText, int top, int skip, IEnumerable<SortInfo> sort, bool? enableAutofilters, bool? enableLifespanFilter, QuerySettings settings, out int count, out List<string> log, out IEnumerable<QueryTraceInfo> traceInfo) { log = new List<string>(); IEnumerable<int> result = new int[0]; var src = queryText; log.Add(src); var control = GetControlString(src); var trace = new List<QueryTraceInfo>(); while (true) { int start; var sss = GetInnerScript(src, control, out start); var end = sss == String.Empty; QueryTraceInfo traceItem; if (!end) { src = src.Remove(start, sss.Length); control = control.Remove(start, sss.Length); int innerCount; var innerResult = ExecuteInnerScript(sss.Substring(2, sss.Length - 4), 0, 0, sort, enableAutofilters, enableLifespanFilter, null, true, out innerCount, out traceItem).StringArray; switch (innerResult.Length) { case 0: sss = EmptyInnerQueryText; break; case 1: sss = innerResult[0]; break; default: sss = String.Join(" ", innerResult); sss = "(" + sss + ")"; break; } src = src.Insert(start, sss); control = control.Insert(start, sss); trace.Add(traceItem); log.Add(src); } else { result = ExecuteInnerScript(src, top, skip, sort, enableAutofilters, enableLifespanFilter, settings, false, out count, out traceItem).IntArray; trace.Add(traceItem); log.Add(String.Join(" ", result.Select(i => i.ToString()).ToArray())); break; } } traceInfo = trace; return result; }
private ActionResult GetChildrenByNodeInternal(Node node, bool includeLeafNodes, string contentTypes) { var folderParent = node as IFolder; if (folderParent == null) return null; var filter = GetContentTypesFilter(contentTypes); var querySettings = new QuerySettings { EnableAutofilters = false }; //in case of SmartFolder: do not override the settings given in the query var children = folderParent.GetChildren(filter, folderParent is SmartFolder ? null : querySettings).Nodes.ToList(); if (!includeLeafNodes) children = children.Where(c => c is IFolder).ToList(); return Json(children.Where(c => c != null).Select(child => new Content(child, true, false, false, false, 0, 0)).ToArray(), JsonRequestBehavior.AllowGet); }
public static ContentQuery CreateQuery(string text, QuerySettings settings) { return(CreateQuery(text, settings, null)); }
private static InnerQueryResult ExecuteInnerScript(string src, int top, int skip, IEnumerable<SortInfo> sort, bool? enableAutofilters, bool? enableLifespanFilter, QuerySettings settings, bool enableProjection, out int count, out QueryTraceInfo traceInfo) { var query = LucQuery.Parse(src); var projection = query.Projection; if (projection != null) if (!enableProjection) throw new ApplicationException(String.Format("Projection in top level query is not allowed ({0}:{1})", Parser.SnLucLexer.Keywords.Select, projection)); if (skip != 0) query.Skip = skip; if (top != 0) query.PageSize = top; else if (query.PageSize == 0) query.PageSize = GetDefaultMaxResults(); if (sort != null && sort.Count() > 0) query.SetSort(sort); if (enableAutofilters.HasValue) query.EnableAutofilters = enableAutofilters.Value; if (enableLifespanFilter.HasValue) query.EnableLifespanFilter = enableLifespanFilter.Value; //Re-set settings values. This is important for NodeList that //uses the paging info written into the query text. if (settings != null) { settings.Top = query.PageSize; settings.Skip = query.Skip; } InnerQueryResult result; var qresult = query.Execute().ToList(); if (projection == null || !enableProjection) { var idResult = qresult.Select(o => o.NodeId).ToArray(); result = new InnerQueryResult { IsIntArray = true, IntArray = idResult, StringArray = idResult.Select(i => i.ToString()).ToArray() }; } else { var stringResult = qresult.Select(o => o[projection, false]).Where(r => !String.IsNullOrEmpty(r)); var escaped = new List<string>(); foreach (var s in stringResult) escaped.Add(EscapeForQuery(s)); result = new InnerQueryResult { IsIntArray = false, StringArray = escaped.ToArray() }; } traceInfo = query.TraceInfo; count = query.TotalCount; return result; }
// returns synchronized portal nodes private IEnumerable<Node> GetAllPortalObjects(ADObjectType objType, SyncTree syncTree) { var typeText = string.Empty; if (objType == ADObjectType.AllContainers) { typeText = string.Concat( "(TypeIs:", Common.GetNodeType(ADObjectType.OrgUnit).Name, " OR TypeIs:", Common.GetNodeType(ADObjectType.Container).Name, " OR TypeIs:", Common.GetNodeType(ADObjectType.Domain).Name, ")"); } else { typeText = string.Concat("TypeIs:", Common.GetNodeType(objType).Name); } var startPath = string.Concat('"', syncTree.PortalPath.TrimEnd(new char[] { '/' }), '"'); var queryText = string.Concat(typeText, " AND InTree:", startPath); var settings = new QuerySettings {EnableAutofilters = false, EnableLifespanFilter = false}; var query = ContentQuery.CreateQuery(queryText, settings); var result = query.Execute(); return result.Nodes; }
public static QueryResult Query(string text, QuerySettings settings) { return(Query(text, settings, null)); }
protected override object GetModel() { if (ContextNode == null) return null; var content = Content.Create(ContextNode); var qs = new QuerySettings(); if (EnableAutofilters != FilterStatus.Default) qs.EnableAutofilters = (EnableAutofilters == FilterStatus.Enabled); if (EnableLifespanFilter != FilterStatus.Default) qs.EnableLifespanFilter = (EnableLifespanFilter == FilterStatus.Enabled); if (Top > 0) qs.Top = Top; if (State.Skip > 0) qs.Skip = State.Skip; if (!string.IsNullOrEmpty(State.SortColumn)) { qs.Sort = new[] { new SortInfo { FieldName = State.SortColumn, Reverse = State.SortDescending } }; } content.ChildrenQuerySettings = qs; content.ChildrenQueryFilter = GetQueryFilter(); content.XmlWriterExtender = writer => { }; switch (CollectionAxis) { case CollectionAxisMode.Children: return content; case CollectionAxisMode.VersionHistory: var versionRoot = SearchFolder.Create(content.Versions); return versionRoot; case CollectionAxisMode.ReferenceProperty: return content; case CollectionAxisMode.External: return SearchFolder.Create(RequestNodeList); } return null; }
public static IEnumerable <int> ExecuteRecursive(string queryText, int top, int skip, IEnumerable <SortInfo> sort, FilterStatus enableAutofilters, FilterStatus enableLifespanFilter, QuerySettings settings, out int count, out List <string> log, out IEnumerable <QueryTraceInfo> traceInfo) { log = new List <string>(); IEnumerable <int> result = new int[0]; var src = queryText; log.Add(src); var control = GetControlString(src); var trace = new List <QueryTraceInfo>(); while (true) { int start; var sss = GetInnerScript(src, control, out start); var end = sss == String.Empty; QueryTraceInfo traceItem; if (!end) { src = src.Remove(start, sss.Length); control = control.Remove(start, sss.Length); int innerCount; var innerResult = ExecuteInnerScript(sss.Substring(2, sss.Length - 4), 0, 0, sort, enableAutofilters, enableLifespanFilter, null, true, out innerCount, out traceItem).StringArray; switch (innerResult.Length) { case 0: sss = EmptyInnerQueryText; break; case 1: sss = innerResult[0]; break; default: sss = String.Join(" ", innerResult); sss = "(" + sss + ")"; break; } src = src.Insert(start, sss); control = control.Insert(start, sss); trace.Add(traceItem); log.Add(src); } else { result = ExecuteInnerScript(src, top, skip, sort, enableAutofilters, enableLifespanFilter, settings, false, out count, out traceItem).IntArray; trace.Add(traceItem); log.Add(String.Join(" ", result.Select(i => i.ToString()).ToArray())); break; } } traceInfo = trace; return(result); }
private static void ExportContentTree(Content content, ExportContext context, string fsPath, string indent) { try { ExportContent(content, context, fsPath, indent); } catch (Exception ex) { var path = content == null ? fsPath : content.Path; PrintException(ex, path); return; } //TODO: SmartFolder may contain real items too if (content.ContentHandler is SmartFolder) return; // create folder only if it has children var contentAsFolder = content.ContentHandler as IFolder; var contentAsGeneric = content.ContentHandler as GenericContent; //try everything that can have children (generic content, content types or other non-gc nodes) if (contentAsFolder == null && contentAsGeneric == null) return; try { var settings = new QuerySettings {EnableAutofilters = false, EnableLifespanFilter = false}; var queryResult = contentAsFolder == null ? contentAsGeneric.GetChildren(settings) : contentAsFolder.GetChildren(settings); if (queryResult.Count == 0) return; var children = queryResult.Nodes; var newDir = Path.Combine(fsPath, GetSafeFileNameFromContentName(content.Name)); if (!(content.ContentHandler is ContentType)) Directory.CreateDirectory(newDir); var newIndent = indent + " "; foreach (var childContent in from node in children select Content.Create(node)) ExportContentTree(childContent, context, newDir, newIndent); } catch (Exception ex) { PrintException(ex, fsPath); } }
/// <summary> /// Executes a prepared query. Before execution substitutes the parameters into the placeholders. /// Placeholder is a '@' character followed by a number that means the (zero based) index in the paramter array. /// Example: +TypeIs:@0 +Name:@1 /// Parameter values will be escaped and quotation marks will be used in the appropriate places. /// Do not surround the placeholders with quotation mark (") or apsthrophe ('). /// In case of inconsistence beetween parameter count and placeholder indexes InvalidOperationException will be thrown. /// </summary> /// <param name="text">Query text containing placeholders</param> /// <param name="settings">Additional control parameters (top, skip, sort, automations). It can be null.</param> /// <param name="parameters">Value list that will be substituted into the placeholders of the query text.</param> /// <returns>Contains result set and its metadata.</returns> public static QueryResult Query(string text, QuerySettings settings, params object[] parameters) { return(CreateQuery(text, settings, parameters).Execute(ExecutionHint.None)); }
/* ====================================================================================================== Methods */ private void BuildList() { //store the selected value for using it after the list is repopulated //(storing the index is not correct, we have to use the value) var selVal = this.SelectedIndex > 0 ? this.SelectedValue : null; //we have to clear the itemlist here to //refresh the item collection if changed this.Items.Clear(); if (this.DropdownOptions.CommonType == DropDownCommonType.ContentTypeDropdown) { // special use-case, content type list is defined in webconfig NodeQueryResult contentTypeNames = GetWebContentTypeList(); if (contentTypeNames.Count > 0) { foreach (Node contentType in contentTypeNames.Nodes) { var contentTypeName = contentType.Name; this.Items.Add(new ListItem(contentTypeName, contentTypeName)); } } } if (!string.IsNullOrEmpty(this.DropdownOptions.Query)) { // the list is built up from a query var sortinfo = new List<SortInfo>() { new SortInfo() { FieldName = "Name", Reverse = false } }; var settings = new QuerySettings() { EnableAutofilters = false, Sort = sortinfo }; var query = ContentQuery.CreateQuery(this.DropdownOptions.Query, settings); var result = query.Execute(); if (result.Count == 0) { this.Items.Add(new ListItem("No items available", string.Empty)); return; } this.Items.Add(new ListItem("Select an item...", string.Empty)); foreach (Node node in result.Nodes) { var nodeName = node.Name; this.Items.Add(new ListItem(nodeName, nodeName)); } } //re-select the original selected value if needed if (selVal != null) { var index = 0; foreach (ListItem item in this.Items) { if (selVal.CompareTo(item.Value) == 0) { this.SelectedIndex = index; break; } index++; } } }
private static InnerQueryResult ExecuteInnerScript(string src, int top, int skip, IEnumerable <SortInfo> sort, FilterStatus enableAutofilters, FilterStatus enableLifespanFilter, QuerySettings settings, bool enableProjection, out int count, out QueryTraceInfo traceInfo) { LucQuery query; try { query = LucQuery.Parse(src); } catch (ParserException ex) { throw new InvalidContentQueryException(src, innerException: ex); } var projection = query.Projection; if (projection != null) { if (!enableProjection) { throw new ApplicationException(String.Format("Projection in top level query is not allowed ({0}:{1})", Parser.SnLucLexer.Keywords.Select, projection)); } } if (skip != 0) { query.Skip = skip; } if (top != 0) { query.PageSize = top; } else if (query.PageSize == 0) { query.PageSize = GetDefaultMaxResults(); } if (sort != null && sort.Count() > 0) { query.SetSort(sort); } if (enableAutofilters != FilterStatus.Default) { query.EnableAutofilters = enableAutofilters; } if (enableLifespanFilter != FilterStatus.Default) { query.EnableLifespanFilter = enableLifespanFilter; } //Re-set settings values. This is important for NodeList that //uses the paging info written into the query text. if (settings != null) { settings.Top = query.PageSize; settings.Skip = query.Skip; } InnerQueryResult result; var qresult = query.Execute().ToList(); if (projection == null || !enableProjection) { var idResult = qresult.Select(o => o.NodeId).ToArray(); result = new InnerQueryResult { IsIntArray = true, IntArray = idResult, StringArray = idResult.Select(i => i.ToString()).ToArray() }; } else { var stringResult = qresult.Select(o => o[projection, false]).Where(r => !String.IsNullOrEmpty(r)); var escaped = new List <string>(); foreach (var s in stringResult) { escaped.Add(EscapeForQuery(s)); } result = new InnerQueryResult { IsIntArray = false, StringArray = escaped.ToArray() }; } traceInfo = query.TraceInfo; count = query.TotalCount; return(result); }