Skip to content

Commit 13d3cff

Browse files
committed
Allow opening graph files in .dot format
1 parent f9a936b commit 13d3cff

File tree

8 files changed

+83
-19
lines changed

8 files changed

+83
-19
lines changed

src/StructuredLogViewer/Controls/BuildControl.xaml.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ on the node will navigate to the corresponding source code associated with the n
389389

390390
preprocessedFileManager = new PreprocessedFileManager(this.Build, sourceFileResolver);
391391
preprocessedFileManager.DisplayFile += filePath => DisplayFile(filePath);
392-
Build.TargetGraphManager.TextProvider = evaluation => preprocessedFileManager.GetPreprocessedText(evaluation);
392+
Build.TextProvider = evaluation => preprocessedFileManager.GetPreprocessedText(evaluation);
393393

394394
navigationHelper = new NavigationHelper(Build, sourceFileResolver);
395395
navigationHelper.OpenFileRequested += filePath => DisplayFile(filePath);
@@ -510,19 +510,12 @@ private void CentralTabControl_SelectionChanged(object sender, SelectionChangedE
510510

511511
private void PopulateProjectReferenceGraph()
512512
{
513-
#if false
514-
var graph = Digraph.Load(@"C:\temp\graph\graph.dot");
515-
graph.CalculateHeight();
516-
graph.CalculateDepth();
517-
graph.ComputeTransitiveReduction();
518-
#else
519513
var graph = Build.ProjectReferenceGraph.Graph;
520-
#endif
521514

522515
var graphHostControl = new GraphHostControl();
523-
graphHostControl.Graph = graph;
524516
graphHostControl.DisplayText += text => DisplayText(text, "Graph");
525517
graphHostControl.GoToSearch += text => SelectSearchTab(text);
518+
graphHostControl.Graph = graph;
526519

527520
projectReferenceGraphTab.Content = graphHostControl;
528521
}

src/StructuredLogViewer/Controls/GraphControl.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public GraphControl()
3131
layersControl = new StackPanel { Orientation = Orientation.Vertical };
3232

3333
canvas = new Canvas();
34+
canvas.SetResourceReference(Panel.BackgroundProperty, "Theme_WhiteBackground");
3435

3536
grid = new Grid();
3637
grid.Children.Add(canvas);
@@ -207,6 +208,12 @@ void AddLine(FrameworkElement fromControl, FrameworkElement toControl, Brush str
207208
AddLine(sourcePoint, destinationPoint, stroke);
208209
}
209210

211+
void AddRectangle(FrameworkElement element, Brush stroke, Brush fill = null)
212+
{
213+
var rect = GetRectOnCanvas(element);
214+
AddRectangle(rect, stroke, fill);
215+
}
216+
210217
void AddRectangle(Rect rect, Brush stroke, Brush fill = null)
211218
{
212219
var rectangleShape = new System.Windows.Shapes.Rectangle
@@ -260,8 +267,6 @@ private void SelectControls(FrameworkElement fromControl, FrameworkElement toCon
260267
}
261268

262269
var highlighted = new HashSet<FrameworkElement>();
263-
highlighted.Add(fromControl);
264-
highlighted.Add(toControl);
265270

266271
var edges = new HashSet<(FrameworkElement start, FrameworkElement end)>();
267272

@@ -282,12 +287,17 @@ private void SelectControls(FrameworkElement fromControl, FrameworkElement toCon
282287
}
283288
});
284289

290+
highlighted.Remove(fromControl);
291+
highlighted.Remove(toControl);
292+
285293
foreach (var highlight in highlighted)
286294
{
287-
var rect = GetRectOnCanvas(highlight);
288-
AddRectangle(rect, new SolidColorBrush(Colors.Red), Brushes.Pink);
295+
AddRectangle(highlight, new SolidColorBrush(Colors.Blue), Brushes.Azure);
289296
}
290297

298+
AddRectangle(fromControl, Brushes.Red, Brushes.Pink);
299+
AddRectangle(toControl, Brushes.Red, Brushes.Pink);
300+
291301
foreach (var edge in edges)
292302
{
293303
AddLine(edge.start, edge.end, outgoingBrush);

src/StructuredLogViewer/Controls/GraphHostControl.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public GraphHostControl()
1818

1919
private Digraph graph;
2020
private GraphControl graphControl;
21+
private Button searchButton;
22+
private Button showTextButton;
2123

2224
public Digraph Graph
2325
{
@@ -39,9 +41,19 @@ public Digraph Graph
3941
{
4042
graphControl.Digraph = graph;
4143
}
44+
45+
UpdateVisibility();
4246
}
4347
}
4448

49+
private void UpdateVisibility()
50+
{
51+
var textVisibility = DisplayText != null ? Visibility.Visible : Visibility.Collapsed;
52+
var searchVisibility = GoToSearch != null ? Visibility.Visible : Visibility.Collapsed;
53+
showTextButton.Visibility = textVisibility;
54+
searchButton.Visibility = searchVisibility;
55+
}
56+
4557
private void Initialize()
4658
{
4759
var toolbars = new StackPanel();
@@ -73,7 +85,7 @@ private void Initialize()
7385
Visibility = Visibility.Hidden
7486
};
7587

76-
var searchButton = new Button
88+
searchButton = new Button
7789
{
7890
Content = "Go to search",
7991
VerticalAlignment = VerticalAlignment.Center,
@@ -82,7 +94,7 @@ private void Initialize()
8294
Visibility = Visibility.Hidden
8395
};
8496

85-
var showTextButton = new Button
97+
showTextButton = new Button
8698
{
8799
Content = "Show graph text",
88100
VerticalAlignment = VerticalAlignment.Center,
@@ -135,7 +147,7 @@ private void Initialize()
135147
{
136148
projectNameTextBlock.Text = selectedVertex.Value;
137149
projectNameTextBlock.Visibility = Visibility.Visible;
138-
searchButton.Visibility = Visibility.Visible;
150+
searchButton.Visibility = GoToSearch != null ? Visibility.Visible : Visibility.Collapsed;
139151
}
140152
else
141153
{

src/StructuredLogViewer/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<MenuItem Header="Rebuild Solution/Project" Click="Rebuild_Click" InputGestureText="Shift+F6" />
2525
<Separator />
2626
<MenuItem Header="_Open Log..." Click="Open_Click" InputGestureText="Ctrl+O" />
27+
<MenuItem Header="_Open Graph..." Click="OpenGraph_Click" />
2728
<MenuItem x:Name="ReloadMenu" Header="_Reload" Click="Reload_Click" InputGestureText="F5" />
2829
<MenuItem x:Name="SaveAsMenu" Header="_Save Log As..." Click="SaveAs_Click" InputGestureText="Ctrl+S" />
2930
<MenuItem x:Name="RedactSecretsMenu" Header="_Redact Secrets" Click="RedactSecrets_Click" InputGestureText="Ctrl+R" />

src/StructuredLogViewer/MainWindow.xaml.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ public bool OpenFile(string filePath)
403403
return true;
404404
}
405405

406+
if (filePath.EndsWith(".dot", StringComparison.OrdinalIgnoreCase))
407+
{
408+
OpenGraphFile(filePath);
409+
return true;
410+
}
411+
406412
if (filePath.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) ||
407413
filePath.EndsWith("proj", StringComparison.OrdinalIgnoreCase))
408414
{
@@ -670,6 +676,27 @@ await System.Threading.Tasks.Task.Run(() =>
670676
}
671677
}
672678

679+
private void OpenGraphFile(string filePath)
680+
{
681+
DisplayBuild(null);
682+
683+
try
684+
{
685+
var graph = Digraph.Load(filePath);
686+
graph.CalculateHeight();
687+
graph.CalculateDepth();
688+
graph.ComputeTransitiveReduction();
689+
690+
var graphHostControl = new GraphHostControl();
691+
graphHostControl.Graph = graph;
692+
693+
SetContent(graphHostControl);
694+
}
695+
catch
696+
{
697+
}
698+
}
699+
673700
private void AddNuGetNode(Build build)
674701
{
675702
var nuget = new Package { Name = "NuGet" };
@@ -773,6 +800,11 @@ private void Open_Click(object sender, RoutedEventArgs e)
773800
OpenLogFile();
774801
}
775802

803+
private void OpenGraph_Click(object sender, RoutedEventArgs e)
804+
{
805+
OpenGraphFile();
806+
}
807+
776808
private void Build_Click(object sender, RoutedEventArgs e)
777809
{
778810
OpenProjectOrSolution();
@@ -847,6 +879,21 @@ private void Reload()
847879
OpenLogFile(logFilePath);
848880
}
849881

882+
private void OpenGraphFile()
883+
{
884+
var openFileDialog = new OpenFileDialog();
885+
openFileDialog.Filter = Serialization.OpenFileGraphFilter;
886+
openFileDialog.Title = "Open a graph file";
887+
openFileDialog.CheckFileExists = true;
888+
var result = openFileDialog.ShowDialog(this);
889+
if (result != true)
890+
{
891+
return;
892+
}
893+
894+
OpenGraphFile(openFileDialog.FileName);
895+
}
896+
850897
private async System.Threading.Tasks.Task RedactSecrets()
851898
{
852899
RedactInputControl redactInputControl = new RedactInputControl(GetSaveAsDestination);

src/StructuredLogger/Analyzers/TargetGraph.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Microsoft.Build.Logging.StructuredLogger
1010
public class TargetGraphManager : ISearchExtension
1111
{
1212
public Build Build { get; }
13-
public Func<ProjectEvaluation, string> TextProvider { get; set; }
1413

1514
public bool AugmentOtherResults => true;
1615

@@ -44,7 +43,7 @@ public TargetGraph GetTargetGraph(ProjectEvaluation evaluation)
4443
return graph;
4544
}
4645

47-
var preprocessedText = this.TextProvider?.Invoke(evaluation);
46+
var preprocessedText = Build.TextProvider?.Invoke(evaluation);
4847
if (preprocessedText == null)
4948
{
5049
return null;

src/StructuredLogger/ObjectModel/Build.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class Build : TimedNode
1818

1919
public IList<ISearchExtension> SearchExtensions { get; } = new List<ISearchExtension>();
2020

21+
public Func<ProjectEvaluation, string> TextProvider { get; set; }
22+
2123
public bool IsAnalyzed { get; set; }
2224
public bool Succeeded { get; set; } = true;
2325
public Error FirstError { get; set; }

src/StructuredLogger/Serialization/Serialization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Reflection;
77
using System.Runtime.CompilerServices;
88
using System.Xml.Linq;
9-
using static Microsoft.Build.Logging.StructuredLogger.BinLogReader;
109

1110
namespace Microsoft.Build.Logging.StructuredLogger
1211
{
@@ -15,6 +14,7 @@ public static class Serialization
1514
public static readonly string FileDialogFilter = "Structured Log (*.buildlog)|*.buildlog|Readable (large) XML Log (*.xml)|*.xml";
1615
public static readonly string BinlogFileDialogFilter = "Binary Log (*.binlog)|*.binlog|Structured Log (*.buildlog)|*.buildlog|Readable (large) XML Log (*.xml)|*.xml";
1716
public static readonly string OpenFileDialogFilter = "Build Log (*.binlog;*.buildlog;*.xml)|*.binlog;*.buildlog;*.xml";
17+
public static readonly string OpenFileGraphFilter = "Graph (*.dot)|*.dot";
1818

1919
public static readonly XName[] AttributeNameList = typeof(AttributeNames)
2020
.GetFields(BindingFlags.Public | BindingFlags.Static)

0 commit comments

Comments
 (0)