示例#1
0
        /// <summary>
        /// Breadth first traversal
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private List <string> BreadthFirstTraversal(JobNode node)
        {
            var result = new List <string>();

            if (node.JobId != ROOT_JOB_IDENTIFIER)
            {
                result.Add(node.JobId);
            }

            if (node.DependantJobs != null)
            {
                foreach (var childJob in node.DependantJobs)
                {
                    result.AddRange(BreadthFirstTraversal(childJob));
                }
            }



            return(result);
        }
示例#2
0
        /// <summary>
        /// Find a job in the tree
        /// </summary>
        /// <param name="node">node to start from</param>
        /// <param name="jobId">job id</param>
        /// <returns></returns>
        private JobNode Find(JobNode node, string jobId)
        {
            if (node.JobId == jobId)
            {
                return(node);
            }

            if (node.DependantJobs != null)
            {
                foreach (var child in node.DependantJobs)
                {
                    var findResult = Find(child, jobId);
                    if (findResult != null)
                    {
                        return(findResult);
                    }
                }
            }

            return(null);
        }
示例#3
0
        /// <summary>
        /// Find parent of a given job id on node and its children
        /// </summary>
        /// <param name="node"></param>
        /// <param name="jobId"></param>
        /// <returns></returns>
        private JobNode FindParent(JobNode node, string jobId)
        {
            if (node.DependantJobs == null)
            {
                return(null);
            }
            foreach (var child in node.DependantJobs)
            {
                if (child.JobId == jobId)
                {
                    return(node);
                }
                else
                {
                    var findNextLevel = FindParent(child, jobId);
                    if (findNextLevel != null)
                    {
                        return(findNextLevel);
                    }
                }
            }

            return(null);
        }
示例#4
0
 /// <summary>
 /// Creates an instance of Job tree
 /// </summary>
 public JobTree()
 {
     Root = new JobNode(ROOT_JOB_IDENTIFIER);
 }
示例#5
0
        /// <summary>
        /// Remove from existing node to add a parent to the node
        /// </summary>
        /// <param name="jobId"></param>
        /// <param name="alreadyPresent"></param>
        private void DettatchFromParent(string jobId, JobNode alreadyPresent)
        {
            var parent = FindParent(Root, jobId);

            parent.DependantJobs.Remove(alreadyPresent);
        }