private static string BuildGraphViz(VisualGraphGeneratedMessage graph) { var filename = Path.GetTempFileName() + ".dot"; using (var f = File.Open(filename, FileMode.OpenOrCreate)) { f.SetLength(0); using (var writer = new StreamWriter(f)) { writer.WriteLine("digraph d {"); writer.WriteLine("\trankdir = LR;"); if (graph.Connections == null) { MessageBox.Show("connections null"); } if (graph.Nodes == null) { MessageBox.Show("nodes null"); } foreach (var c in graph.Connections) { writer.WriteLine("\t\"" + c.To + "\" -> \"" + c.From + "\";"); } writer.WriteLine(); foreach (var n in graph.Nodes) { writer.WriteLine("\t\"" + n.FullName + "\"[label=\"" + n.DisplayName + "\", " + GetShape(n) + "];"); } writer.WriteLine("}"); } } return(filename); }
private static string Builddgml(VisualGraphGeneratedMessage graph) { var filename = Path.GetTempFileName() + ".dgml"; using (var f = File.Open(filename, FileMode.OpenOrCreate)) { f.SetLength(0); using (var writer = new StreamWriter(f)) { writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); writer.WriteLine("<DirectedGraph xmlns=\"http://schemas.microsoft.com/vs/2009/dgml\">"); writer.WriteLine("<Nodes>"); foreach (var n in graph.Nodes) { writer.WriteLine("<Node Id=\"" + SecurityElement.Escape(n.FullName) + "\" Group=\"" + GetGroup(n) + "\" Label=\"" + SecurityElement.Escape(n.DisplayName) + "\" />"); } writer.WriteLine("</Nodes>"); writer.WriteLine("<Links>"); foreach (var c in graph.Connections) { writer.WriteLine("<Link Source=\"" + SecurityElement.Escape(c.From) + "\" Target=\"" + SecurityElement.Escape(c.To) + "\" Category=\"links\"/>"); } writer.WriteLine("</Links>"); writer.WriteLine("</DirectedGraph>"); } } return(filename); }
private static void ConvertToGraphMessage(VisualGraphGeneratedMessage message, AffectedGraph graph) { foreach (var node in graph.AllNodes()) { message.Nodes.Add(new GraphNode { Assembly = node.Assembly, DisplayName = node.DisplayName, FullName = node.FullName, IsInterface = node.IsInterface, IsChange = node.IsChange, IsRootNode = node.IsRootNode, IsTest = node.IsTest, Name = node.Name, Type = node.Type, InTestAssembly = node.InTestAssembly, IsProfiledTest = node.Profiled, Complexity = node.Complexity, }); } foreach (var c in graph.AllConnections()) { message.Connections.Add(new Connection { From = c.From, To = c.To }); } }
private Node FindSearchedNode(VisualGraphGeneratedMessage graph) { foreach (var n in graph.Nodes) { if (n.IsRootNode) { return(_gViewer.Graph.FindNode(n.FullName)); } } return(null); }
public void GenerateAndShowGraphFor(VisualGraphGeneratedMessage message) { try { var filename = Builddgml(message); Open(filename); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public VisualGraphGeneratedMessage GetLastAffectedGraph() { var ret = new VisualGraphGeneratedMessage(); var graph = _minimizer.GetLastAffectedGraph(); if (graph == null) { return(ret); } Logger.WriteDebug("Getting last affected graph from the minimizer"); ConvertToGraphMessage(ret, graph); Logger.WriteDebug("Graph has " + graph.AllNodes().Count() + "nodes."); return(ret); }
public VisualGraphGeneratedMessage GetVisualizationGraphFor(string cacheName) { var ret = new VisualGraphGeneratedMessage(); if (minimizerGraphsAndRiskIsOff()) { return(ret); } Logger.WriteDebug("Generating graph from minimizer for '" + cacheName + "'"); var graph = _minimizer.GetGraphFor(cacheName, _configuration.AllSettings("mm-MinimizerDebug") == "true"); Logger.WriteDebug("graph generated with " + graph.AllNodes().Count() + " nodes " + graph.AllConnections().Count() + " connections."); EnrichGraphWithProfilerInformation(cacheName, graph); ConvertToGraphMessage(ret, graph); return(ret); }
public VisualGraphGeneratedMessage GetProfiledGraphFor(string cacheName) { var ret = new VisualGraphGeneratedMessage(); if (minimizerGraphsAndRiskIsOff()) { return(ret); } Logger.WriteDebug("Generating graph from profiler for '" + cacheName + "'"); var graph = _profilerData.GetProfiledGraphFor(cacheName); Logger.WriteDebug("graph generated with " + graph.AllNodes().Count() + " nodes " + graph.AllConnections().Count() + " connections."); _minimizer.EnrichGraph(graph); ConvertToGraphMessage(ret, graph); return(ret); }
public void Display(VisualGraphGeneratedMessage message) { Controls.Clear(); if (_gViewer != null) { Controls.Remove(_gViewer); } _gViewer = new GViewer { Dock = DockStyle.Fill, LayoutAlgorithmSettingsButtonVisible = false, NavigationVisible = false, ToolBarIsVisible = false, SaveButtonVisible = false, SaveGraphButtonVisible = false, AutoSizeMode = AutoSizeMode.GrowOnly, AutoScroll = false, }; _gViewer.HorizontalScroll.Enabled = false; _gViewer.VerticalScroll.Enabled = false; _gViewer.HorizontalScroll.Visible = false; _gViewer.VerticalScroll.Visible = false; _gViewer.DoubleClick += AGLVisualizer_DoubleClick; if (_mode == DisplayMode.Dark) { BackColor = System.Drawing.Color.Black; _gViewer.OutsideAreaBrush = new SolidBrush(System.Drawing.Color.Black); } else { BackColor = System.Drawing.Color.LightGray; _gViewer.OutsideAreaBrush = new SolidBrush(System.Drawing.Color.LightGray); } _gViewer.CurrentLayoutMethod = LayoutMethod.UseSettingsOfTheGraph; _gViewer.Graph = BuildGraphFrom(message); Controls.Add(_gViewer); selectNode(FindSearchedNode(message).Id); }
public void GenerateAndShowGraphFor(VisualGraphGeneratedMessage message) { if (_visualizer == null) { _visualizer = new AGLVisualizer(_mode, _dte, _transparent, _client); _visualizer.Closed += _visualizer_Closed; _visualizer.WindowState = FormWindowState.Maximized; } var parent = Control.FromHandle(new IntPtr(_dte.MainWindow.HWnd)); _visualizer.Parent = parent; _visualizer.Location = NativeWinPlacementAPI.GetPlacement(new IntPtr(_dte.MainWindow.HWnd)); _visualizer.StartPosition = FormStartPosition.CenterScreen; Logger.Write("Location is " + _visualizer.Location); var root = message.Nodes.First(x => x.IsRootNode); if (root != null) { _lastSignature = root.FullName; } _visualizer.Display(message); _visualizer.Visible = false; _visualizer.Show(); }
private Graph BuildGraphFrom(VisualGraphGeneratedMessage affectedGraph) { var graph = new Graph("graph") { Attr = { BackgroundColor = Color.Transparent } }; if (affectedGraph.Connections != null) { _gViewer.LayoutAlgorithmSettingsButtonVisible = true; _gViewer.ForeColor = System.Drawing.Color.FromArgb(1, 2, 3); foreach (var x in affectedGraph.Connections) { var edge = graph.AddEdge(x.From, x.To); if (_mode == DisplayMode.Dark) { edge.Attr.Color = Color.White; } } } graph.Attr.LayerDirection = LayerDirection.LR; if (affectedGraph.Nodes != null) { foreach (var y in affectedGraph.Nodes) { var n = graph.FindNode(y.FullName) ?? graph.AddNode(y.FullName); n.LabelText = y.DisplayName; n.Attr.Shape = Shape.Box; if (y.IsRootNode) { n.Attr.FillColor = Color.LightGreen; } else if (y.IsChange) { n.Attr.FillColor = Color.Maroon; } else if (y.IsTest && y.IsProfiledTest) { n.Attr.FillColor = Color.Yellow; } else if (y.IsTest) { n.Attr.FillColor = Color.DarkGoldenrod; } else if (y.IsInterface) { n.Attr.FillColor = Color.LightBlue; } //TODO GREG PUT ON FEATURE TOGGLE else if (false && y.Complexity > 15) { n.Attr.FillColor = Color.LightPink; } else { n.Attr.FillColor = Color.White; } } } return(graph); }