private void RemoveUngroupedRecursive(ExpressionNode parent) { if(parent == null) { return; } if(parent.Left == null && parent.Right == null) { return; } if(parent.Left != null && parent.Right != null) { RemoveUngroupedRecursive(parent.Left); RemoveUngroupedRecursive(parent.Right); } else { parent.Left = parent.Right = null; } }
private bool EvaluateTreeRecursive(ExpressionNode node, string file) { if(node == null) { return true; } if(node.Type == ExpressionType.Filter) { return ((FilterNode)node).Filter.Allow(file); } else { if(node.Left == null || node.Right == null) { // invalid tree Debug.ReportWarning("Invalid expression tree"); return true; } else { bool resultA = EvaluateTreeRecursive(node.Left, file); bool resultB = EvaluateTreeRecursive(node.Right, file); if(((ImplicationNode)node).Implication == FilterImplication.AND) { return (resultA && resultB); } else { return (resultA || resultB); } } } }
public void RemoveUngrouped(ExpressionNode parent) { // check the parameters Debug.Assert(parent != null, "Parent is null"); RemoveUngroupedRecursive(parent); }
private List<ExpressionNode> GetNodesRecursive(ExpressionNode node, ExpressionType type) { List<ExpressionNode> list = new List<ExpressionNode>(); if(node == null) { return list; } // add the node to the category if it represents a Filter if(node.Type == ExpressionType.Filter) { list.Add(node); } // add the filters from the children if(node.Left != null) { list.AddRange(GetNodesRecursive(node.Left, type)); } if(node.Right != null) { list.AddRange(GetNodesRecursive(node.Right, type)); } return list; }
public void RemoveChildren(ExpressionNode parent, TreeDirection direction) { // check the parameters Debug.Assert(parent != null, "Parent is null"); if(direction == TreeDirection.Left) { parent.Left = null; } else { parent.Right = null; } }
public void RemoveChildren(ExpressionNode parent) { // check the parameters Debug.Assert(parent != null, "Parent is null"); parent.Left = null; parent.Right = null; }
/// <summary> /// Method executed after deserialization in order to establish the parent-child relationship /// </summary> public void EstablishParentChildRelationship(ExpressionNode parent) { if(parent == null) { return; } if(parent.Left != null) { parent.Left.Parent = parent; EstablishParentChildRelationship(parent.Left); } if(parent.Right != null) { parent.Right.Parent = parent; EstablishParentChildRelationship(parent.Right); } }
/// <summary> /// Method executed before serialization in order to destory the parent-child relationship /// </summary> public void DestroyParentChildRelationship(ExpressionNode parent) { if(parent == null) { return; } // remove link parent.Parent = null; // remove link for children if(parent.Left != null) { DestroyParentChildRelationship(parent.Left); } if(parent.Right != null) { DestroyParentChildRelationship(parent.Right); } }
/// <summary> /// Adds the root node of the tree. /// </summary> /// <param name="type">The node type.</param> /// <param name="item">The item to add to the node.</param> public void AddRoot(ExpressionType type, object item) { // check the parameters Debug.Assert(item != null, "Item is null"); _root = NewNodeByType(type, item); }
/// <summary> /// Adds the node. /// </summary> /// <param name="parent">The parent.</param> /// <param name="direction">The direction.</param> /// <param name="type">The type.</param> /// <param name="item">The item.</param> public void AddNode(ExpressionNode parent, TreeDirection direction, ExpressionType type, object item) { // check the parameters Debug.Assert(parent != null && item != null, "Parent or Item are null"); if(direction == TreeDirection.Left) { parent.Left = NewNodeByType(type, item); parent.Left.Parent = parent; } else { parent.Right = NewNodeByType(type, item); parent.Right.Parent = parent; } }
/// <summary> /// Converts the tree to string representation. /// </summary> /// <param name="node">The base node.</param> /// <returns></returns> private string TreeToString(ExpressionNode node) { if(node == null) { return string.Empty; } StringBuilder builder = new StringBuilder(); if(node.Left != null) { if(node.Left.Type == ExpressionType.Implication) { builder.Append(ExpressionStartChar); } builder.Append(TreeToString(node.Left)); if(node.Left.Type == ExpressionType.Implication) { builder.Append(ExpressionEndChar); } } if(node.Type == ExpressionType.Implication) { builder.Append(" "); ImplicationNode implication = (ImplicationNode)node; if(implication.Implication == FilterImplication.AND) { builder.Append(AndImplication); } else if(implication.Implication == FilterImplication.OR) { builder.Append(OrImplication); } builder.Append(" "); } else { FilterNode filter = (FilterNode)node; if(filter.Filter.Name != null) { builder.Append(filter.Filter.Name); } } if(node.Right != null) { if(node.Right.Type == ExpressionType.Implication) { builder.Append(ExpressionStartChar); } builder.Append(TreeToString(node.Right)); if(node.Right.Type == ExpressionType.Implication) { builder.Append(ExpressionEndChar); } } return builder.ToString(); }