Beispiel #1
0
 IEnumerable <BinaryOperator> GetBinaryOperators(CriteriaOperatorExtractor extractor, FilterProviderBase providerBase)
 {
     return(extractor.BinaryOperators.Where(
                @operator =>
                @operator.RightOperand is OperandValue &&
                ReferenceEquals(((OperandValue)@operator.RightOperand).Value, providerBase.FilterMemberName)));
 }
        private CriteriaOperatorExtractor GetBinaryOperatorExtractor(CriteriaOperator criteriaOperator)
        {
            var binaryOperatorExtractor = new CriteriaOperatorExtractor();

            binaryOperatorExtractor.Extract(criteriaOperator);
            return(binaryOperatorExtractor);
        }
        public void ExtractMethodName()
        {
            var unaryOperator = new UnaryOperator(UnaryOperatorType.IsNull, "");

            CriteriaOperatorExtractor binaryOperatorExtractor = GetBinaryOperatorExtractor(unaryOperator);

            Assert.AreEqual(unaryOperator, binaryOperatorExtractor.UnaryOperators[0]);
        }
        public void ExtractNullOperator()
        {
            var nullOperator = new NullOperator("");

            CriteriaOperatorExtractor binaryOperatorExtractor = GetBinaryOperatorExtractor(nullOperator);

            Assert.AreEqual(nullOperator, binaryOperatorExtractor.NullOperators[0]);
        }
        public void ExtractNotOperator()
        {
            var notOperator = new NotOperator();

            CriteriaOperatorExtractor binaryOperatorExtractor = GetBinaryOperatorExtractor(notOperator);

            Assert.AreEqual(notOperator, binaryOperatorExtractor.NotOperators[0]);
        }
        public void ExtractContainsNullOperator()
        {
            var nullOperator     = new NullOperator();
            var containsOperator = new ContainsOperator("", nullOperator);

            CriteriaOperatorExtractor binaryOperatorExtractor = GetBinaryOperatorExtractor(containsOperator);

            Assert.AreEqual(nullOperator, binaryOperatorExtractor.NullOperators[0]);
        }
        public void RemoveRootOperator()
        {
            CriteriaOperator unaryOperator = new UnaryOperator(UnaryOperatorType.IsNull, "prop2");

            var binaryOperatorExtractor = new CriteriaOperatorExtractor();

            binaryOperatorExtractor.Remove(ref unaryOperator, unaryOperator.ToString());

            Assert.IsNull(unaryOperator);
        }
 public void ExtractGroupOperator()
 {
     BinaryOperator binaryOperator2;
     CriteriaOperator groupOperator;
     BinaryOperator binaryOperator = getGroupOperator(out binaryOperator2, out groupOperator);
     var extractor = new CriteriaOperatorExtractor();
     extractor.Extract(groupOperator);
     Assert.AreEqual(binaryOperator, extractor.BinaryOperators[0]);
     Assert.AreEqual(binaryOperator2, extractor.BinaryOperators[1]);
 }
Beispiel #9
0
        public void Merge(int objectTypeToMerge, int objectType)
        {
            foreach (var selectStatement in _selectStatements)
            {
                var criteriaOperatorExtractor = new CriteriaOperatorExtractor();
                var binaryOperator            = getOperator(objectTypeToMerge);
                var binaryOperator1           = getOperator(objectType);

                criteriaOperatorExtractor.Replace(ref selectStatement.Condition, binaryOperator.ToString(), new GroupOperator(GroupOperatorType.Or, binaryOperator1, binaryOperator));
            }
        }
        public void ExtractGroupedNullOperator()
        {
            var nullOperator1 = new NullOperator();
            var nullOperator2 = new NullOperator();
            var groupOperator = new GroupOperator(nullOperator1, nullOperator2);

            CriteriaOperatorExtractor binaryOperatorExtractor = GetBinaryOperatorExtractor(groupOperator);

            Assert.AreEqual(nullOperator1, binaryOperatorExtractor.NullOperators[0]);
            Assert.AreEqual(nullOperator2, binaryOperatorExtractor.NullOperators[1]);
        }
        public void ReplaceRootOperator()
        {
            CriteriaOperator unaryOperator = new UnaryOperator(UnaryOperatorType.IsNull, "prop2");

            var binaryOperatorExtractor = new CriteriaOperatorExtractor();
            var replaceOperator         = new BinaryOperator("pr", 1);

            binaryOperatorExtractor.Replace(ref unaryOperator, unaryOperator.ToString(), replaceOperator);

            Assert.AreEqual(unaryOperator, replaceOperator);
        }
        public void RemoveNestedOperator()
        {
            var unaryOperator = new UnaryOperator(UnaryOperatorType.IsNull, "prop2");
            CriteriaOperator groupOperator = new GroupOperator(new BinaryOperator("pro1", 1), unaryOperator);

            var binaryOperatorExtractor = new CriteriaOperatorExtractor();

            binaryOperatorExtractor.Remove(ref groupOperator, unaryOperator.ToString());

            Assert.AreEqual(new BinaryOperator("pro1", 1).ToString(), groupOperator.ToString());
        }
Beispiel #13
0
        public void Merge(int objectTypeToMerge, int objectType)
        {
            foreach (var selectStatement in _selectStatements)
            {
                var criteriaOperatorExtractor = new CriteriaOperatorExtractor();
                var binaryOperator = getOperator(objectTypeToMerge);
                var binaryOperator1 = getOperator(objectType);

                criteriaOperatorExtractor.Replace(ref selectStatement.Condition, binaryOperator.ToString(), new GroupOperator(GroupOperatorType.Or, binaryOperator1, binaryOperator));
            }

        }
        public void ReplaceNestedOperator()
        {
            var unaryOperator = new UnaryOperator(UnaryOperatorType.BitwiseNot, "pro");
            CriteriaOperator criteriaOperator = new GroupOperator(new BinaryOperator(), unaryOperator);

            var binaryOperatorExtractor = new CriteriaOperatorExtractor();
            var notOperator             = new NotOperator();

            binaryOperatorExtractor.Replace(ref criteriaOperator, unaryOperator.ToString(), notOperator);

            Assert.AreEqual(((GroupOperator)criteriaOperator).Operands[1], notOperator);
        }
        public void ExtractGroupOperator()
        {
            int              dayOfYear = DateTime.Now.DayOfYear;
            BinaryOperator   binaryOperator2;
            CriteriaOperator groupOperator;
            BinaryOperator   binaryOperator = getGroupOperator(out binaryOperator2, out groupOperator);
            var              extractor      = new CriteriaOperatorExtractor();

            extractor.Extract(groupOperator);
            Assert.AreEqual(binaryOperator, extractor.BinaryOperators[0]);
            Assert.AreEqual(binaryOperator2, extractor.BinaryOperators[1]);
        }
        public void ExtractNestedGroupOperator()
        {
            BinaryOperator binaryOperator2;
            CriteriaOperator nestedGroupOperator;
            BinaryOperator binaryOperator1 = getGroupOperator(out binaryOperator2, out nestedGroupOperator);
            var groupOperator = new GroupOperator(nestedGroupOperator, binaryOperator1, binaryOperator2);
            CriteriaOperator containsOperator = new ContainsOperator("", groupOperator);

            var extractor = new CriteriaOperatorExtractor();
            extractor.Extract(containsOperator);

            Assert.AreEqual(4, extractor.BinaryOperators.Count);
            Assert.AreEqual(binaryOperator1, extractor.BinaryOperators[0]);
            Assert.AreEqual(binaryOperator2, extractor.BinaryOperators[1]);
            Assert.AreEqual(binaryOperator1, extractor.BinaryOperators[2]);
            Assert.AreEqual(binaryOperator2, extractor.BinaryOperators[3]);
        }
        public void ExtractNestedGroupOperator()
        {
            BinaryOperator   binaryOperator2;
            CriteriaOperator nestedGroupOperator;
            BinaryOperator   binaryOperator1 = getGroupOperator(out binaryOperator2, out nestedGroupOperator);
            var groupOperator = new GroupOperator(nestedGroupOperator, binaryOperator1, binaryOperator2);
            CriteriaOperator containsOperator = new ContainsOperator("", groupOperator);

            var extractor = new CriteriaOperatorExtractor();

            extractor.Extract(containsOperator);

            Assert.AreEqual(4, extractor.BinaryOperators.Count);
            Assert.AreEqual(binaryOperator1, extractor.BinaryOperators[0]);
            Assert.AreEqual(binaryOperator2, extractor.BinaryOperators[1]);
            Assert.AreEqual(binaryOperator1, extractor.BinaryOperators[2]);
            Assert.AreEqual(binaryOperator2, extractor.BinaryOperators[3]);
        }
Beispiel #18
0
        public SelectStatement ApplyCondition(SelectStatement statement)
        {
            var extractor = new CriteriaOperatorExtractor();

            extractor.Extract(statement.Condition);

            foreach (FilterProviderBase provider in FilterProviderManager.Providers)
            {
                FilterProviderBase providerBase = FilterProviderManager.GetFilterProvider(statement.TableName, provider.FilterMemberName, StatementContext.Select);
                if (providerBase != null)
                {
                    IEnumerable <BinaryOperator> binaryOperators = GetBinaryOperators(extractor, providerBase);
                    if (!FilterIsShared(statement.TableName, providerBase.Name) && !binaryOperators.Any())
                    {
                        string nodeAlias = GetNodeAlias(statement, providerBase);
                        ApplyCondition(statement, providerBase, nodeAlias);
                    }
                }
            }
            return(statement);
        }
        public void RemoveRootOperator()
        {
            CriteriaOperator unaryOperator = new UnaryOperator(UnaryOperatorType.IsNull, "prop2");

            var binaryOperatorExtractor = new CriteriaOperatorExtractor();
            binaryOperatorExtractor.Remove(ref unaryOperator, unaryOperator.ToString());

            Assert.IsNull(unaryOperator);
        }
        public void RemoveNestedOperator()
        {
            var unaryOperator = new UnaryOperator(UnaryOperatorType.IsNull, "prop2");
            CriteriaOperator groupOperator = new GroupOperator(new BinaryOperator("pro1", 1), unaryOperator);

            var binaryOperatorExtractor = new CriteriaOperatorExtractor();
            binaryOperatorExtractor.Remove(ref groupOperator, unaryOperator.ToString());

            Assert.AreEqual(new BinaryOperator("pro1", 1).ToString(), groupOperator.ToString());
        }
 IEnumerable<BinaryOperator> GetBinaryOperators(CriteriaOperatorExtractor extractor, FilterProviderBase providerBase) {
     return extractor.BinaryOperators.Where(
                                               @operator =>
                                               @operator.RightOperand is OperandValue &&
                                               ReferenceEquals(((OperandValue) @operator.RightOperand).Value, providerBase.FilterMemberName));
 }
        public void ReplaceRootOperator()
        {
            CriteriaOperator unaryOperator = new UnaryOperator(UnaryOperatorType.IsNull, "prop2");

            var binaryOperatorExtractor = new CriteriaOperatorExtractor();
            var replaceOperator = new BinaryOperator("pr", 1);
            binaryOperatorExtractor.Replace(ref unaryOperator, unaryOperator.ToString(), replaceOperator);

            Assert.AreEqual(unaryOperator, replaceOperator);
        }
        public void ReplaceNestedOperator()
        {
            var unaryOperator = new UnaryOperator(UnaryOperatorType.BitwiseNot, "pro");
            CriteriaOperator criteriaOperator = new GroupOperator(new BinaryOperator(), unaryOperator);

            var binaryOperatorExtractor = new CriteriaOperatorExtractor();
            var notOperator = new NotOperator();
            binaryOperatorExtractor.Replace(ref criteriaOperator, unaryOperator.ToString(), notOperator);

            Assert.AreEqual(((GroupOperator) criteriaOperator).Operands[1], notOperator);
        }
 private CriteriaOperatorExtractor GetBinaryOperatorExtractor(CriteriaOperator criteriaOperator)
 {
     var binaryOperatorExtractor = new CriteriaOperatorExtractor();
     binaryOperatorExtractor.Extract(criteriaOperator);
     return binaryOperatorExtractor;
 }
        public SelectStatement ApplyCondition(SelectStatement statement)
        {
            var extractor = new CriteriaOperatorExtractor();
            extractor.Extract(statement.Condition);
            traceStatement(statement, "ApplyCondition");

            foreach (FilterProviderBase provider in FilterProviderManager.Providers){
                FilterProviderBase providerBase = FilterProviderManager.GetFilterProvider(provider.FilterMemberName, StatementContext.Select);
                if (providerBase!= null){
                    Tracing.Tracer.LogVerboseValue("providerName", providerBase.Name);
                    IEnumerable<BinaryOperator> binaryOperators = GetBinaryOperators(extractor, providerBase);
                    if (!FilterIsShared(statement.TableName,providerBase.Name) && binaryOperators.Count() == 0&&!IsSystemTable(statement.TableName)){
                        string nodeAlias = GetNodeAlias(statement, providerBase);
                        ApplyCondition(statement, providerBase, nodeAlias);
                    }
                }
            }
            return statement;
        }