Inheritance: Expression, IBinaryExpressionWrapper
Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
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);
            }
        }