Inheritance: Expression
Example #1
0
 public static IEnumerable<Node> GetPortletsFromRepo()
 {
     var query = new NodeQuery();
     var expression = new ExpressionList(ChainOperator.And);
     expression.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, PortletsFolderPath));
     expression.Add(new TypeExpression(NodeType.GetByName("Portlet")));
     query.Add(expression);
     return query.Execute().Nodes;
 }
Example #2
0
        private static Expression ParseExpressionList(XmlNode node, XmlNamespaceManager nsmgr, SchemaRoot schema)
        {
            ChainOperator  op       = (ChainOperator)Enum.Parse(typeof(ChainOperator), node.LocalName);
            ExpressionList exprList = new ExpressionList(op);

            foreach (XmlNode subNode in node.SelectNodes("x:*", nsmgr))
            {
                exprList.Add(ParseExpression(subNode, nsmgr, schema));
            }
            return(exprList);
        }
Example #3
0
        private Query CompileExpressionListNode(ExpressionList expression)
        {
            int expCount = expression.Expressions.Count;
            if (expCount == 0)
                throw new NotSupportedException("Do not use empty ExpressionList");

            if (expression.Expressions.Count == 1)
                return CompileExpressionNode(expression.Expressions[0]);

            var result = new BooleanQuery();
            var occur = (expression.OperatorType == ChainOperator.And) ? BooleanClause.Occur.MUST : BooleanClause.Occur.SHOULD;
            foreach (Expression expr in expression.Expressions)
            {
                //var q = CompileExpressionNode(expr);
                //var clause = new BooleanClause(q, occur);
                //result.Add(clause);

                Query q;
                BooleanClause clause;
                var notExp = expr as NotExpression;
                if (notExp != null)
                {
                    q = CompileExpressionNode(notExp.Expression);
                    clause = new BooleanClause(q, BooleanClause.Occur.MUST_NOT);
                }
                else
                {
                    var binwrapper = expr as IBinaryExpressionWrapper;
                    if (binwrapper != null && binwrapper.BinExp.Operator == Operator.NotEqual)
                    {
                        q = CompileBinaryExpression(binwrapper.BinExp.LeftValue, Operator.Equal, binwrapper.BinExp.RightValue);
                        clause = new BooleanClause(q, BooleanClause.Occur.MUST_NOT);
                    }
                    else
                    {
                        q = CompileExpressionNode(expr);
                        clause = new BooleanClause(q, occur);
                    }
                }
                result.Add(clause);
            }
            return result;
        }
Example #4
0
        public static NodeQueryResult GetWebContentTypeList()
        {
            var contentTypeNames = ConfigurationManager.AppSettings[ContentTypeNameListKey];
            if (String.IsNullOrEmpty(contentTypeNames))
                contentTypeNames = DefaultContentTypeName;

            var list = contentTypeNames.Split(',');
            var validCtdNames = new List<string>();
            foreach (var c in list)
                if (IsValidContentType(c.Trim()))
                    validCtdNames.Add(c.Trim());


            var expressionList = new ExpressionList(ChainOperator.Or);
            var query = new NodeQuery();
            foreach (var ctd in validCtdNames)
            {
                var stringExpressionValue = RepositoryPath.Combine(Repository.ContentTypesFolderPath, String.Concat(ActiveSchema.NodeTypes[ctd].NodeTypePath, "/"));
                expressionList.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, stringExpressionValue));
            }

            if (validCtdNames.Count == 0)
            {
                var stringExpressionValue = RepositoryPath.Combine(Repository.ContentTypesFolderPath, String.Concat(ActiveSchema.NodeTypes[DefaultContentTypeName].NodeTypePath, "/"));
                expressionList.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, stringExpressionValue));
            }
            query.Add(expressionList);

            return query.Execute();
        }
        private ActionResult SearchNodeQuery(string searchStr, string searchRoot, string contentTypes)
        {
            if (!string.IsNullOrEmpty(searchStr))
            {
                // simple nodequery
                var query = new NodeQuery();
                query.Add(new SearchExpression(searchStr));
                var nodes = query.Execute().Nodes;

                // filter with path
                if (!string.IsNullOrEmpty(searchRoot))
                    nodes = nodes.Where(n => n.Path.StartsWith(searchRoot));

                // filter with contenttypes
                if (!string.IsNullOrEmpty(contentTypes))
                {
                    var contentTypesArr = GetContentTypes(contentTypes);
                    nodes = nodes.Where(n => contentTypesArr.Contains(n.NodeType.Name));
                }
                var contents = nodes.Where(n => n != null).Select(n => new Content(n, true, false, false, false, 0, 0));

                return Json(contents.ToArray(), JsonRequestBehavior.AllowGet);
            }
            else
            {
                if (string.IsNullOrEmpty(searchRoot) && string.IsNullOrEmpty(contentTypes))
                    return Json(null, JsonRequestBehavior.AllowGet);

                var query = new NodeQuery();
                var andExpression = new ExpressionList(ChainOperator.And);
                query.Add(andExpression);

                // filter with path
                if (!string.IsNullOrEmpty(searchRoot))
                    andExpression.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, searchRoot));

                // filter with contenttypes
                if (!string.IsNullOrEmpty(contentTypes))
                {
                    var contentTypesArr = GetContentTypes(contentTypes);
                    var orExpression = new ExpressionList(ChainOperator.Or);
                    foreach (var contentType in contentTypesArr)
                    {
                        orExpression.Add(new TypeExpression(NodeType.GetByName(contentType), true));
                    }
                    andExpression.Add(orExpression);
                }

                var nodes = query.Execute().Nodes;
                var contents = nodes.Select(n => new Content(n, true, false, false, false, 0, 0));

                return Json(contents.ToArray(), JsonRequestBehavior.AllowGet);
            }
        }
Example #6
0
        /// <summary>
        /// Sets datasource of listview.
        /// </summary>
        /// <remarks>
        /// Loads tags form Content Repository and adds the following properties of them to a datatable:
        /// DisplayName, Created By, Creation Date, Modification Date, Reference Count, Path, Is Blacklisted an Node ID.
        /// Sets this datatable as datasource to the listview.
        /// </remarks>
        private void SetDataSource()
        {
            var refCounts = TagManager.GetTagOccurrencies();

            var exprList = new ExpressionList(ChainOperator.And);

            exprList.Add(new TypeExpression(ActiveSchema.NodeTypes["Tag"], true));
            exprList.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, TagPath));

            var nq = new NodeQuery(exprList);

            var result = nq.Execute();

            var dt = new DataTable();
            _tagsInRepository = new List<string>();

            dt.Columns.AddRange(new[] { 
                                        new DataColumn("DisplayName", typeof(String)),
                                        new DataColumn("CreatedBy", typeof(String)), 
                                        new DataColumn("CreationDate", typeof(DateTime)), 
                                        new DataColumn("ModificationDate", typeof(DateTime)), 
                                        new DataColumn("RefCount", typeof(Int32)), 
                                        new DataColumn("Path", typeof(String)),
                                        new DataColumn("IsBlackListed", typeof(String)),
                                        new DataColumn("ID", typeof(Int32))
                                });

            foreach (var item in result.Nodes.ToList())
            {
                dt.Rows.Add(new object[]
                                {
                                    item.DisplayName,
                                    item.CreatedBy,
                                    item.CreationDate,
                                    item.ModificationDate,
                                    refCounts.ContainsKey(item.DisplayName) ? refCounts[item.DisplayName] : 0,
                                    item.Path, GetIsBlackListed(item.Id),
                                    Convert.ToInt32(item.Id)
                                });
                if (GetIsBlackListed(item.Id) == "No")
                    _tagsInRepository.Add(item.DisplayName);
            }

            _allTags = TagManager.GetAllTags(null, SearchPaths);

            dt.DefaultView.Sort = !String.IsNullOrEmpty(Request.QueryString["OrderBy"]) ? String.Concat(Request.QueryString["OrderBy"], " " + Request.QueryString["Direction"]) : "DisplayName ASC";

            _lv = FindControl("LVTags") as ListView;
            if (_lv != null)
            {
                _lv.DataSource = dt.DefaultView;
                _lv.DataBind();
            }
        }
Example #7
0
        public void NodeQueryTest001_XML()
        {
            NodeQuery query = new NodeQuery();
            ExpressionList orList = new ExpressionList(ChainOperator.Or);
            query.Add(new ReferenceExpression(ReferenceAttribute.Parent, orList));
            orList.Add(new StringExpression(StringAttribute.Name, StringOperator.EndsWith, ".txt"));
            orList.Add(new StringExpression(StringAttribute.Name, StringOperator.EndsWith, ".doc"));

            var nodes = query.Execute();

            Assert.IsTrue(nodes == null || nodes.Count == 0);
        }
Example #8
0
        //-- Test helper ---------------------------------------------------------------------

        private static NodeQuery CreateComplexQuery()
        {
            //	(
            //		Node.Doughter.Father.Name = "Adam"
            //		Or
            //		Node.Doughter.Mother.Name = "Adam"
            //	)
            //	Or
            //	(
            //		Node.Son.Father.Name = "Adam"
            //		Or
            //		Node.Son.Mother.Name = "Adam"
            //	)

            PropertyType motherSlot = ActiveSchema.PropertyTypes["Mother"];
            PropertyType fatherSlot = ActiveSchema.PropertyTypes["Father"];
            PropertyType daughterSlot = ActiveSchema.PropertyTypes["Daughter"];
            PropertyType sonSlot = ActiveSchema.PropertyTypes["Son"];

            StringExpression nameExp1 = new StringExpression(StringAttribute.Name, StringOperator.Equal, "Adam");

            ReferenceExpression refExp1 = new ReferenceExpression(fatherSlot, nameExp1);
            ReferenceExpression refExp2 = new ReferenceExpression(motherSlot, nameExp1);
            ExpressionList orList1 = new ExpressionList(ChainOperator.Or);
            orList1.Add(refExp1);
            orList1.Add(refExp2);

            ReferenceExpression refExp3 = new ReferenceExpression(daughterSlot, orList1);
            ReferenceExpression refExp4 = new ReferenceExpression(sonSlot, orList1);
            ExpressionList orList2 = new ExpressionList(ChainOperator.Or);
            orList2.Add(refExp3);
            orList2.Add(refExp4);

            ExpressionList orList3 = new ExpressionList(ChainOperator.Or);
            orList3.Add(refExp3);
            orList3.Add(refExp4);

            NodeQuery query = new NodeQuery();
            query.Add(orList3);
            return query;
        }
Example #9
0
		public void NodeQuery_BuildFromXml()
		{
			SchemaEditor editor = new SchemaEditor();
			NodeType nodeType1 = editor.CreateNodeType(null, "nodeType1");
			NodeType nodeType2 = editor.CreateNodeType(null, "nodeType2");
			PropertyType stringSlot1 = editor.CreatePropertyType("stringSlot1", DataType.String);
			PropertyType stringSlot2 = editor.CreatePropertyType("stringSlot2", DataType.String);
			PropertyType intSlot1 = editor.CreatePropertyType("intSlot1", DataType.Int);
			PropertyType intSlot2 = editor.CreatePropertyType("intSlot2", DataType.Int);
			PropertyType dateTimeSlot1 = editor.CreatePropertyType("dateTimeSlot1", DataType.DateTime);
			PropertyType dateTimeSlot2 = editor.CreatePropertyType("dateTimeSlot2", DataType.DateTime);
			PropertyType currencySlot1 = editor.CreatePropertyType("currencySlot1", DataType.Currency);
			PropertyType currencySlot2 = editor.CreatePropertyType("currencySlot2", DataType.Currency);
			PropertyType refSlot1 = editor.CreatePropertyType("refSlot1", DataType.Reference);
			PropertyType refSlot2 = editor.CreatePropertyType("refSlot2", DataType.Reference);

			NodeQuery query = new NodeQuery();

			//==== Operators
			ExpressionList strOpExp = new ExpressionList(ChainOperator.Or);
			query.Add(strOpExp);
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.Contains, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.EndsWith, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.Equal, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.GreaterThan, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.GreaterThanOrEqual, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.LessThan, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.LessThanOrEqual, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.NotEqual, "{path}"));
			strOpExp.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "{path}"));

			//==== StringExpression
			ExpressionList strExp = new ExpressionList(ChainOperator.Or);
			query.Add(strExp);
			strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, "{value}"));
			strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, stringSlot2));
			strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, StringAttribute.Path));
			strExp.Add(new StringExpression(stringSlot1, StringOperator.Equal, (string)null));
			strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, "{value}"));
			strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, stringSlot2));
			strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, StringAttribute.Path));
			strExp.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, (string)null));

			//==== IntExpression
			ExpressionList intExp = new ExpressionList(ChainOperator.Or);
			query.Add(intExp);
			intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, 123));
			intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, IntAttribute.MajorVersion));
			intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, intSlot2));
			intExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.Equal, (int?)null));
			intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, 123));
			intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, IntAttribute.MajorVersion));
			intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, intSlot2));
			intExp.Add(new IntExpression(intSlot1, ValueOperator.Equal, (int?)null));

			//==== DateTimeExpression
			ExpressionList dtExp = new ExpressionList(ChainOperator.Or);
			query.Add(dtExp);
			dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, DateTime.Now));
			dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, DateTimeAttribute.ModificationDate));
			dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, dateTimeSlot2));
			dtExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.Equal, (DateTime?)null));
			dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, DateTime.Now));
			dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, DateTimeAttribute.ModificationDate));
			dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, dateTimeSlot2));
			dtExp.Add(new DateTimeExpression(dateTimeSlot1, ValueOperator.Equal, (DateTime?)null));

			//==== CurrencyExpression
			ExpressionList curExp = new ExpressionList(ChainOperator.Or);
			query.Add(curExp);
			curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, (decimal)123.456));
			curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, currencySlot2));
			curExp.Add(new CurrencyExpression(currencySlot1, ValueOperator.Equal, (decimal?)null));

			//==== ReferenceExpression
			ExpressionList subExp = new ExpressionList(ChainOperator.And);
			subExp.Add(new IntExpression(IntAttribute.Index, ValueOperator.GreaterThan, 123));
			subExp.Add(new DateTimeExpression(DateTimeAttribute.CreationDate, ValueOperator.GreaterThan, DateTime.Now));
			ExpressionList refExp = new ExpressionList(ChainOperator.Or);
			query.Add(refExp);
			refExp.Add(new ReferenceExpression(refSlot1));
			refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy));
			refExp.Add(new ReferenceExpression(refSlot1, (Node)null));
			refExp.Add(new ReferenceExpression(refSlot1, Repository.Root));
			refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, (Node)null));
			refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, Repository.Root));
			refExp.Add(new ReferenceExpression(refSlot1, subExp));
			refExp.Add(new ReferenceExpression(ReferenceAttribute.LockedBy, subExp));

			//==== TypeExpression
			ExpressionList typeExp = new ExpressionList(ChainOperator.Or);
			query.Add(typeExp);
			typeExp.Add(new TypeExpression(nodeType1));
			typeExp.Add(new TypeExpression(nodeType2, true));

			//==== Negation
			Expression negExp = new NotExpression(
				new ExpressionList(ChainOperator.And,
					new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "/Root1/"),
					new StringExpression(StringAttribute.Name, StringOperator.NotEqual, "name")
					));
			query.Add(negExp);

			//==== Orders
			query.Orders.Add(new SearchOrder(DateTimeAttribute.ModificationDate, OrderDirection.Desc));
			query.Orders.Add(new SearchOrder(IntAttribute.MajorVersion, OrderDirection.Asc));
			query.Orders.Add(new SearchOrder(StringAttribute.Name, OrderDirection.Asc));

			//==== Paging
			query.PageSize = 123;
			query.StartIndex = 987;

			string queryString = query.ToXml();
			NodeQueryAccessor queryAcc = new NodeQueryAccessor(new NodeQuery());
			NodeQuery newQuery = queryAcc.Parse(queryString, editor);
			string newQueryString = newQuery.ToXml();

			Assert.IsTrue(queryString != null && queryString == newQueryString);
		}
Example #10
0
        private Content[] GetFeed2Private(string feedPath, bool onlyFiles, bool onlyFolders, int start, int limit)
		{
			Node container = GetNodeById(feedPath);

			if (container == null) throw new NodeLoadException("Error loading path");
			IFolder folder = container as IFolder;
			if (folder == null) return new Content[] { };

			IEnumerable<Node> nodeList;
			NodeQuery query;

			if (onlyFiles || onlyFolders)
			{
				nodeList = onlyFiles ?
					from child in folder.Children where child is IFile select child :
					from child in folder.Children where child is IFolder select child;
			}
			else
			{
				//nodeList = folder.Children;
				if (start == 0 && limit == 0)
				{
					nodeList = folder.Children;
				}
				else
				{
					SmartFolder smartFolder = folder as SmartFolder;
					if (folder is SmartFolder)
					{
                        query = new NodeQuery();
                        string queryString = ((SmartFolder)folder).Query;

                        ExpressionList orExp = new ExpressionList(ChainOperator.Or);
                        
                        if (!string.IsNullOrEmpty(queryString))
                            orExp.Add(NodeQuery.Parse(queryString));
                        
                        orExp.Add(new IntExpression(IntAttribute.ParentId, ValueOperator.Equal, container.Id));
                        query.Add(orExp);
					}
					else
					{
						query = new NodeQuery();
						query.Add(new IntExpression(IntAttribute.ParentId, ValueOperator.Equal, container.Id));
					}
					query.PageSize = limit;
					query.StartIndex = start == 0 ? 1 : start;
					nodeList = query.Execute().Nodes;
				}
			}

			return nodeList.Select(node => new Content(node, false, false, false, false, start, limit)).ToArray();
		}
Example #11
0
        public void NodeQuery_Bug2125()
        {
            Expression exp;
            ExpressionList expList;

            var query1 = new NodeQuery();
            exp = new SearchExpression("dummy");
            query1.Add(exp);

            Assert.IsTrue(Object.ReferenceEquals( exp.Parent, query1), "#1");

            expList = new ExpressionList(ChainOperator.And);
            query1.Add(expList);

            Assert.IsTrue(Object.ReferenceEquals(expList.Parent, query1), "#2");

            exp = new StringExpression(StringAttribute.Name, StringOperator.Equal, "Root");
            expList.Add(exp);

            Assert.IsTrue(Object.ReferenceEquals(exp.Parent, expList), "#3");

            exp = new IntExpression(IntAttribute.Id, ValueOperator.Equal, 2);
            expList.Add(exp);

            Assert.IsTrue(Object.ReferenceEquals(exp.Parent, expList), "#4");

            //------------------------------------------------------------------------------------

            var query2 = new NodeQuery
            (
                new SearchExpression("dummy"),
                new ExpressionList
                (
                    ChainOperator.And,
                    new StringExpression(StringAttribute.Name, StringOperator.Equal, "Root"),
                    new IntExpression(IntAttribute.Id, ValueOperator.Equal, 2)
                )
            );

            Assert.IsTrue(Object.ReferenceEquals(query2.Expressions[0].Parent, query2), "#5");
            Assert.IsTrue(Object.ReferenceEquals(query2.Expressions[1].Parent, query2), "#6");
            Assert.IsTrue(Object.ReferenceEquals(((ExpressionList)query2.Expressions[1]).Expressions[0].Parent, query2.Expressions[1]), "#7");
            Assert.IsTrue(Object.ReferenceEquals(((ExpressionList)query2.Expressions[1]).Expressions[1].Parent, query2.Expressions[1]), "#8");
        }
Example #12
0
        public static IEnumerable<Node> GetContainerUsers(Node container)
        {
            var query = new NodeQuery();
            ExpressionList expressionList = new ExpressionList(ChainOperator.And);

            // nodetype
            TypeExpression typeExpression = new TypeExpression(Common.GetNodeType(ADObjectType.User));
            expressionList.Add(typeExpression);

            // from container as root
            StringExpression pathExpression = new StringExpression(StringAttribute.Path, StringOperator.StartsWith, container.Path);
            expressionList.Add(pathExpression);

            query.Add(expressionList);

            var result = query.Execute();
            return result.Nodes;
        }
Example #13
0
        private void CheckUniqueUser()
        {
            var path = Path;

            if (!path.StartsWith(string.Concat(Repository.ImsFolderPath, RepositoryPath.PathSeparator)) || Parent.Path == Repository.ImsFolderPath)
            {
                throw new InvalidOperationException("Invalid path: user nodes can only be saved under a /Root/IMS/[DomainName] folder.");
            }

            string domainPath = path.Substring(0, Repository.ImsFolderPath.Length + 1 + path.Substring(Repository.ImsFolderPath.Length + 1).IndexOf('/') + 1);

            //We validate here the uniqueness of the user. The constraint is the user name itself and that in Active Directory
            //there must not exist two users and/or groups with the same name under a domain. Organizational units may have
            //the same name as a user.

            //CONDITIONAL EXECUTE
            IEnumerable<int> identifiers;
            int count;
            if (StorageContext.Search.IsOuterEngineEnabled && StorageContext.Search.SearchEngine != InternalSearchEngine.Instance)
            {
                var query = new NodeQuery();
                var nameExpression = new StringExpression(StringAttribute.Name, StringOperator.Equal, Name);
                var pathExpression = new StringExpression(StringAttribute.Path, StringOperator.StartsWith, domainPath);
                var orTypes = new ExpressionList(ChainOperator.Or);
                orTypes.Add(new TypeExpression(ActiveSchema.NodeTypes["User"]));
                orTypes.Add(new TypeExpression(ActiveSchema.NodeTypes["Group"]));

                query.Add(pathExpression);
                query.Add(nameExpression);
                query.Add(orTypes);
                var result = query.Execute();
                identifiers = result.Identifiers;
                count = result.Count;
            }
            else
            {
                var nodes = NodeQuery.QueryNodesByTypeAndPathAndName(new List<NodeType> { ActiveSchema.NodeTypes["User"], ActiveSchema.NodeTypes["Group"] }, false, domainPath, false, Name).Nodes;

                var nodeList = nodes as NodeList<Node>;
                if (nodeList != null)
                {
                    identifiers = nodeList.GetIdentifiers();
                    count = nodeList.Count;
                }
                else
                {
                    identifiers = nodes.Select(x => x.Id);
                    count = identifiers.Count();
                }
            }

            if (count > 1 || (count == 1 && identifiers.First() != this.Id))
            {
                var ids = String.Join(", ", (from x in identifiers select x.ToString()).ToArray());
                throw GetUniqueUserException(domainPath, ids);
            }
        }
        private User GetRegisteredUser(string resetEmail, string domain)
        {
            if (String.IsNullOrEmpty(resetEmail))
                throw new ArgumentNullException("resetEmail");
            if (String.IsNullOrEmpty(domain))
                throw new ArgumentNullException("domain");

            var query = new NodeQuery();
            var expressionList = new ExpressionList(ChainOperator.And);
            expressionList.Add(new TypeExpression(ActiveSchema.NodeTypes[Configuration.UserTypeName], false));
            expressionList.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, string.Concat(Repository.ImsFolderPath, RepositoryPath.PathSeparator, domain, RepositoryPath.PathSeparator)));
            expressionList.Add(new StringExpression(ActiveSchema.PropertyTypes["Email"], StringOperator.Equal, resetEmail));
            query.Add(expressionList);
            AccessProvider.ChangeToSystemAccount();
            var resultList = query.Execute();
            AccessProvider.RestoreOriginalUser();

            // no user has beeen found
            if (resultList.Count == 0)
                return null;

            var u = resultList.Nodes.First() as User;
            return u;
        }
Example #15
0
        public void AddClause(Expression expression, ChainOperator chainOp)
        {
            if (expression == null)
                throw new ArgumentNullException("expression");

            ExpressionList finalExpList;
            var origExpList = expression as ExpressionList;
            
            if (origExpList != null)
            {
                finalExpList = origExpList;
            }
            else
            {
                finalExpList = new ExpressionList(chainOp);
                finalExpList.Add(expression);
            }

            this.Text = AddFilterToNodeQuery(Text, finalExpList.ToXml());
        }