private bool TraverseChildNodesInternal(TaskNode taskNode, ref TaskNodeTraversalCallback nodeAction)
        {
            bool bContinueTraversing;

            bContinueTraversing = true;

            // If goal model, callback
            if (taskNode.Type == NODE_TYPE.GOAL)
            {
                bContinueTraversing = nodeAction(taskNode);

                if (bContinueTraversing)
                {
                    // traverse children
                    if (taskNode.HasChildNodes)
                    {
                        foreach (TaskNode node in taskNode.ChildNodes)
                        {
                            bContinueTraversing = TraverseChildNodesInternal(node, ref nodeAction);

                            if (!bContinueTraversing)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        throw new ApplicationException("Task model definition error. Goal node must have children.");
                    }
                }
            }

            return(bContinueTraversing);
        }
        public TestOracle(TaskNode goalTaskNode, MessageUnitList messages)
        {
            // define task operator only one time
            if (mapOperator == null)
            {
                MapTaskOperators();
            }

            // Must be a goal node & has child nodes
            if (goalTaskNode.Type == NODE_TYPE.GOAL &&
                    goalTaskNode.HasChildNodes)
            {
                // initialize
                _goalTaskNode = goalTaskNode;
                //_taskNodeList = goalTaskNode.ChildNodes;
                _messages = messages;

                // Add all task nodes
                this.Clear();

                foreach (TaskNode tNode in goalTaskNode.ChildNodes)
                {
                    this.Add(tNode);
                }
            }
            else
            {
                throw new ApplicationException("Test oracle must take a goal type task node which contains child nodes.");
            }
        }
        public void TraverseTaskNodes(ref TaskNodeTraversalCallback cbNodeAction)
        {
            TaskNode tNode;

            tNode = new TaskNode(RootNodes[0]);

            tNode.TraverseChildNodes(ref cbNodeAction);
        }
        public void TraverseTaskNodes(ref TaskNodeTraversalCallback cbNodeAction)
        {
            TaskNode tNode;

            tNode = new TaskNode(RootNodes[0]);

            tNode.TraverseChildNodes(ref cbNodeAction);
        }
        public void TraverseChildNodes(ref TaskNodeTraversalCallback nodeAction)
        {
            XmlNodeList nodes;
            TaskNode    taskNode;

            nodes = _xmlNode.ChildNodes;

            foreach (XmlNode node in nodes)
            {
                // Convert to TaskNode
                taskNode = new TaskNode(node);

                if (!TraverseChildNodesInternal(taskNode, ref nodeAction))
                {
                    break;
                }
            }
        }
        public MessageUnit GetMessageUnitFromTask(TaskNode taskNode)
        {
            MessageUnit msgUnit;

            msgUnit = new MessageUnit();
            msgUnit.Message = taskNode.Name;
            msgUnit.Occurrence = taskNode.RecursionCount;

            // Only task node has interaction property
            if (taskNode.Type == NODE_TYPE.TASK)
            {
                _roleModel.GetRoleFromMessage(msgUnit.Message, ref msgUnit.From, ref msgUnit.To);

                msgUnit.From = _agentModel.GetAgentFromRole(msgUnit.From);
                msgUnit.To = _agentModel.GetAgentFromRole(msgUnit.To);
            }

            return msgUnit;
        }
        public void TraverseChildNodes(ref TaskNodeTraversalCallback nodeAction)
        {
            XmlNodeList nodes;
            TaskNode taskNode;

            nodes = _xmlNode.ChildNodes;

            foreach (XmlNode node in nodes)
            {
                // Convert to TaskNode
                taskNode = new TaskNode(node);

                if (!TraverseChildNodesInternal(taskNode, ref nodeAction))
                {
                    break;
                }
            }
        }
        private bool TraverseChildNodesInternal(TaskNode taskNode, ref TaskNodeTraversalCallback nodeAction)
        {
            bool bContinueTraversing;

            bContinueTraversing = true;

            // If goal model, callback
            if (taskNode.Type == NODE_TYPE.GOAL)
            {
                bContinueTraversing = nodeAction(taskNode);

                if (bContinueTraversing)
                {
                    // traverse children
                    if (taskNode.HasChildNodes)
                    {
                        foreach (TaskNode node in taskNode.ChildNodes)
                        {
                            bContinueTraversing = TraverseChildNodesInternal(node, ref nodeAction);

                            if (!bContinueTraversing)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        throw new ApplicationException("Task model definition error. Goal node must have children.");
                    }
                }
            }

            return bContinueTraversing;
        }
        private TestOracle GenerateTestOracleByGoal(TaskNode goalNode)
        {
            TaskNodeTraversalCallback nodeAction;
            TaskNode goalTaskNode;
            MessageUnitList messagesList;

            goalTaskNode = null;
            messagesList = new MessageUnitList();

            // Define lambda callback
            nodeAction = new TaskNodeTraversalCallback((taskNode) =>
            {
                // Found the target goal
                if (taskNode.IsSameContent(goalNode))
                {
                    if (taskNode.HasChildNodes)
                    {
                        goalTaskNode = taskNode;

                        foreach (TaskNode node in taskNode.ChildNodes)
                        {
                            messagesList.Add(_tAgentMapper.GetMessageUnitFromTask(node));
                        }
                    }

                    // Terminate node traversing
                    return false;
                }

                // Continue traversing
                return true;
            });

            _tModel.TraverseTaskNodes(ref nodeAction);

            // if error
            if (goalTaskNode == null)
            {
                throw new ApplicationException("Task node list cannot be null.");
            }

            return new TestOracle(goalTaskNode, messagesList);
        }