public IEnumerable <int> ExecuteToIds(ExecutionHint hint) { // We need to get the pure id list for one single query. // If you run Execute, it returns a NodeList that loads // all result ids, not only the page you specified. return(GetIdResults(hint)); }
protected NodeEnumerator(string path, ExecutionHint executionHint, string filter, int?depth) { RootPath = path; _currentLevel = new Stack <int[]>(); _currentIndices = new Stack <int>(); _hint = executionHint; _depth = depth.HasValue ? Math.Max(1, depth.Value) : depth; if (filter != null) { if (filter.Length == 0) { filter = null; } else if (filter.StartsWith("<")) { SnLog.WriteWarning( "NodeEnumerator cannot be initialized with filter that is a NodeQuery. Use content query text instead.", properties: new Dictionary <string, object> { { "InvalidFilter", filter } }); filter = null; } } _filter = filter; }
protected SiteMenuNodeEnumerator(string path, ExecutionHint executionHint, NodeQuery filter, int?depth, string contextPath, bool getContextChildren) : base(path, executionHint, filter, depth) { _contextPath = contextPath; _getContextChildren = getContextChildren; }
private IEnumerable <int> GetIdResults(ExecutionHint hint, int top, int skip, IEnumerable <SortInfo> sort, FilterStatus enableAutofilters, FilterStatus enableLifespanFilter, QueryExecutionMode executionMode) { if (SenseNet.ContentRepository.User.Current.Id == -1 && !this.IsSafe) { var ex = new InvalidOperationException("Cannot execute this query, please convert it to a safe query."); ex.Data.Add("EventId", EventId.Querying); ex.Data.Add("Query", this._text); throw ex; } if (IsNodeQuery) { using (var op = SnTrace.Query.StartOperation("NodeQuery: {0} | Top:{1} Skip:{2} Sort:{3} Mode:{4}", _text, _settings.Top, _settings.Skip, _settings.Sort, _settings.QueryExecutionMode)) { var result = GetIdResultsWithNodeQuery(hint, top, skip, sort, enableAutofilters, enableLifespanFilter, executionMode); op.Successful = true; return(result); } } if (IsContentQuery) { using (var op = SnTrace.Query.StartOperation("ContentQuery: {0} | Top:{1} Skip:{2} Sort:{3} Mode:{4}", this._text, _settings.Top, _settings.Skip, _settings.Sort, _settings.QueryExecutionMode)) { var result = GetIdResultsWithLucQuery(top, skip, sort, enableAutofilters, enableLifespanFilter, executionMode); op.Successful = true; return(result); } } throw new InvalidOperationException("Cannot execute query with null or empty Text"); }
protected SiteMenuNodeEnumerator(string path, ExecutionHint executionHint, NodeQuery filter, int? depth, string contextPath, bool getContextChildren) : base(path, executionHint, filter, depth) { _contextPath = contextPath; _getContextChildren = getContextChildren; }
public static IEnumerable <Node> GetNodes(string path, ExecutionHint hint, NodeQuery filter, int?depth) { if (path == null) { throw new ArgumentNullException("path"); } return(new NodeEnumerator(path, hint, filter, depth)); }
protected SiteMenuNodeEnumerator(string path, ExecutionHint executionHint, string filter, int? depth, string contextPath, bool getContextChildren) : base(path, executionHint, null, depth) { _contextPath = contextPath; _getContextChildren = getContextChildren; _childrenFilter = filter; }
public static IEnumerable<Node> GetNodes(string path, ExecutionHint hint, string filter, int? depth, string contextPath, bool getContextChildren) { if (path == null) throw new ArgumentNullException("path"); return new SiteMenuNodeEnumerator(path, hint, filter, depth, contextPath, getContextChildren); }
protected SiteMenuNodeEnumerator(string path, ExecutionHint executionHint, string filter, int?depth, string contextPath, bool getContextChildren) : base(path, executionHint, null, depth) { _contextPath = contextPath; _getContextChildren = getContextChildren; _childrenFilter = filter; }
protected NodeEnumerator(string path, ExecutionHint executionHint, NodeQuery filter, int?depth) { RootPath = path; _currentLevel = new Stack <int[]>(); _currentIndices = new Stack <int>(); _hint = executionHint; _filter = filter; _depth = depth.HasValue ? Math.Max(1, depth.Value) : depth; }
public static IEnumerable <Node> GetNodes(string path, ExecutionHint hint, string filter, int?depth, string contextPath, bool getContextChildren) { if (path == null) { throw new ArgumentNullException("path"); } return(new SiteMenuNodeEnumerator(path, hint, filter, depth, contextPath, getContextChildren)); }
private IEnumerable <int> GetIdResultsWithNodeQuery(ExecutionHint hint, int top, int skip, IEnumerable <SortInfo> sort, FilterStatus enableAutofilters, FilterStatus enableLifespanFilter, QueryExecutionMode executionMode) { //TODO: QUICK: Process executionMode in GetIdResultsWithNodeQuery var queryText = LucQuery.IsAutofilterEnabled(enableAutofilters) ? AddAutofilterToNodeQuery(Text) : Text; if (LucQuery.IsLifespanFilterEnabled(enableLifespanFilter)) { queryText = AddLifespanFilterToNodeQuery(queryText, GetLifespanFilterForNodeQuery()); } NodeQuery query; try { query = NodeQuery.Parse(queryText); } catch (XmlException ex) { throw new InvalidContentQueryException(queryText, innerException: ex); } catch (InvalidOperationException ex) { throw new InvalidContentQueryException(queryText, innerException: ex); } if (skip != 0) { query.Skip = skip; } if (top != 0) { query.Top = top; } else if (query.Top == 0) { query.Top = GetDefaultMaxResults(); } query.PageSize = query.Top; if (sort != null && sort.Count() > 0) { throw new NotSupportedException("Sorting override is not allowed on NodeQuery"); } var result = query.Execute(hint); TotalCount = result.Count; return(result.Identifiers.ToList()); }
private IEnumerable <int> GetIdResults(ExecutionHint hint, int top, int skip, IEnumerable <SortInfo> sort, bool?enableAutofilters, bool?enableLifespanFilter) { if (IsNodeQuery) { return(GetIdResultsWithNodeQuery(hint, top, skip, sort, enableAutofilters, enableLifespanFilter)); } if (IsContentQuery) { return(GetIdResultsWithLucQuery(top, skip, sort, enableAutofilters, enableLifespanFilter)); } throw new InvalidOperationException("Cannot execute query with null or empty Text"); }
private IEnumerable <int> GetIdResults(ExecutionHint hint, int top, int skip, IEnumerable <SortInfo> sort, FilterStatus enableAutofilters, FilterStatus enableLifespanFilter) { if (ContentRepository.User.Current.Id == -1 && !this.IsSafe) { var ex = new InvalidOperationException("Cannot execute this query."); ex.Data.Add("EventId", ContentRepository.EventId.Querying.CannotExecuteQuery); ex.Data.Add("Query", this._text); //Diagnostics.Logger.WriteError(ContentRepository.EventId.Error.CannotExecuteQuery, ex); throw ex; } if (IsNodeQuery) { #if QUERY var op = DetailedLogger.CreateOperation(); // category: QUERY DetailedLogger.Log(op, "NodeQuery {0} | Top:{1} Skip:{2} Sort:{3}", this._text, _settings.Top, _settings.Skip, // category: QUERY _settings.Sort == null ? "" : String.Join(",", _settings.Sort.Select(s => s.FieldName + (s.Reverse ? " ASC" : " DESC")))); #endif var result = GetIdResultsWithNodeQuery(hint, top, skip, sort, enableAutofilters, enableLifespanFilter); #if QUERY op.Finish(); #endif return(result); } if (IsContentQuery) { #if QUERY var op = DetailedLogger.CreateOperation(); // category: QUERY DetailedLogger.Log(op, "ContentQuery {0} | Top:{1} Skip:{2} Sort:{3}", this._text, _settings.Top, _settings.Skip, // category: QUERY _settings.Sort == null ? "" : String.Join(",", _settings.Sort.Select(s => s.FieldName + (s.Reverse ? " ASC" : " DESC")))); #endif var result = GetIdResultsWithLucQuery(top, skip, sort, enableAutofilters, enableLifespanFilter); #if QUERY op.Finish(); #endif return(result); } throw new InvalidOperationException("Cannot execute query with null or empty Text"); }
public NodeQueryResult Execute(ExecutionHint hint) { switch (hint) { case ExecutionHint.None: if (IsRelationalEngineQuery()) { return(ExecuteRelationalEngineQuery()); } return(ExecuteIndexedEngineQuery()); case ExecutionHint.ForceRelationalEngine: return(ExecuteRelationalEngineQuery()); case ExecutionHint.ForceIndexedEngine: return(ExecuteIndexedEngineQuery()); default: throw new NotImplementedException(); } }
private IEnumerable <int> GetIdResultsWithNodeQuery(ExecutionHint hint, int top, int skip, IEnumerable <SortInfo> sort, bool?enableAutofilters, bool?enableLifespanFilter) { var queryText = enableAutofilters.GetValueOrDefault() ? AddAutofilterToNodeQuery(Text) : Text; if (enableLifespanFilter.GetValueOrDefault()) { queryText = AddLifespanFilterToNodeQuery(queryText, GetLifespanFilterForNodeQuery()); } var query = NodeQuery.Parse(queryText); if (skip != 0) { query.Skip = skip; } if (top != 0) { query.Top = top; } else if (query.Top == 0) { query.Top = GetDefaultMaxResults(); } query.PageSize = query.Top; if (sort != null && sort.Count() > 0) { throw new NotSupportedException("Sorting override is not allowed on NodeQuery"); } var result = query.Execute(hint); TotalCount = result.Count; return(result.Identifiers.ToList()); }
private IEnumerable <int> GetIdResults(ExecutionHint hint, int top, int skip, IEnumerable <SortInfo> sort, FilterStatus enableAutofilters, FilterStatus enableLifespanFilter) { if (SenseNet.ContentRepository.User.Current.Id == -1 && !this.IsSafe) { var ex = new InvalidOperationException("Cannot execute this query."); ex.Data.Add("EventId", SenseNet.ContentRepository.EventId.Querying.CannotExecuteQuery); ex.Data.Add("Query", this._text); //SenseNet.Diagnostics.Logger.WriteError(SenseNet.ContentRepository.EventId.Error.CannotExecuteQuery, ex); throw ex; } if (IsNodeQuery) { return(GetIdResultsWithNodeQuery(hint, top, skip, sort, enableAutofilters, enableLifespanFilter)); } if (IsContentQuery) { return(GetIdResultsWithLucQuery(top, skip, sort, enableAutofilters, enableLifespanFilter)); } throw new InvalidOperationException("Cannot execute query with null or empty Text"); }
public static User Load(string domain, string name, ExecutionHint hint) { if (domain == null) { throw new ArgumentNullException("domain"); } if (name == null) { throw new ArgumentNullException("name"); } //look for the user ID in the cache by the doman-username key var ck = GetUserCacheKey(domain, name); var userIdobject = DistributedApplication.Cache.Get(ck); if (userIdobject != null) { var userId = Convert.ToInt32(userIdobject); var cachedUser = Node.Load <User>(userId); if (cachedUser != null) { return(cachedUser); } } var path = String.Concat(Repository.ImsFolderPath, RepositoryPath.PathSeparator, domain); var type = ActiveSchema.NodeTypes[typeof(User).Name]; IEnumerable <Node> users; var forceCql = false; if (hint == ExecutionHint.None) { forceCql = StorageContext.Search.IsOuterEngineEnabled && StorageContext.Search.SearchEngine != InternalSearchEngine.Instance; } else if (hint == ExecutionHint.ForceIndexedEngine) { forceCql = true; } else if (hint == ExecutionHint.ForceRelationalEngine) { forceCql = false; } else { throw new NotImplementedException("Unknown ExecutionHint: " + hint); } try { users = forceCql ? ContentQuery.Query(SafeQueries.InTreeAndTypeIsAndName, null, path, type.Name, name).Nodes : users = NodeQuery.QueryNodesByTypeAndPathAndName(type, false, path, false, name).Nodes; } catch (Exception e) { Logger.WriteException(e); return(null); } var count = users.Count(); if (count != 1) { return(null); } var user = users.First() as User; //insert id into cache if (user != null && DistributedApplication.Cache.Get(ck) == null) { DistributedApplication.Cache.Insert(ck, user.Id, CacheDependencyFactory.CreateNodeDependency(user)); } return(user); }
//================================================================== Get result ids private IEnumerable<int> GetIdResults(ExecutionHint hint) { return GetIdResults(hint, Settings.Top, Settings.Skip, Settings.Sort, Settings.EnableAutofilters, Settings.EnableLifespanFilter); }
private IEnumerable<int> GetIdResults(ExecutionHint hint, int top, int skip, IEnumerable<SortInfo> sort, bool? enableAutofilters, bool? enableLifespanFilter) { if (IsNodeQuery) return GetIdResultsWithNodeQuery(hint, top, skip, sort, enableAutofilters, enableLifespanFilter); if (IsContentQuery) return GetIdResultsWithLucQuery(top, skip, sort, enableAutofilters, enableLifespanFilter); throw new InvalidOperationException("Cannot execute query with null or empty Text"); }
private IEnumerable<int> GetIdResultsWithNodeQuery(ExecutionHint hint, int top, int skip, IEnumerable<SortInfo> sort, bool? enableAutofilters, bool? enableLifespanFilter) { var queryText = enableAutofilters.GetValueOrDefault() ? AddAutofilterToNodeQuery(Text) : Text; if (enableLifespanFilter.GetValueOrDefault()) queryText = AddLifespanFilterToNodeQuery(queryText, GetLifespanFilterForNodeQuery()); var query = NodeQuery.Parse(queryText); if(skip != 0) query.Skip = skip; if (top != 0) query.Top = top; else if (query.Top == 0) query.Top = GetDefaultMaxResults(); query.PageSize = query.Top; if (sort != null && sort.Count() > 0) throw new NotSupportedException("Sorting override is not allowed on NodeQuery"); var result = query.Execute(hint); TotalCount = result.Count; return result.Identifiers.ToList(); }
public static User Load(string domain, string name, ExecutionHint hint) { if (domain == null) throw new ArgumentNullException("domain"); if (name == null) throw new ArgumentNullException("name"); //look for the user ID in the cache by the doman-username key var ck = GetUserCacheKey(domain, name); var userIdobject = DistributedApplication.Cache.Get(ck); if (userIdobject != null) { var userId = Convert.ToInt32(userIdobject); var cachedUser = Node.Load<User>(userId); if (cachedUser != null) { //Trace.WriteLine("##UCACHE#>> User ID found in cache: " + ck); return cachedUser; } } //Trace.WriteLine("##UCACHE#>> User ID NOT found in cache: " + ck); var path = String.Concat(Repository.ImsFolderPath, RepositoryPath.PathSeparator, domain); var type = ActiveSchema.NodeTypes[typeof(User).Name]; IEnumerable<Node> users; switch (hint) { case ExecutionHint.None: if (StorageContext.Search.IsOuterEngineEnabled && StorageContext.Search.SearchEngine != InternalSearchEngine.Instance) users = SearchInLucene(path, type.Name, name); else users = NodeQuery.QueryNodesByTypeAndPathAndName(type, false, path, false, name).Nodes; break; case ExecutionHint.ForceRelationalEngine: users = NodeQuery.QueryNodesByTypeAndPathAndName(type, false, path, false, name).Nodes; break; case ExecutionHint.ForceIndexedEngine: users = SearchInLucene(path, type.Name, name); break; default: throw new NotImplementedException(); } var count = users.Count(); if (count == 0) return null; if (count > 1) throw new ApplicationException(string.Format("The Username (='Domain\\Name', in this case '{0}\\{1}') should be unique. {2} matching users have been found.", domain, name, count)); var user = users.First() as User; //insert id into cache if (user != null && DistributedApplication.Cache.Get(ck) == null) { DistributedApplication.Cache.Insert(ck, user.Id, CacheDependencyFactory.CreateNodeDependency(user)); //Trace.WriteLine("##UCACHE#>> User ID inserted into cache: " + ck); } return user; }
// ================================================================== Get result ids private IEnumerable <int> GetIdResults(ExecutionHint hint) { return(GetIdResults(hint, Settings.Top, Settings.Skip, Settings.Sort, Settings.EnableAutofilters, Settings.EnableLifespanFilter, Settings.QueryExecutionMode)); }
public QueryResult Execute(ExecutionHint hint) { return(new QueryResult(GetIdResults(hint), TotalCount)); }
public IEnumerable<int> ExecuteToIds(ExecutionHint hint) { //We need to get the pure id list for one single query. //If you run Execute, it returns a NodeList that loads //all result ids, not only the page you specified. return GetIdResults(hint); }
public static IEnumerable <Node> GetNodes(string path, ExecutionHint hint) { return(GetNodes(path, hint, null, null)); }
public static User Load(string domain, string name, ExecutionHint hint) { if (domain == null) { throw new ArgumentNullException("domain"); } if (name == null) { throw new ArgumentNullException("name"); } //look for the user ID in the cache by the doman-username key var ck = GetUserCacheKey(domain, name); var userIdobject = DistributedApplication.Cache.Get(ck); if (userIdobject != null) { var userId = Convert.ToInt32(userIdobject); var cachedUser = Node.Load <User>(userId); if (cachedUser != null) { //Trace.WriteLine("##UCACHE#>> User ID found in cache: " + ck); return(cachedUser); } } //Trace.WriteLine("##UCACHE#>> User ID NOT found in cache: " + ck); var path = String.Concat(Repository.ImsFolderPath, RepositoryPath.PathSeparator, domain); var type = ActiveSchema.NodeTypes[typeof(User).Name]; IEnumerable <Node> users; switch (hint) { case ExecutionHint.None: if (StorageContext.Search.IsOuterEngineEnabled && StorageContext.Search.SearchEngine != InternalSearchEngine.Instance) { users = SearchInLucene(path, type.Name, name); } else { users = NodeQuery.QueryNodesByTypeAndPathAndName(type, false, path, false, name).Nodes; } break; case ExecutionHint.ForceRelationalEngine: users = NodeQuery.QueryNodesByTypeAndPathAndName(type, false, path, false, name).Nodes; break; case ExecutionHint.ForceIndexedEngine: users = SearchInLucene(path, type.Name, name); break; default: throw new NotImplementedException(); } var count = users.Count(); if (count == 0) { return(null); } if (count > 1) { throw new ApplicationException(string.Format("The Username (='Domain\\Name', in this case '{0}\\{1}') should be unique. {2} matching users have been found.", domain, name, count)); } var user = users.First() as User; //insert id into cache if (user != null && DistributedApplication.Cache.Get(ck) == null) { DistributedApplication.Cache.Insert(ck, user.Id, CacheDependencyFactory.CreateNodeDependency(user)); //Trace.WriteLine("##UCACHE#>> User ID inserted into cache: " + ck); } return(user); }
public static User Load(string domain, string name, ExecutionHint hint) { domain = string.IsNullOrWhiteSpace(domain) ? IdentityManagement.DefaultDomain : domain; if (domain == null) { throw new ArgumentNullException(nameof(domain)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } // look for the user ID in the cache by the doman-username key var ck = GetUserCacheKey(domain, name); var userIdobject = DistributedApplication.Cache.Get(ck); if (userIdobject != null) { var userId = Convert.ToInt32(userIdobject); var cachedUser = Node.Load <User>(userId); if (cachedUser != null) { return(cachedUser); } } var domainPath = string.Concat(RepositoryStructure.ImsFolderPath, RepositoryPath.PathSeparator, domain); var type = ActiveSchema.NodeTypes[typeof(User).Name]; User user; bool forceCql; switch (hint) { case ExecutionHint.None: forceCql = RepositoryInstance.ContentQueryIsAllowed; break; case ExecutionHint.ForceIndexedEngine: forceCql = true; break; case ExecutionHint.ForceRelationalEngine: forceCql = false; break; default: throw new SnNotSupportedException("Unknown ExecutionHint: " + hint); } try { if (forceCql) { var userResult = ContentQuery.Query(SafeQueries.UsersByLoginName, QuerySettings.AdminSettings, domainPath, name); // non-unique user, do not allow login if (userResult.Count > 1) { return(null); } user = userResult.Count == 0 ? null : userResult.Nodes.Cast <User>().FirstOrDefault(); } else { var queryProps = new List <QueryPropertyData> { new QueryPropertyData { PropertyName = LOGINNAME, QueryOperator = Operator.Equal, Value = name } }; var userResult = NodeQuery.QueryNodesByTypeAndPathAndProperty(type, false, domainPath, false, queryProps); // non-unique user, do not allow login if (userResult.Count > 1) { return(null); } user = userResult.Count == 0 ? null : userResult.Nodes.Cast <User>().FirstOrDefault(); } } catch (Exception e) { SnLog.WriteException(e); return(null); } if (user == null) { return(null); } // insert id into cache if (DistributedApplication.Cache.Get(ck) == null) { DistributedApplication.Cache.Insert(ck, user.Id, CacheDependencyFactory.CreateNodeDependency(user)); } return(user); }
public QueryResult Execute(ExecutionHint hint) { return new QueryResult(GetIdResults(hint), TotalCount); }