Пример #1
0
        /// <summary>
        ///   The equals.
        /// </summary>
        /// <param name="other"> The other. </param>
        /// <returns> The System.Boolean. </returns>
        public bool Equals(TaskNode other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(other.Depth == this.Depth && other.Index == this.Index && Equals(other.Parent, this.Parent) &&
                   ReferenceEquals(other.Task, this.Task));
        }
Пример #2
0
        /// <summary>
        ///   The equals.
        /// </summary>
        /// <param name="other"> The other. </param>
        /// <returns> The System.Boolean. </returns>
        public bool Equals(TaskNode other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }

            if (ReferenceEquals(this, other))
            {
                return true;
            }

            return other.Depth == this.Depth && other.Index == this.Index && Equals(other.Parent, this.Parent)
                   && ReferenceEquals(other.Task, this.Task);
        }
        /// <summary>
        ///   Solves all sub tree reference tasks and replaces them by real references to the sub tree.
        /// </summary>
        /// <param name="tree"> Tree in which to solve references. </param>
        /// <returns> Task to use instead of the passed one. </returns>
        private ITask SolveReferences(ITask tree)
        {
            if (tree == null)
            {
                return tree;
            }

            // Check if root is reference.
            if (tree is SubTreeReference)
            {
                SubTreeReference subTreeReference = tree as SubTreeReference;

                // Resolve reference.
                ITask treeReference = this.SolveReference(subTreeReference);

                return treeReference;
            }

            // Find sub tree reference tasks in tree.
            ICollection<TaskNode> referenceNodes = new List<TaskNode>();
            TaskNode rootNode = new TaskNode { Task = tree };
            tree.FindTasks(rootNode, task => task is SubTreeReference, ref referenceNodes);

            // Replace tasks in found nodes by referenced tree.
            foreach (TaskNode referenceNode in referenceNodes)
            {
                SubTreeReference subTreeReference = referenceNode.Task as SubTreeReference;
                if (subTreeReference == null)
                {
                    throw new Exception(
                        "Searched for SubTreeReference nodes, but found a task which is no sub tree reference node.");
                }

                IComposite parentComposite = referenceNode.ParentTask as IComposite;
                if (parentComposite == null)
                {
                    throw new Exception("Found task which has no parent composite.");
                }

                // Resolve reference.
                ITask treeReference = this.SolveReference(subTreeReference);

                // Remove from parent.
                parentComposite.RemoveChild(referenceNode.Task);

                // Add tree reference to parent at same position.
                parentComposite.InsertChild(referenceNode.Index, treeReference);
            }

            return tree;
        }
Пример #4
0
        /// <summary>
        ///   Generates a collection of active task nodes under this task. Used for debugging only.
        /// </summary>
        /// <param name="agentData"> Agent data. </param>
        /// <returns> Collection of active task nodes. </returns>
        public ICollection<TaskNode> GetActiveTasks(IAgentData agentData)
        {
            if (this.root == null || agentData.ExecutionStatus != ExecutionStatus.Running)
            {
                return null;
            }

            agentData.CurrentDeciderLevel = 0;

            TaskNode taskNode = new TaskNode { Task = this.root };
            ICollection<TaskNode> activeTasks = new List<TaskNode> { taskNode };
            this.root.GetActiveTasks(agentData, taskNode, ref activeTasks);
            return activeTasks;
        }
Пример #5
0
        /// <summary>
        ///   Searches for tasks which forfill the passed predicate.
        /// </summary>
        /// <param name="taskNode"> Task node of this task. </param>
        /// <param name="predicate"> Predicate to forfill. </param>
        /// <param name="tasks"> List of tasks which forfill the passed predicate. </param>
        public override void FindTasks(TaskNode taskNode, Func<ITask, bool> predicate, ref ICollection<TaskNode> tasks)
        {
            if (this.Task == null)
            {
                return;
            }

            // Check child.
            TaskNode childTaskNode = taskNode.CreateChildNode(this.Task, 0);
            if (predicate(this.Task))
            {
                tasks.Add(childTaskNode);
            }

            // Find tasks in child.
            this.Task.FindTasks(childTaskNode, predicate, ref tasks);
        }