public static void WriteDotFile(TextWriter w, List <TestTask> tasks, Dictionary <TestTask, TaskState> taskStates = null, IAttributeValueSelector colorSelector = null, IAttributeValueSelector shapeSelector = null) { colorSelector = colorSelector ?? new ByTaskStateSelector(TASK_STATE_COLORS); shapeSelector = shapeSelector ?? new ByQueueSelector(tasks, SHAPES, new Random(0)); w.WriteLine("digraph Tasks {"); var nodeAttributes = AttributeList( Attribute("style", "filled"), Attribute("fontname", "Segoe UI")); w.WriteLine($" node{nodeAttributes};"); foreach (var t in tasks) { var taskState = taskStates != null ? taskStates[t] : TaskState.Waiting; var color = colorSelector.SelectAttributeValue(t.QueueTag, t.Group, taskState); var shape = shapeSelector.SelectAttributeValue(t.QueueTag, t.Group, taskState); var attributes = AttributeList( Attribute("color", color), Attribute("fillcolor", color), Attribute("shape", shape)); w.WriteLine($" {t.Label}{attributes};"); } foreach (var t in tasks) { foreach (TestTask d in t.DependencyList) { w.WriteLine($" {d.Label} -> {t.Label};"); } } w.WriteLine("}"); }
public static void DisplayGraph(List <TestTask> tasks, Dictionary <TestTask, TaskState> taskStates = null, IAttributeValueSelector colorSelector = null, IAttributeValueSelector shapeSelector = null) { var tmpFile = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".png")); RenderGraph(tmpFile, tasks, taskStates, colorSelector, shapeSelector); if (!File.Exists(tmpFile)) { throw new FileNotFoundException("Generated PNG file not found", tmpFile); } Process.Start(tmpFile); }
public static void RenderGraph(string targetPngFile, List <TestTask> tasks, Dictionary <TestTask, TaskState> taskStates = null, IAttributeValueSelector colorSelector = null, IAttributeValueSelector shapeSelector = null) { var tmpDotFile = Path.GetTempFileName(); using (var w = new StreamWriter(tmpDotFile, false, Encoding.ASCII)) { WriteDotFile(w, tasks, taskStates, colorSelector, shapeSelector); } var p = Process.Start(new ProcessStartInfo("dot", $"-Tpng \"-o{targetPngFile}\" \"{tmpDotFile}\"") { CreateNoWindow = true, UseShellExecute = false }); p.WaitForExit(); File.Delete(tmpDotFile); }