public override FilterNode Visit(SingleValueFunctionCallNode nodeIn)
        {
            var fieldNode = nodeIn.Parameters.ElementAt(0);

            if (string.Equals(nodeIn.Name, "empty", StringComparison.OrdinalIgnoreCase))
            {
                return(new FilterComparison(PropertyPathVisitor.Visit(fieldNode), FilterOperator.Empty, FilterValue.Null));
            }

            var valueNode = nodeIn.Parameters.ElementAt(1);

            if (string.Equals(nodeIn.Name, "endswith", StringComparison.OrdinalIgnoreCase))
            {
                var value = ConstantWithTypeVisitor.Visit(valueNode);

                return(new FilterComparison(PropertyPathVisitor.Visit(fieldNode), FilterOperator.EndsWith, value));
            }

            if (string.Equals(nodeIn.Name, "startswith", StringComparison.OrdinalIgnoreCase))
            {
                var value = ConstantWithTypeVisitor.Visit(valueNode);

                return(new FilterComparison(PropertyPathVisitor.Visit(fieldNode), FilterOperator.StartsWith, value));
            }

            if (string.Equals(nodeIn.Name, "contains", StringComparison.OrdinalIgnoreCase))
            {
                var value = ConstantWithTypeVisitor.Visit(valueNode);

                return(new FilterComparison(PropertyPathVisitor.Visit(fieldNode), FilterOperator.Contains, value));
            }

            throw new NotSupportedException();
        }
Beispiel #2
0
        public static SortNode OrderBy(OrderByClause clause)
        {
            var path = PropertyPathVisitor.Visit(clause.Expression);

            if (clause.Direction == OrderByDirection.Ascending)
            {
                return(new SortNode(path, SortOrder.Ascending));
            }
            else
            {
                return(new SortNode(path, SortOrder.Descending));
            }
        }
        public override FilterNode Visit(BinaryOperatorNode nodeIn)
        {
            if (nodeIn.OperatorKind == BinaryOperatorKind.And)
            {
                return(new FilterJunction(FilterJunctionType.And, nodeIn.Left.Accept(this), nodeIn.Right.Accept(this)));
            }

            if (nodeIn.OperatorKind == BinaryOperatorKind.Or)
            {
                return(new FilterJunction(FilterJunctionType.Or, nodeIn.Left.Accept(this), nodeIn.Right.Accept(this)));
            }

            if (nodeIn.Left is SingleValueFunctionCallNode functionNode)
            {
                var regexFilter = Visit(functionNode);

                var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                if (value.ValueType == FilterValueType.Boolean && value.Value is bool booleanRight)
                {
                    if ((nodeIn.OperatorKind == BinaryOperatorKind.Equal && !booleanRight) ||
                        (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual && booleanRight))
                    {
                        regexFilter = new FilterNegate(regexFilter);
                    }

                    return(regexFilter);
                }
            }
            else
            {
                if (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(new FilterComparison(PropertyPathVisitor.Visit(nodeIn.Left), FilterOperator.NotEquals, value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.Equal)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(new FilterComparison(PropertyPathVisitor.Visit(nodeIn.Left), FilterOperator.Equals, value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.LessThan)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(new FilterComparison(PropertyPathVisitor.Visit(nodeIn.Left), FilterOperator.LessThan, value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.LessThanOrEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(new FilterComparison(PropertyPathVisitor.Visit(nodeIn.Left), FilterOperator.LessThanOrEqual, value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThan)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(new FilterComparison(PropertyPathVisitor.Visit(nodeIn.Left), FilterOperator.GreaterThan, value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(new FilterComparison(PropertyPathVisitor.Visit(nodeIn.Left), FilterOperator.GreaterThanOrEqual, value));
                }
            }

            throw new NotSupportedException();
        }
        public override FilterNode Visit(InNode nodeIn)
        {
            var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

            return(new FilterComparison(PropertyPathVisitor.Visit(nodeIn.Left), FilterOperator.In, value));
        }
Beispiel #5
0
        public override FilterNode <ClrValue> Visit(InNode nodeIn)
        {
            var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

            return(ClrFilter.In(PropertyPathVisitor.Visit(nodeIn.Left), value));
        }
Beispiel #6
0
        public override FilterNode <ClrValue> Visit(BinaryOperatorNode nodeIn)
        {
            if (nodeIn.OperatorKind == BinaryOperatorKind.And)
            {
                return(ClrFilter.And(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this)));
            }

            if (nodeIn.OperatorKind == BinaryOperatorKind.Or)
            {
                return(ClrFilter.Or(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this)));
            }

            if (nodeIn.Left is SingleValueFunctionCallNode functionNode)
            {
                if (string.Equals(functionNode.Name, "geo.distance", StringComparison.OrdinalIgnoreCase) && nodeIn.OperatorKind == BinaryOperatorKind.LessThan)
                {
                    var valueDistance = (double)ConstantWithTypeVisitor.Visit(nodeIn.Right).Value !;

                    if (functionNode.Parameters.ElementAt(1) is not ConstantNode constantNode)
                    {
                        throw new NotSupportedException();
                    }

                    if (constantNode.Value is not GeographyPoint geographyPoint)
                    {
                        throw new NotSupportedException();
                    }

                    var property = PropertyPathVisitor.Visit(functionNode.Parameters.ElementAt(0));

                    return(ClrFilter.Lt(property, new FilterSphere(geographyPoint.Longitude, geographyPoint.Latitude, valueDistance)));
                }
                else
                {
                    var regexFilter = Visit(functionNode);

                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    if (value.ValueType == ClrValueType.Boolean && value.Value is bool booleanRight)
                    {
                        if ((nodeIn.OperatorKind == BinaryOperatorKind.Equal && !booleanRight) ||
                            (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual && booleanRight))
                        {
                            regexFilter = ClrFilter.Not(regexFilter);
                        }

                        return(regexFilter);
                    }
                }
            }
            else
            {
                if (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Ne(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.Equal)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Eq(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.LessThan)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Lt(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.LessThanOrEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Le(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThan)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Gt(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Ge(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }
            }

            throw new NotSupportedException();
        }
Beispiel #7
0
        public override FilterNode <ClrValue> Visit(BinaryOperatorNode nodeIn)
        {
            if (nodeIn.OperatorKind == BinaryOperatorKind.And)
            {
                return(ClrFilter.And(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this)));
            }

            if (nodeIn.OperatorKind == BinaryOperatorKind.Or)
            {
                return(ClrFilter.Or(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this)));
            }

            if (nodeIn.Left is SingleValueFunctionCallNode functionNode)
            {
                var regexFilter = Visit(functionNode);

                var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                if (value.ValueType == ClrValueType.Boolean && value.Value is bool booleanRight)
                {
                    if ((nodeIn.OperatorKind == BinaryOperatorKind.Equal && !booleanRight) ||
                        (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual && booleanRight))
                    {
                        regexFilter = ClrFilter.Not(regexFilter);
                    }

                    return(regexFilter);
                }
            }
            else
            {
                if (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Ne(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.Equal)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Eq(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.LessThan)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Lt(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.LessThanOrEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Le(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThan)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Gt(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }

                if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual)
                {
                    var value = ConstantWithTypeVisitor.Visit(nodeIn.Right);

                    return(ClrFilter.Ge(PropertyPathVisitor.Visit(nodeIn.Left), value));
                }
            }

            throw new NotSupportedException();
        }