private List <object> GetChildJfNode(BooleanOperatorNode boolNode) { var result = new List <object>(); if (boolNode.Left is BooleanOperatorNode && boolNode.Operator == ((BooleanOperatorNode)boolNode.Left).Operator) { result.AddRange(GetChildJfNode(boolNode.Left as BooleanOperatorNode)); } else if (boolNode.Left != null) { result.Add(boolNode.Left); } if (boolNode.Right is BooleanOperatorNode && boolNode.Operator == ((BooleanOperatorNode)boolNode.Right).Operator) { result.AddRange(GetChildJfNode(boolNode.Right as BooleanOperatorNode)); } else if (boolNode.Right != null) { result.Add(boolNode.Right); } return(result); }
private Node handleBooleanOperatorNode(ParserRuleContext ctx) { BooleanOperatorNode booleanOperatorNode = new BooleanOperatorNode(); iterateWithTryCatch(ctx, booleanOperatorNode); return(booleanOperatorNode); }
private void AddNode(BooleanOperators type) { if (SelectedFilterConfiguration == null || SelectedExpression == null) { return; } if (SelectedExpression is BooleanOperatorNode && ((BooleanOperatorNode)SelectedExpression).Operator == type) { return; } ExpressionTreeElement left; ExpressionTreeElement right; if (type == BooleanOperators.Not) { left = SelectedExpression.Clone() as ExpressionTreeElement; right = null; } else { left = null; right = SelectedExpression.Clone() as ExpressionTreeElement; } var newNode = new BooleanOperatorNode(SelectedExpression.Parent, left, right, type); var replaceResult = SelectedFilterConfiguration.Conditions.FindAndReplace(SelectedExpression, newNode); if (!replaceResult) { Trace.WriteLine("Cant replace SelectedExpression"); } if (SelectedFilterConfiguration.Conditions.Root != null) { SelectedFilterConfiguration.Conditions.Root = SelectedFilterConfiguration.Conditions.Root.Clone() as ExpressionTreeNode; } }
private void AddOperand() { if (SelectedFilterConfiguration == null || SelectedFilterableArgument == null) { return; } var fieldLeaf = new ExpressionTreeFieldLeaf(null, SelectedFilterableArgument.BoundProperty); object value; if (SelectedFilterableArgument.DefaultValue != null) { value = SelectedFilterableArgument.DefaultValue; } else if (fieldLeaf.Property.PropertyType == typeof(DateTime)) { value = DateTime.Now; } else if (fieldLeaf.Property.PropertyType == typeof(String)) { value = String.Empty; } else if (fieldLeaf.Property.PropertyType.IsAbstract) { value = null; } else { value = Activator.CreateInstance(fieldLeaf.Property.PropertyType); } var valueLeaf = new ExpressionTreeValueLeaf(null, value); var compariosonNode = new ComparisonOperatorNode(null, fieldLeaf, valueLeaf, SelectedFilterableArgument.AvailableOperators.FirstOrDefault()); //First node always add as comparision node if (SelectedFilterConfiguration.Conditions.Root == null) { SelectedFilterConfiguration.Conditions.Root = compariosonNode; } else { //Default add join node as AND operator if (SelectedExpression == null) { //If adding to root var rootBooleanNode = new BooleanOperatorNode(null, compariosonNode, SelectedFilterConfiguration.Conditions.Root, BooleanOperators.And); SelectedFilterConfiguration.Conditions.Root = rootBooleanNode; } else if (SelectedExpression is BooleanOperatorNode && ((BooleanOperatorNode)SelectedExpression).Operator != BooleanOperators.Not && SelectedExpression.Left == null) { //Adding to existing node SelectedExpression.Left = compariosonNode; SelectedFilterConfiguration.Conditions.Root = SelectedFilterConfiguration.Conditions.Root.Clone() as ExpressionTreeNode; } else if (SelectedExpression.Parent is BooleanOperatorNode && ((BooleanOperatorNode)SelectedExpression.Parent).Operator != BooleanOperators.Not && SelectedExpression.Parent.Left == null) { //Adding to existing node SelectedExpression.Parent.Left = compariosonNode; SelectedFilterConfiguration.Conditions.Root = SelectedFilterConfiguration.Conditions.Root.Clone() as ExpressionTreeNode; } else { //Adding to arbitrary node bool isParentNull = SelectedExpression.Parent == null; bool isSelectedBoolNode = SelectedExpression is BooleanOperatorNode; ExpressionTreeElement leftExpession; ExpressionTreeElement rightExpression; if (isSelectedBoolNode) { leftExpession = SelectedExpression.Right; } else if (isParentNull) { leftExpession = SelectedExpression; } else { leftExpession = SelectedExpression.Parent.Right; } if (leftExpession is BooleanOperatorNode) { rightExpression = leftExpession; leftExpession = compariosonNode; } else { rightExpression = compariosonNode; } var newBoolNode = new BooleanOperatorNode( SelectedExpression.Parent, leftExpession != null ? (leftExpession.Clone() as ExpressionTreeElement) : null, rightExpression.Clone() as ExpressionTreeElement, BooleanOperators.And); if (isParentNull && !isSelectedBoolNode) { SelectedFilterConfiguration.Conditions.Root = newBoolNode; } else { Trace.WriteLine("Before adding to SelectedExpression.Parent\r\n" + SelectedExpression.Parent); if (isSelectedBoolNode) { SelectedExpression.Right = newBoolNode; } else { SelectedExpression.Parent.Right = newBoolNode; } Trace.WriteLine("After adding to SelectedExpression.Parent\r\n" + SelectedExpression.Parent); SelectedFilterConfiguration.Conditions.Root = SelectedFilterConfiguration.Conditions.Root.Clone() as ExpressionTreeNode; } Trace.WriteLine("Final expression after adding\r\n" + SelectedFilterConfiguration.Conditions.Root); } } if (SelectedFilterConfiguration.Conditions.Root != null) { Task.Run(() => { Thread.Sleep(100); Application.Current.Dispatcher.Invoke(() => SelectedExpression = SelectedFilterConfiguration.Conditions.Root.Find(compariosonNode) as ExpressionTreeNode); }); } else { SelectedExpression = null; } }