示例#1
0
        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);
                if (providerBase!= null)
                {
                    Tracing.Tracer.LogVerboseValue("providerName", providerBase.Name);
                    IEnumerable<BinaryOperator> binaryOperators =
                        extractor.BinaryOperators.Where(
                            @operator =>
                            @operator.RightOperand is OperandValue &&
                            ReferenceEquals(((OperandValue) @operator.RightOperand).Value, providerBase.FilterMemberName));
                    if (!FilterIsShared(statement.TableName,providerBase.Name) && binaryOperators.Count() == 0&&!IsSystemTable(statement.TableName))
                    {
                        string s = providerBase.FilterValue== null? null:providerBase.FilterValue.ToString();

                        string nodeAlias = statement.Operands.OfType<QueryOperand>().Where(
                                               operand => operand.ColumnName == providerBase.FilterMemberName).Select(
                                               operand => operand.NodeAlias).FirstOrDefault() ?? statement.Alias;
                        statement.Condition &= new QueryOperand(providerBase.FilterMemberName, nodeAlias) ==s;
                        Tracing.Tracer.LogVerboseValue("new_statement", statement);
                    }
                }
            }
            return statement;
        }
 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]);
 }
        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]);
        }
 private CriteriaOperatorExtractor GetBinaryOperatorExtractor(CriteriaOperator criteriaOperator)
 {
     var binaryOperatorExtractor = new CriteriaOperatorExtractor();
     binaryOperatorExtractor.Extract(criteriaOperator);
     return binaryOperatorExtractor;
 }
        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);
        }
        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());
        }