public override VfpExpression Visit(VfpJoinExpression expression)
        {
            var result = base.Visit(expression);

            expression = result as VfpJoinExpression;

            if (expression == null)
            {
                return(result);
            }

            var filterExpression = expression.Left.Expression as VfpFilterExpression;

            if (IsZeroEqualsZero(filterExpression))
            {
                expression = VfpExpressionBuilder.Join(expression.ExpressionKind, expression.ResultType, filterExpression.Input, expression.Right, expression.JoinCondition);
            }

            filterExpression = expression.Right.Expression as VfpFilterExpression;

            if (IsZeroEqualsZero(filterExpression))
            {
                expression = VfpExpressionBuilder.Join(expression.ExpressionKind, expression.ResultType, expression.Left, filterExpression.Input, expression.JoinCondition);
            }

            return(expression);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var left   = VfpExpressionBuilder.Constant(0);
            var right  = VfpExpressionBuilder.Constant(0);
            var binary = left.And(right);
            var host   = new VisualizerDevelopmentHost(binary,
                                                       typeof(VfpExpressionTreeVisualizer),
                                                       typeof(VfpExpressionTreeVisualizerObjectSource));

            host.ShowVisualizer();
        }
Пример #3
0
        protected override VfpExpressionBinding VisitVfpExpressionBinding(VfpExpressionBinding binding)
        {
            binding = base.VisitVfpExpressionBinding(binding);

            if (!_xmlToCursors.ContainsKey(binding.VariableName))
            {
                return(binding);
            }

            var xmlToCursors = _xmlToCursors[binding.VariableName];

            if (!xmlToCursors.Any())
            {
                return(binding);
            }

            var scan = binding.Expression as VfpScanExpression;

            if (scan == null)
            {
                return(binding);
            }

            var           scanBinding = scan.BindAs(CursorNamePrefix + (_count++));
            VfpExpression predicate   = null;

            foreach (var xmlToCursor in xmlToCursors)
            {
                var scanProperty          = scanBinding.Variable.Property(xmlToCursor.ColumnProperty.Property);
                var xmlToCursorExpression = VfpExpressionBuilder.XmlToCursor(scanProperty, xmlToCursor.XmlToCursor.Parameter, CursorNamePrefix + xmlToCursor.XmlToCursor.CursorName, xmlToCursor.XmlToCursor.ItemType);

                _xmlToCursorsToBeRemoved.Add(xmlToCursor.XmlToCursor.CursorName);

                if (predicate == null)
                {
                    predicate = xmlToCursorExpression;
                }
                else
                {
                    predicate = predicate.And(xmlToCursorExpression);
                }
            }

            var filter        = scanBinding.Filter(predicate);
            var filterBinding = filter.BindAs(binding.Variable.VariableName);

            return(filterBinding);
        }
        public override VfpExpression Visit(VfpFilterExpression expression)
        {
            var result = base.Visit(expression);

            expression = result as VfpFilterExpression;

            if (expression == null)
            {
                return(result);
            }

            if (IsValidXmlToCursorExpression(expression.Predicate as VfpXmlToCursorExpression))
            {
                var predicate = VfpExpressionBuilder.Constant(0).ExpressionEquals(VfpExpressionBuilder.Constant(0));

                return(new VfpFilterExpression(expression.ResultType, expression.Input, predicate));
            }

            return(result);
        }
Пример #5
0
        public override VfpExpression Visit(VfpLikeExpression expression)
        {
            // Check the argument expression to see if it contains a property expression.
            // Don't need to rewrite the expression if the left side already contains a property expression.
            if (PropertyGatherer.Gather(expression.Argument).Any())
            {
                return(expression);
            }

            // Check the pattern expression to see if it has a property expression.
            if (!PropertyGatherer.Gather(expression.Pattern).Any())
            {
                return(expression);
            }

            return(VfpExpressionBuilder.Like(expression.ResultType,
                                             expression.Pattern,
                                             expression.Argument,
                                             expression.Escape));
        }
        public override VfpExpression Visit(VfpInExpression expression)
        {
            const int convertToXmltocursorMintextLength = 200;

            if (expression.List.Any(x => x.ExpressionKind != VfpExpressionKind.Constant))
            {
                return(base.Visit(expression));
            }

            var values = new StringBuilder(convertToXmltocursorMintextLength);
            var array  = expression.List.Cast <VfpConstantExpression>().Select(x => x.Value).Distinct().ToArray();

            foreach (var item in array)
            {
                values.Append(item);

                if (values.Length > convertToXmltocursorMintextLength)
                {
                    break;
                }
            }

            if (values.Length > convertToXmltocursorMintextLength)
            {
                _count++;

                var arrayXmlToCursor = new ArrayXmlToCursor(array);
                var xml         = VfpExpressionBuilder.Constant(arrayXmlToCursor.Xml);
                var parameter   = VfpExpressionBuilder.Parameter(PrimitiveTypeKind.String.ToTypeUsage(), "@__XmlToCursor" + _count, xml);
                var cursorName  = "curXml" + _count;
                var xmlToCursor = VfpExpressionBuilder.XmlToCursor(expression.Item, parameter, cursorName, arrayXmlToCursor.ItemType);

                return(base.Visit(xmlToCursor));
            }

            return(base.Visit(expression));
        }
        public void CreateDefaultPrimitiveTypeKindTest()
        {
            var primitiveTypeKinds = Enum.GetValues(typeof(PrimitiveTypeKind))
                                     .Cast <PrimitiveTypeKind>()
                                     .Where(x => x != PrimitiveTypeKind.Time)
                                     .Where(x => x != PrimitiveTypeKind.DateTimeOffset)
                                     .Where(x => x.ToString().StartsWith("Geometry"))
                                     .Where(x => x.ToString().StartsWith("Geography"));

            foreach (var primitiveTypeKind in primitiveTypeKinds)
            {
                Console.WriteLine(primitiveTypeKind.ToString());

                var type       = primitiveTypeKind.ToClrType();
                var value      = GetPrimitiveTypeKindDefaultValue(primitiveTypeKind);
                var text       = GetPrimitiveTypeKindDefaultText(primitiveTypeKind);
                var expression = VfpExpressionBuilder.Constant(value, type);

                Assert.AreEqual(primitiveTypeKind, expression.ConstantKind);
                Assert.AreEqual(value, expression.Value);
                Assert.AreEqual(VfpExpressionKind.Constant, expression.ExpressionKind);
                Assert.AreEqual("Edm." + primitiveTypeKind, expression.ResultType.ToString());
            }
        }
Пример #8
0
        protected override VfpExpressionBinding VisitVfpExpressionBinding(VfpExpressionBinding binding)
        {
            var isFilterBinding = binding.Expression is VfpFilterExpression;

            if (isFilterBinding)
            {
                _filterBindings.Push(binding);
            }

            binding = base.VisitVfpExpressionBinding(binding);

            if (isFilterBinding)
            {
                var expression = binding.Expression;

                foreach (var cursorName in _xmlToCursorsToBeRemoved)
                {
                    expression = XmlToCursorExpressionRemover.Remove(expression, cursorName);
                }

                _xmlToCursorsToBeRemoved.Clear();
                _filterBindings.Pop();

                binding = expression.BindAs(binding.Variable.VariableName);
            }

            if (!_filterBindings.Any())
            {
                return(binding);
            }

            var filterBinding = _filterBindings.Peek();

            if (filterBinding == null)
            {
                return(binding);
            }

            var scan = binding.Expression as VfpScanExpression;

            if (scan == null)
            {
                return(binding);
            }

            if (!_xmlToCursors.ContainsKey(binding.VariableName))
            {
                return(binding);
            }

            var xmlToCursors = _xmlToCursors[binding.VariableName];

            if (!xmlToCursors.Any())
            {
                return(binding);
            }

            foreach (var xmlToCursor in xmlToCursors)
            {
                var xmlToCursorExpression = xmlToCursor.XmlToCursor;

                _count++;

                var variableReference   = xmlToCursorExpression.ItemType.ToTypeUsage().Variable("Xml" + _count);
                var xmlToCursorScan     = VfpExpressionBuilder.XmlToCursorScan(xmlToCursorExpression.Parameter, xmlToCursorExpression.CursorName + "_j");
                var xmlToCursorBinding  = xmlToCursorScan.BindAs(variableReference.VariableName);
                var xmlToCursorProperty = VfpExpressionBuilder.XmlToCursorProperty(variableReference.ResultType, variableReference);
                var scanProperty        = GetScanProperty(binding.Variable, xmlToCursorExpression.Property);
                var comparison          = scanProperty.ExpressionEquals(xmlToCursorProperty);

                var joinVariableReference = binding.VariableType.Variable(binding.VariableName);
                var joinExpression        = binding.InnerJoin(xmlToCursorBinding, comparison, binding.Expression.ResultType);

                _xmlToCursorsToBeRemoved.Add(xmlToCursorExpression.CursorName);

                binding = joinExpression.BindAs(joinVariableReference.VariableName);
            }

            return(binding);
        }
        private static VfpJoinExpression CreateJoin(VfpExpressionBinding left, VfpExpressionBinding right) {
            var comparison = VfpExpressionBuilder.Constant(1).ExpressionEquals(VfpExpressionBuilder.Constant(1));

            return left.LeftJoin(right, comparison, right.VariableType);
        }