Ejemplo n.º 1
0
        private IReadOnlyList <Node> GetTaskGraphNodes(ICakeContext context, ICakeTaskInfo task, IReadOnlyList <ICakeTaskInfo> tasks)
        {
            var taskDictionary = tasks.ToDictionary();

            var nodes = new List <Node>();

            var stack = new Stack <ICakeTaskInfo>();

            stack.Push(task);
            while (stack.Count > 0)
            {
                var currentNode = stack.Pop();
                context.Log.Write(Verbosity.Diagnostic, LogLevel.Debug, $"Creating Node for {currentNode.Name} which has {currentNode.Dependencies.Count} dependencies");
                nodes.Add(new Node(currentNode.Name));

                foreach (var dependencyName in currentNode.Dependencies)
                {
                    var dependencyTask = TaskGraphGeneratorHelpers.GetTaskDependency(context, taskDictionary, dependencyName.Name);
                    stack.Push(dependencyTask);
                    context.Log.Write(Verbosity.Diagnostic, LogLevel.Debug, $"Creating Edge from {currentNode.Name} to {dependencyTask.Name}");
                    nodes.Add(new Node(Guid.NewGuid().ToString(), currentNode.Name, dependencyTask.Name));
                }
            }

            return(nodes);
        }
        /// <summary>
        /// Convert the task and dependencies to mermaid syntax string
        /// </summary>
        /// <param name="context"></param>
        /// <param name="task"></param>
        /// <param name="tasks"></param>
        /// <returns></returns>
        public async Task <string> SerializeAsync(ICakeContext context, ICakeTaskInfo task, IReadOnlyList <ICakeTaskInfo> tasks)
        {
            TaskGraphGeneratorHelpers.ValidateParameters(context, task, tasks);

            var edges = GetEdges(context, task, tasks);

            return(ConvertToString(task, edges));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the task to a graph and outputs the string for displaying
        /// </summary>
        /// <param name="context"></param>
        /// <param name="task"></param>
        /// <param name="tasks"></param>
        /// <returns></returns>
        public Task <string> SerializeAsync(ICakeContext context, ICakeTaskInfo task, IReadOnlyList <ICakeTaskInfo> tasks)
        {
            TaskGraphGeneratorHelpers.ValidateParameters(context, task, tasks);

            var nodes = GetTaskGraphNodes(context, task, tasks);

            return(Task.FromResult(JsonConvert.SerializeObject(nodes)));
        }
        private static IReadOnlyCollection <string> GetEdges(ICakeContext context, ICakeTaskInfo task, IReadOnlyList <ICakeTaskInfo> tasks)
        {
            var taskDictionary = tasks.ToDictionary();

            var stack = new Stack <ICakeTaskInfo>();

            stack.Push(task);
            var edges   = new List <string>();
            var visited = new HashSet <string>();

            while (stack.Count > 0)
            {
                var currentNode = stack.Pop();
                context.Log.Write(Verbosity.Diagnostic, LogLevel.Debug,
                                  $"Creating Node for {currentNode.Name} which has {currentNode.Dependencies.Count} dependencies");

                foreach (var dependencyName in currentNode.Dependencies)
                {
                    var dependencyTask = TaskGraphGeneratorHelpers.GetTaskDependency(context, taskDictionary, dependencyName.Name);

                    if (visited.Contains(dependencyTask.Name, StringComparer.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    visited.Add(dependencyTask.Name);
                    stack.Push(dependencyTask);

                    context.Log.Write(Verbosity.Diagnostic, LogLevel.Debug,
                                      $"Creating Edge from {currentNode.Name} to {dependencyTask.Name}");
                    var edge = $"{currentNode.Name}-->{dependencyTask.Name};";
                    edges.Add(edge);
                }
            }

            return(edges);
        }