Ejemplo n.º 1
0
        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));
        }
        /// <summary>
        /// MessageReceived event to keep in track of every interaction among constituents in SoS
        /// </summary>
        /// <param name="from">A reference object to the sender of the message</param>
        /// <param name="target">A reference type to the receiver of the message</param>
        /// <param name="msgText"></param>
        /// <param name="info"></param>
        protected override void OnMessageReceived(object from, Type target, string msgText, params object[] info)
        {
            MessageUnit entry;

            entry = new MessageUnit();

            // Create MessageUnit using the received message
            entry.From      = from.GetType().Name.ToString();
            entry.To        = target.Name.ToString();
            entry.Message   = msgText.ToString();
            entry.Cycle     = this.Cycle;
            entry.Parameter = info;

            // Add current message to the simulation log
            _simLog.Add(entry);

            // update visual text
            if (OnTextUpdate != null)
            {
                // Format message as follows:
                // (SenderAgent->ReceiverAgent).MessageText
                OnTextUpdate(entry.ToString());
            }
        }
        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);
        }