Exemple #1
0
        private bool CheckBranchRulesValid(RuleModel ruleRoot, RuleTreeNode checkedRulesRoot, CheckLoanValid message)
        {
            //depth tree scan using stack
            bool isBranchValid = true;
            Stack <RuleModel>    rulesTreeStack        = new Stack <RuleModel>();
            Stack <RuleTreeNode> checkedRulesTreeStack = new Stack <RuleTreeNode>();

            rulesTreeStack.Push(ruleRoot);
            checkedRulesTreeStack.Push(checkedRulesRoot);
            while (!(rulesTreeStack.Count == 0))
            {
                var currentRuleToCheck         = rulesTreeStack.Pop();
                var currentCheckedRuleToUpdate = checkedRulesTreeStack.Pop();

                for (int j = 0; j < currentRuleToCheck.ChildrenRules.Count; j++)//create stack of branch nodes
                {
                    rulesTreeStack.Push(currentRuleToCheck.ChildrenRules[j]);
                    checkedRulesTreeStack.Push(currentCheckedRuleToUpdate.ChildrenRules[j]);
                }
                var  loanValueToCompare = message.LoanDetails.GetType().GetProperty(currentRuleToCheck.Parameter).GetValue(message.LoanDetails, null);
                bool isRuleValid        = CheckRuleValid(loanValueToCompare, currentRuleToCheck, message.IgnoreRules);
                isBranchValid = isRuleValid ? isBranchValid : false;
                UpdateCheckedRulesTree(loanValueToCompare, currentCheckedRuleToUpdate, currentRuleToCheck, isRuleValid);

                if (currentRuleToCheck.ChildrenRules.Count == 0)//at end of branch
                {
                    if (isBranchValid)
                    {
                        return(true);
                    }
                    isBranchValid = true;
                }
            }
            return(false);
        }
Exemple #2
0
        private static void PrintTree(RuleTreeNode tree)
        {
            List <RuleTreeNode> firstStack = new List <RuleTreeNode>();

            firstStack.Add(tree);

            List <List <RuleTreeNode> > childListStack = new List <List <RuleTreeNode> >();

            childListStack.Add(firstStack);

            while (childListStack.Count > 0)
            {
                List <RuleTreeNode> childStack = childListStack[childListStack.Count - 1];

                if (childStack.Count == 0)
                {
                    childListStack.RemoveAt(childListStack.Count - 1);
                }
                else
                {
                    tree = childStack[0];
                    childStack.RemoveAt(0);

                    string indent = "";
                    for (int i = 0; i < childListStack.Count - 1; i++)
                    {
                        indent += (childListStack[i].Count > 0) ? "|  " : "   ";
                    }

                    if (tree.IsRuleValid)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine(indent + "+- " + tree.RuleDescription);
                    }
                    else if (!tree.IsRuleValid)
                    {
                        if (tree.RuleDescription == null)
                        {
                            Console.ForegroundColor = ConsoleColor.Gray;
                            Console.WriteLine(indent + "+- " + tree.RuleId);
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine(indent + "+- " + tree.RuleDescription);
                        }
                    }
                    if (tree.ChildrenRules.Count > 0)
                    {
                        childListStack.Add(new List <RuleTreeNode>(tree.ChildrenRules));
                    }
                }
            }
        }
Exemple #3
0
 private void UpdateCheckedRulesTree(object loanValueToCompare, RuleTreeNode ruleTreeNodeStackItem, RuleModel ruleTreeStackItem, bool isRuleValid)
 {
     ruleTreeNodeStackItem.IsRuleValid     = isRuleValid;
     ruleTreeNodeStackItem.RuleDescription = isRuleValid? GetValidRuleDescription(loanValueToCompare, ruleTreeStackItem):
                                             GetInvalidRuleDescription(loanValueToCompare, ruleTreeStackItem);
 }
        /// <summary>
        ///     Accepts a drop event
        /// </summary>
        /// <param name="sourceNode"></param>
        public override void AcceptDrop(BaseTreeNode sourceNode)
        {
            {
                if (sourceNode is ShortcutTreeNode)
                {
                    ShortcutTreeNode shortcut = sourceNode as ShortcutTreeNode;

                    if (shortcut.Item.Dictionary == Item.Dictionary)
                    {
                        Shortcut otherShortcut = (Shortcut)shortcut.Item.Duplicate();
                        Item.appendShortcuts(otherShortcut);

                        shortcut.Delete();
                    }
                }
                else if (sourceNode is ShortcutFolderTreeNode)
                {
                    ShortcutFolderTreeNode folder = sourceNode as ShortcutFolderTreeNode;

                    if (folder.Item.Dictionary == Item.Dictionary)
                    {
                        ShortcutFolder otherFolder = (ShortcutFolder)folder.Item.Duplicate();
                        Item.appendFolders(otherFolder);

                        folder.Delete();
                    }
                }
                else if (sourceNode is RuleTreeNode)
                {
                    RuleTreeNode rule = sourceNode as RuleTreeNode;

                    if (rule.Item.Dictionary == Item.Dictionary)
                    {
                        Shortcut shortcut = (Shortcut)acceptor.getFactory().createShortcut();
                        shortcut.CopyFrom(rule.Item);
                        Item.appendShortcuts(shortcut);
                    }
                }
                else if (sourceNode is FunctionTreeNode)
                {
                    FunctionTreeNode function = sourceNode as FunctionTreeNode;

                    if (function.Item.Dictionary == Item.Dictionary)
                    {
                        Shortcut shortcut = (Shortcut)acceptor.getFactory().createShortcut();
                        shortcut.CopyFrom(function.Item);
                        Item.appendShortcuts(shortcut);
                    }
                }
                else if (sourceNode is ProcedureTreeNode)
                {
                    ProcedureTreeNode procedure = sourceNode as ProcedureTreeNode;

                    if (procedure.Item.Dictionary == Item.Dictionary)
                    {
                        Shortcut shortcut = (Shortcut)acceptor.getFactory().createShortcut();
                        shortcut.CopyFrom(procedure.Item);
                        Item.appendShortcuts(shortcut);
                    }
                }
                else if (sourceNode is VariableTreeNode)
                {
                    VariableTreeNode variable = sourceNode as VariableTreeNode;

                    if (variable.Item.Dictionary == Item.Dictionary)
                    {
                        Shortcut shortcut = (Shortcut)acceptor.getFactory().createShortcut();
                        shortcut.CopyFrom(variable.Item);
                        Item.appendShortcuts(shortcut);
                    }
                }
            }
        }