-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathBuildControl.xaml.cs
2893 lines (2512 loc) · 109 KB
/
BuildControl.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using System.Xml;
using DotUtils.MsBuild.SensitiveDataDetector;
using Microsoft.Build.Experimental.ProjectCache;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging.StructuredLogger;
using Microsoft.Language.Xml;
using Mono.Cecil;
using StructuredLogViewer.Core.ProjectGraph;
using TPLTask = System.Threading.Tasks.Task;
namespace StructuredLogViewer.Controls
{
public partial class BuildControl : UserControl
{
public Build Build { get; set; }
public TreeViewItem SelectedTreeViewItem { get; private set; }
public string LogFilePath => Build?.LogFilePath;
private SourceFileResolver sourceFileResolver;
private ArchiveFileResolver archiveFile => sourceFileResolver.ArchiveFile;
private PreprocessedFileManager preprocessedFileManager;
private NavigationHelper navigationHelper;
private MenuItem searchMenuGroup;
private MenuItem copyMenuGroup;
private MenuItem gotoMenuGroup;
private MenuItem copyItem;
private MenuItem copySubtreeItem;
private MenuItem viewSubtreeTextItem;
private MenuItem searchInSubtreeItem;
private MenuItem searchInNodeByNameItem;
private MenuItem searchThisNode;
private MenuItem excludeSubtreeFromSearchItem;
private MenuItem excludeNodeByNameFromSearch;
private MenuItem searchInclusiveWithinThisTimespan; // Search with Start OR End time overlaps this duration.
private MenuItem searchExclusiveWithinThisTimespan; // Search with Start AND End time overlaps this duration.
private MenuItem goToTimeLineItem;
private MenuItem goToTracingItem;
private MenuItem copyChildrenItem;
private MenuItem sortChildrenItem;
private MenuItem filterChildrenItem;
private MenuItem copyNameItem;
private MenuItem copyValueItem;
private MenuItem viewSourceItem;
private MenuItem viewFullTextItem;
private MenuItem openFileItem;
private MenuItem copyFilePathItem;
private MenuItem preprocessItem;
private MenuItem searchNuGetItem;
private MenuItem runItem;
private MenuItem debugItem;
private MenuItem hideItem;
private MenuItem showTimeItem;
private MenuItem favoriteItem;
private MenuItem unfavoriteItem;
private MenuItem favoriteSharedItem;
private MenuItem unfavoriteSharedItem;
private Separator separator1;
private Separator separator2;
private ContextMenu sharedTreeContextMenu;
private ContextMenu filesTreeContextMenu;
private TreeView ActiveTreeView;
private PropertiesAndItemsSearch propertiesAndItemsSearch;
private SecretsSearch secretsSearch;
public BuildControl(Build build, string logFilePath)
{
InitializeComponent();
UpdateWatermark();
searchLogControl.ExecuteSearch = (searchText, maxResults, cancellationToken) =>
{
if (Build.SearchIndex is { } index)
{
index.MaxResults = maxResults;
index.MarkResultsInTree = SettingsService.MarkResultsInTree;
var indexResults = index.FindNodes(searchText, cancellationToken);
PrecalculationDuration = index.PrecalculationDuration;
return indexResults;
}
var search = new Search(
new[] { Build },
Build.StringTable.Instances,
maxResults,
SettingsService.MarkResultsInTree);
var results = search.FindNodes(searchText, cancellationToken);
PrecalculationDuration = search.PrecalculationDuration;
return results;
};
searchLogControl.ResultsTreeBuilder = BuildResultTree;
searchLogControl.WatermarkDisplayed += () =>
{
Search.ClearSearchResults(Build, SettingsService.MarkResultsInTree);
UpdateWatermark();
};
propertiesAndItemsSearch = new PropertiesAndItemsSearch();
propertiesAndItemsControl.ExecuteSearch = (searchText, maxResults, cancellationToken) =>
{
var context = GetProjectContext() as TimedNode;
if (context == null)
{
return null;
}
var results = propertiesAndItemsSearch.Search(
context,
searchText,
maxResults,
SettingsService.MarkResultsInTree,
cancellationToken);
return results;
};
propertiesAndItemsControl.ResultsTreeBuilder = BuildResultTree;
UpdatePropertiesAndItemsWatermark();
propertiesAndItemsControl.WatermarkDisplayed += UpdatePropertiesAndItemsWatermark;
propertiesAndItemsControl.RecentItemsCategory = "PropertiesAndItems";
secretsSearch = new SecretsSearch(build);
SetProjectContext(null);
VirtualizingPanel.SetIsVirtualizing(treeView, SettingsService.EnableTreeViewVirtualization);
DataContext = build;
Build = build;
// first try to see if the source archive was embedded in the log
if (build.SourceFiles != null)
{
sourceFileResolver = new SourceFileResolver(build.SourceFiles);
}
else
{
// otherwise try to read from the .zip file on disk if present
sourceFileResolver = new SourceFileResolver(logFilePath);
}
if (Build.Statistics.TimedNodeCount > 1000)
{
projectGraphTab.Visibility = Visibility.Collapsed;
}
// Search Log | Properties and Items | Find in Files
sharedTreeContextMenu = new ContextMenu();
sharedTreeContextMenu.Opened += SharedTreeContextMenu_Opened;
favoriteSharedItem = new MenuItem { Header = "Add to Favorites" };
unfavoriteSharedItem = new MenuItem { Header = "Remove from Favorites" };
var sharedCopyItem = new MenuItem() { Header = "Copy" };
var sharedCopyAllItem = new MenuItem() { Header = "Copy All" };
var sharedCopySubtreeItem = new MenuItem() { Header = "Copy subtree" };
favoriteSharedItem.Click += (s, a) => AddToFavorites();
unfavoriteSharedItem.Click += (s, a) => RemoveFromFavorites();
sharedCopyItem.Click += (s, a) => Copy();
sharedCopyAllItem.Click += (s, a) => CopyAll();
sharedCopySubtreeItem.Click += (s, a) => CopySubtree();
sharedTreeContextMenu.AddItem(favoriteSharedItem);
sharedTreeContextMenu.AddItem(unfavoriteSharedItem);
sharedTreeContextMenu.AddItem(sharedCopyItem);
sharedTreeContextMenu.AddItem(sharedCopyAllItem);
sharedTreeContextMenu.AddItem(sharedCopySubtreeItem);
// Files
filesTreeContextMenu = new ContextMenu();
var filesCopyItem = new MenuItem { Header = "Copy" };
var filesCopyAllItem = new MenuItem { Header = "Copy All" };
var filesCopyPathsItem = new MenuItem { Header = "Copy file paths" };
var filesCopySubtreeItem = new MenuItem { Header = "Copy subtree" };
filesCopyItem.Click += (s, a) => Copy();
filesCopyAllItem.Click += (s, a) => CopyAll();
filesCopyPathsItem.Click += (s, a) => CopyPaths();
filesCopySubtreeItem.Click += (s, a) => CopySubtree();
filesTreeContextMenu.AddItem(filesCopyItem);
filesTreeContextMenu.AddItem(filesCopyAllItem);
filesTreeContextMenu.AddItem(filesCopyPathsItem);
filesTreeContextMenu.AddItem(filesCopySubtreeItem);
// Build Log
var contextMenu = new ContextMenu();
contextMenu.Opened += ContextMenu_Opened;
searchMenuGroup = new() { Header = "Search" };
copyMenuGroup = new() { Header = "Copy" };
gotoMenuGroup = new() { Header = "Go to" };
copyItem = new MenuItem() { Header = "Copy" };
copySubtreeItem = new MenuItem() { Header = "Copy subtree" };
viewSubtreeTextItem = new MenuItem() { Header = "View subtree text" };
searchInSubtreeItem = new MenuItem() { Header = "Search in subtree" };
excludeSubtreeFromSearchItem = new MenuItem() { Header = "Exclude subtree from search" };
excludeNodeByNameFromSearch = new MenuItem() { Header = "Exclude node from search" };
searchInclusiveWithinThisTimespan = new MenuItem() { Header = "Search overlapping this duration" };
searchExclusiveWithinThisTimespan = new MenuItem() { Header = "Search within this duration" };
searchInNodeByNameItem = new MenuItem() { Header = "Search in this node." };
searchThisNode = new MenuItem() { Header = "Search This Node" };
goToTimeLineItem = new MenuItem() { Header = "Timeline" };
goToTracingItem = new MenuItem() { Header = "Tracing" };
copyChildrenItem = new MenuItem() { Header = "Copy children" };
sortChildrenItem = new MenuItem() { Header = "Sort children" };
filterChildrenItem = new MenuItem() { Header = "Filter children (Ctrl+F)" };
copyNameItem = new MenuItem() { Header = "Copy name" };
copyValueItem = new MenuItem() { Header = "Copy value" };
viewSourceItem = new MenuItem() { Header = "View source" };
viewFullTextItem = new MenuItem { Header = "View full text" };
showTimeItem = new MenuItem() { Header = "Show time and duration" };
favoriteItem = new MenuItem() { Header = "Add to Favorites" };
unfavoriteItem = new MenuItem() { Header = "Remove from Favorites" };
openFileItem = new MenuItem() { Header = "Open File" };
copyFilePathItem = new MenuItem() { Header = "Copy file path" };
preprocessItem = new MenuItem() { Header = "Preprocess" };
var nugetImage = new System.Windows.Shapes.Path
{
Data = (Geometry)Application.Current.FindResource("NuGetGeometry"),
Stroke = (Brush)Application.Current.FindResource("NuGet"),
Fill = (Brush)Application.Current.FindResource("NuGet"),
Width = 16,
Height = 16,
StrokeThickness = 1
};
searchNuGetItem = new MenuItem() { Header = "Search project.assets.json", Icon = nugetImage };
hideItem = new MenuItem() { Header = "Hide" };
runItem = new MenuItem() { Header = "Run" };
debugItem = new MenuItem() { Header = "Debug" };
copyItem.Click += (s, a) => Copy();
copySubtreeItem.Click += (s, a) => CopySubtree(ActiveTreeView);
viewSubtreeTextItem.Click += (s, a) => ViewSubtreeText();
searchInSubtreeItem.Click += (s, a) => SearchInSubtree();
excludeSubtreeFromSearchItem.Click += (s, a) => ExcludeSubtreeFromSearch();
excludeNodeByNameFromSearch.Click += (s, a) => ExcludeNodeByNameFromSearch();
searchInclusiveWithinThisTimespan.Click += (s, a) => SearchInclusiveWithinThisTimespan();
searchExclusiveWithinThisTimespan.Click += (s, a) => SearchExclusiveWithinThisTimespan();
searchInNodeByNameItem.Click += (s, a) => SearchInNodeByName();
searchThisNode.Click += (s, a) => SearchThisNode();
goToTimeLineItem.Click += (s, a) => GoToTimeLine();
goToTracingItem.Click += (s, a) => GoToTracing();
copyChildrenItem.Click += (s, a) => CopyChildren();
sortChildrenItem.Click += (s, a) => SortChildren();
filterChildrenItem.Click += (s, a) => FilterChildren();
copyNameItem.Click += (s, a) => CopyName();
copyValueItem.Click += (s, a) => CopyValue();
viewSourceItem.Click += (s, a) => Invoke(treeView.SelectedItem as BaseNode);
viewFullTextItem.Click += (s, a) => ViewFullText(treeView.SelectedItem as BaseNode);
showTimeItem.Click += (s, a) => ShowTimeAndDuration();
favoriteItem.Click += (s, a) => AddToFavorites();
unfavoriteItem.Click += (s, a) => RemoveFromFavorites();
openFileItem.Click += (s, a) => OpenFile();
copyFilePathItem.Click += (s, a) => CopyFilePath();
preprocessItem.Click += (s, a) => Preprocess(treeView.SelectedItem as IPreprocessable);
searchNuGetItem.Click += (s, a) => SearchNuGet(treeView.SelectedItem as IProjectOrEvaluation);
runItem.Click += (s, a) => Run(treeView.SelectedItem as Task, debug: false);
debugItem.Click += (s, a) => Run(treeView.SelectedItem as Task, debug: true);
hideItem.Click += (s, a) => Delete();
separator1 = new Separator();
separator2 = new Separator();
contextMenu.AddItem(favoriteItem);
contextMenu.AddItem(unfavoriteItem);
contextMenu.AddItem(runItem);
contextMenu.AddItem(debugItem);
contextMenu.AddItem(viewSourceItem);
contextMenu.AddItem(viewFullTextItem);
contextMenu.AddItem(openFileItem);
contextMenu.AddItem(preprocessItem);
contextMenu.AddItem(searchMenuGroup);
searchMenuGroup.AddItem(searchNuGetItem);
searchMenuGroup.AddItem(searchInSubtreeItem);
searchMenuGroup.AddItem(searchInNodeByNameItem);
searchMenuGroup.AddItem(searchThisNode);
searchMenuGroup.AddItem(excludeSubtreeFromSearchItem);
searchMenuGroup.AddItem(excludeNodeByNameFromSearch);
searchMenuGroup.AddItem(searchInclusiveWithinThisTimespan);
searchMenuGroup.AddItem(searchExclusiveWithinThisTimespan);
contextMenu.AddItem(gotoMenuGroup);
gotoMenuGroup.AddItem(goToTimeLineItem);
gotoMenuGroup.AddItem(goToTracingItem);
contextMenu.AddItem(new Separator());
contextMenu.AddItem(copyItem);
contextMenu.AddItem(copySubtreeItem);
contextMenu.AddItem(copyFilePathItem);
contextMenu.AddItem(copyChildrenItem);
contextMenu.AddItem(copyNameItem);
contextMenu.AddItem(copyValueItem);
contextMenu.AddItem(separator2);
contextMenu.AddItem(viewSubtreeTextItem);
contextMenu.AddItem(showTimeItem);
contextMenu.AddItem(separator1);
contextMenu.AddItem(sortChildrenItem);
contextMenu.AddItem(filterChildrenItem);
contextMenu.AddItem(hideItem);
var treeViewItemStyle = TreeViewExtensions.CreateTreeViewItemStyleWithEvents<BaseNode, TreeViewItem>();
treeViewItemStyle.Setters.Add(new EventSetter(MouseDoubleClickEvent, (MouseButtonEventHandler)OnItemDoubleClick));
treeViewItemStyle.Setters.Add(new EventSetter(KeyDownEvent, (KeyEventHandler)OnItemKeyDown));
treeView.ContextMenu = contextMenu;
treeView.ItemContainerStyle = treeViewItemStyle;
treeView.KeyUp += TreeView_KeyDown;
treeView.SelectedItemChanged += TreeView_SelectedItemChanged;
treeView.GotFocus += TreeView_GetFocus;
treeView.AddHandler(TreeViewItem.SelectedEvent, (RoutedEventHandler)TreeViewItem_Selected);
findTextBox.KeyDown += FindTextBox_KeyDown;
searchLogControl.searchTextBox.KeyUp += SearchTextBox_KeyUp;
ActiveTreeView = treeView;
searchLogControl.ResultsList.ItemContainerStyle = treeViewItemStyle;
searchLogControl.ResultsList.SelectedItemChanged += ResultsList_SelectionChanged;
searchLogControl.ResultsList.GotFocus += (s, a) => ActiveTreeView = searchLogControl.ResultsList;
searchLogControl.ResultsList.ContextMenu = sharedTreeContextMenu;
propertiesAndItemsControl.ResultsList.ItemContainerStyle = treeViewItemStyle;
propertiesAndItemsControl.ResultsList.SelectedItemChanged += ResultsList_SelectionChanged;
propertiesAndItemsControl.ResultsList.GotFocus += (s, a) => ActiveTreeView = propertiesAndItemsControl.ResultsList;
propertiesAndItemsControl.ResultsList.ContextMenu = sharedTreeContextMenu;
if (archiveFile != null)
{
findInFilesControl.ExecuteSearch = FindInFiles;
findInFilesControl.ResultsTreeBuilder = BuildFindResults;
findInFilesControl.GotFocus += (s, a) => ActiveTreeView = findInFilesControl.ResultsList;
findInFilesControl.ResultsList.ItemContainerStyle = treeViewItemStyle;
findInFilesControl.ResultsList.GotFocus += (s, a) => ActiveTreeView = findInFilesControl.ResultsList;
findInFilesControl.ResultsList.ContextMenu = sharedTreeContextMenu;
filesTab.Visibility = Visibility.Visible;
findInFilesTab.Visibility = Visibility.Visible;
PopulateFilesTab();
filesTree.ResultsList.ItemContainerStyle = treeViewItemStyle;
filesTree.TextChanged += FilesTree_SearchTextChanged;
var text =
@"This log contains the full text of projects and imported files used during the build.
You can use the 'Files' tab in the bottom left to view these files and the 'Find in Files' tab for full-text search.
For many nodes in the tree (Targets, Tasks, Errors, Projects, etc) pressing SPACE or ENTER or double-clicking
on the node will navigate to the corresponding source code associated with the node.
More functionality is available from the right-click context menu for each node.
Right-clicking a project node may show the 'Preprocess' option if the version of MSBuild was at least 15.3.";
#if DEBUG
text = build.StringTable.Intern(text);
#endif
var folder = new Folder { Name = "Embedded files" };
folder.AddChild(new Note { Text = text });
build.AddChild(folder);
}
favoritesTree.TopPanel.Visibility = Visibility.Collapsed;
favoritesTree.ResultsList.ItemContainerStyle = treeViewItemStyle;
favoritesTree.ResultsList.SelectedItemChanged += ResultsList_SelectionChanged;
favoritesTree.ResultsList.ContextMenu = sharedTreeContextMenu;
favoritesTree.DisplayItems(new[] { new Note { Text = "Right-click any node and Favorite it to add it here" } });
favoritesTree.ResultsList.GotFocus += (s, a) => ActiveTreeView = favoritesTree.ResultsList;
breadCrumb.SelectionChanged += BreadCrumb_SelectionChanged;
Loaded += BuildControl_Loaded;
preprocessedFileManager = new PreprocessedFileManager(this.Build, sourceFileResolver);
preprocessedFileManager.DisplayFile += filePath => DisplayFile(filePath);
navigationHelper = new NavigationHelper(Build, sourceFileResolver);
navigationHelper.OpenFileRequested += filePath => DisplayFile(filePath);
centralTabControl.SelectionChanged += CentralTabControl_SelectionChanged;
}
public void Dispose()
{
// WPF controls
documentWell.Dispose();
searchLogControl.Dispose();
searchLogControl.ResultsList.ItemContainerStyle = null;
searchLogControl.ResultsList.SelectedItemChanged -= ResultsList_SelectionChanged;
searchLogControl.WatermarkDisplayed -= UpdatePropertiesAndItemsWatermark;
searchLogControl.ExecuteSearch = null;
searchLogControl.WatermarkContent = null;
propertiesAndItemsControl.ResultsList.ItemContainerStyle = null;
propertiesAndItemsControl.ResultsList.SelectedItemChanged -= ResultsList_SelectionChanged;
propertiesAndItemsControl.WatermarkDisplayed -= UpdatePropertiesAndItemsWatermark;
propertiesAndItemsControl.ExecuteSearch = null;
propertiesAndItemsControl.WatermarkContent = null;
propertiesAndItemsContext.Content = null;
propertiesAndItemsSearch = null;
breadCrumb.ItemsSource = null;
filesTree.ResultsList.ItemContainerStyle = null;
filesTree.ContextMenu = null;
filesTree.DisplayItems(null);
favoritesTree.ResultsList.ItemContainerStyle = null;
findInFilesControl.ResultsList.ItemContainerStyle = null;
treeView.RemoveHandler(TreeViewItem.SelectedEvent, (RoutedEventHandler)TreeViewItem_Selected);
treeView.SelectedItemChanged -= TreeView_SelectedItemChanged;
treeView.KeyUp -= TreeView_KeyDown;
treeView.GotFocus -= TreeView_GetFocus;
treeView.ItemsSource = null;
treeView.ItemContainerStyle = null;
treeView.ContextMenu = null;
centralTabControl.SelectionChanged -= CentralTabControl_SelectionChanged;
findTextBox.KeyDown -= FindTextBox_KeyDown;
searchLogControl.searchTextBox.KeyUp -= SearchTextBox_KeyUp;
if (this.tracing.Timeline != null)
{
this.tracing.Dispose();
}
if (this.timeline.Timeline != null)
{
this.timeline.Dispose();
}
if (this.graph != null)
{
graph = null;
projectGraphControl.Dispose();
}
// member variables
copyItem = null;
copySubtreeItem = null;
viewSubtreeTextItem = null;
searchInSubtreeItem = null;
excludeSubtreeFromSearchItem = null;
excludeNodeByNameFromSearch = null;
searchInNodeByNameItem = null;
searchThisNode = null;
goToTimeLineItem = null;
goToTracingItem = null;
copyChildrenItem = null;
sortChildrenItem = null;
filterChildrenItem = null;
copyNameItem = null;
copyValueItem = null;
viewSourceItem = null;
viewFullTextItem = null;
openFileItem = null;
copyFilePathItem = null;
preprocessItem = null;
searchNuGetItem = null;
runItem = null;
debugItem = null;
hideItem = null;
showTimeItem = null;
favoriteItem = null;
unfavoriteItem = null;
favoriteSharedItem = null;
unfavoriteSharedItem = null;
sharedTreeContextMenu = null;
filesTreeContextMenu = null;
ActiveTreeView = null;
DataContext = null;
preprocessedFileManager = null;
navigationHelper = null;
projectContext = null;
SelectedTreeViewItem = null;
sourceFileResolver = null;
BaseNode.ClearSelectedNode();
this.Build = null;
}
private void CentralTabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItem = centralTabControl.SelectedItem as TabItem;
if (selectedItem == null)
{
return;
}
else if (selectedItem.Name == nameof(timelineTab))
{
PopulateTimeline();
}
else if (selectedItem.Name == nameof(projectGraphTab))
{
PopulateProjectGraph();
}
else if (selectedItem.Name == nameof(tracingTab))
{
PopulateTrace();
}
}
private void FilesTree_SearchTextChanged(string text)
{
var list = filesTree.ResultsList.ItemsSource as IEnumerable<object>;
if (list != null)
{
UpdateFileVisibility(list.OfType<NamedNode>(), text);
}
}
private bool UpdateFileVisibility(IEnumerable<NamedNode> items, string text)
{
bool visible = false;
if (items == null)
{
return false;
}
foreach (var item in items)
{
if (item is Folder folder)
{
var subItems = folder.Children.OfType<NamedNode>();
var folderVisibility = UpdateFileVisibility(subItems, text);
folder.IsVisible = folderVisibility;
visible |= folderVisibility;
}
else if (item is SourceFile file)
{
if (string.IsNullOrEmpty(text) || file.SourceFilePath.IndexOf(text, StringComparison.OrdinalIgnoreCase) > -1)
{
visible = true;
file.IsVisible = true;
}
else
{
file.IsVisible = false;
}
var subItems = file.Children.OfType<NamedNode>();
var fileVisibility = UpdateFileVisibility(subItems, text);
file.IsVisible |= fileVisibility;
visible |= fileVisibility;
}
else if (item is Target || item is Task)
{
if (string.IsNullOrEmpty(text) ||
item.Name.IndexOf(text, StringComparison.OrdinalIgnoreCase) > -1 ||
(text == "$target" && item is Target) ||
(text == "$task" && item is Task))
{
visible = true;
item.IsVisible = true;
}
else
{
item.IsVisible = false;
}
}
}
return visible;
}
public void SelectTree()
{
centralTabControl.SelectedIndex = 0;
}
private void PopulateTimeline()
{
if (this.timeline.Timeline == null)
{
var timeline = new Timeline(Build, analyzeCpp: false);
this.timeline.BuildControl = this;
this.timeline.SetTimeline(timeline, Build.StartTime.Ticks);
this.timelineWatermark.Visibility = Visibility.Hidden;
this.timeline.Visibility = Visibility.Visible;
}
}
private void PopulateTrace()
{
if (this.tracing.Timeline == null)
{
var start = DateTime.UtcNow;
var timeline = new Timeline(Build, analyzeCpp: true);
var timelineTime = DateTime.UtcNow - start;
this.tracing.TimelineTime = timelineTime;
this.tracing.BuildControl = this;
this.tracing.SetTimeline(timeline, Build.StartTime.Ticks, Build.EndTime.Ticks);
this.tracingWatermark.Visibility = Visibility.Hidden;
this.tracing.Visibility = Visibility.Visible;
}
}
private Microsoft.Msagl.Drawing.Graph graph;
private void PopulateProjectGraph()
{
if (graph != null)
{
return;
}
graph = new MsaglProjectGraphConstructor().FromBuild(Build);
projectGraphControl.BuildControl = this;
if (graph.NodeCount > 1000 || graph.EdgeCount > 10000)
{
centralTabControl.SelectedIndex = 0;
projectGraphTab.Visibility = Visibility.Collapsed;
return;
}
projectGraphControl.SetGraph(graph);
projectGraphControl.Visibility = Visibility.Visible;
projectGraphWatermark.Visibility = Visibility.Collapsed;
}
private static string[] searchExamples = new[]
{
"Copying file from ",
"Resolved file path is ",
"There was a conflict",
"Encountered conflict between",
"Building target completely ",
"is newer than output ",
"Property reassignment: $(",
"out-of-date",
"$task $time",
"$message CompilerServer failed",
"will be compiled because",
};
private static string[] nodeKinds = new[]
{
"$project",
"$projectevaluation",
"$target",
"$task",
"$error",
"$warning",
"$message",
"$property",
"$item",
"$additem",
"$removeitem",
"$metadata",
"$csc",
"$rar",
"$import",
"$noimport",
"$secret"
};
private static Inline MakeLink(string query, SearchAndResultsControl searchControl, string before = " \u2022 ", string after = "\r\n")
{
var hyperlink = new Hyperlink(new Run(query.Trim()));
hyperlink.Click += (s, e) => searchControl.SearchText = query;
var span = new System.Windows.Documents.Span();
if (before != null)
{
span.Inlines.Add(new Run(before));
}
span.Inlines.Add(hyperlink);
if (after != null)
{
if (after == "\r\n")
{
span.Inlines.Add(new LineBreak());
}
else
{
span.Inlines.Add(new Run(after));
}
}
return span;
}
private void UpdateWatermark()
{
string watermarkText0 = @"Type in the search box to search. Press Ctrl+F to focus the search box. Results (up to 1000) will display here.
";
string watermarkText1 = @"
Search for multiple words separated by space (space means AND). Enclose multiple words in double-quotes """" to search for the exact phrase. A single word in quotes means exact match (turns off substring search).
Use syntax like '$property Prop' to narrow results down by item kind. Supported kinds: ";
string watermarkText2 = @" • Use under(FILTER) clause to only include results where any of the nodes in the parent chain matches the FILTER.
• Use notunder(...) as the opposite of under(...).
• Use project(...) to filter by parent project.
• Use not(...) to exclude subqueries.
Examples:
• $csc under($project Core)
• Copying file project(ProjectA.csproj)
Use '$target skipped=false' to exclude skipped targets (use true to only include skipped).
Append [[$time]], [[$start]] and/or [[$end]] to show times and/or durations and sort the results by start time or duration descending (for tasks, targets and projects).
Use start<""2023-11-23 14:30:54.579"", start>, end<, or end> to filter events that start or end before or after a given timestamp. Timestamp needs to be in quotes.
Use '$copy path' where path is a file or directory to find file copy operations involving the file or directory. `$copy substring` will search for copied files containing the substring.
Use '$nuget project(MyProject.csproj) Package.Name' to search for NuGet packages (by name or version), dependencies (direct and transitive) and files coming from NuGet packages.
Use '$projectreference project(MyProject.csproj) RefProj' to search for projects referenced by MyProject.csproj directly or indirectly. For a single matching project all referencing projects will be shown as well.
Examples:
";
var watermark = new TextBlock();
watermark.Inlines.Add(watermarkText0);
var recentSearches = SettingsService.GetRecentSearchStrings();
if (recentSearches.Any())
{
watermark.Inlines.Add(@"
Recent (");
var clearRecentHyperlink = new Hyperlink(new Run("clear"));
clearRecentHyperlink.Click += (s, e) => { SettingsService.RemoveAllRecentSearchText(); UpdateWatermark(); };
watermark.Inlines.Add(clearRecentHyperlink);
watermark.Inlines.Add(@"):
");
foreach (var recentSearch in recentSearches.Where(s => !searchExamples.Contains(s) && !nodeKinds.Contains(s)))
{
watermark.Inlines.Add(MakeLink(recentSearch, searchLogControl));
}
}
watermark.Inlines.Add(watermarkText1);
bool isFirst = true;
foreach (var nodeKind in nodeKinds)
{
if (!isFirst)
{
watermark.Inlines.Add(", ");
}
isFirst = false;
watermark.Inlines.Add(MakeLink(nodeKind + " ", searchLogControl, before: null, after: null));
}
watermark.Inlines.Add(new LineBreak());
watermark.Inlines.Add(new LineBreak());
AddTextWithHyperlinks(watermarkText2, watermark.Inlines, searchLogControl);
foreach (var example in searchExamples)
{
watermark.Inlines.Add(MakeLink(example, searchLogControl));
}
searchLogControl.WatermarkContent = watermark;
}
private void UpdatePropertiesAndItemsWatermark()
{
string watermarkText1 = $@"Look up properties or items for the selected project " +
"or a node under a project or evaluation. " +
"Properties and items might not be available for some projects.\n\n" +
"Surround the search term in quotes to find an exact match " +
"(turns off substring search). Prefix the search term with " +
"[[name=]] or [[value=]] to only search property and metadata names " +
"or values. Add [[$property ]], [[$item ]] or [[$metadata ]] to limit search " +
"to a specific node type.";
var watermark = new TextBlock();
AddTextWithHyperlinks(watermarkText1, watermark.Inlines, propertiesAndItemsControl);
watermark.Inlines.Add(new LineBreak());
watermark.Inlines.Add(new LineBreak());
var recentSearches = SettingsService.GetRecentSearchStrings("PropertiesAndItems");
if (recentSearches.Any())
{
watermark.Inlines.Add(@"
Recent (");
var clearRecentHyperlink = new Hyperlink(new Run("clear"));
clearRecentHyperlink.Click += (s, e) => { SettingsService.RemoveAllRecentSearchText("PropertiesAndItems"); UpdatePropertiesAndItemsWatermark(); };
watermark.Inlines.Add(clearRecentHyperlink);
watermark.Inlines.Add(@"):
");
foreach (var recentSearch in recentSearches)
{
watermark.Inlines.Add(MakeLink(recentSearch, propertiesAndItemsControl));
}
}
propertiesAndItemsControl.WatermarkContent = watermark;
}
public void AddTextWithHyperlinks(string text, InlineCollection result, SearchAndResultsControl searchControl)
{
const string openParen = "[[";
const string closeParen = "]]";
var chunks = TextUtilities.SplitIntoParenthesizedSpans(text, openParen, closeParen);
foreach (var chunk in chunks)
{
if (chunk.StartsWith(openParen) && chunk.EndsWith(closeParen))
{
var link = chunk.Substring(openParen.Length, chunk.Length - openParen.Length - closeParen.Length);
result.Add(MakeLink(link, searchControl, before: null, after: null));
}
else
{
result.Add(chunk);
}
}
}
private void SearchNuGet(IProjectOrEvaluation node)
{
string projectName = Path.GetFileName(node.ProjectFile);
searchLogControl.SearchText = $"$nuget project({projectName})";
SelectSearchTab();
}
private void Preprocess(IPreprocessable project) => preprocessedFileManager.ShowPreprocessed(project);
private void Run(Task task, bool debug = false)
{
var logFilePath = Build.LogFilePath;
if (!File.Exists(logFilePath))
{
MessageBox.Show($"The log file {logFilePath} doesn't exist on disk. Please save the log to disk and reopen it from disk.");
return;
}
try
{
var directory = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
var arguments = $"{logFilePath.QuoteIfNeeded()} {task.Index} pause{(debug ? " debug" : "")}";
var targetFramework = GetTaskTargetFramework(task);
if (targetFramework == null || targetFramework.StartsWith(".NETFramework"))
{
var taskRunnerExe = Path.Combine(directory, "TaskRunner.exe");
Process.Start(taskRunnerExe.QuoteIfNeeded(), arguments);
}
else
{
var taskRunnerDll = Path.Combine(directory, "TaskRunner.dll");
Process.Start("dotnet", $"{taskRunnerDll.QuoteIfNeeded()} {arguments}");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private string GetTaskTargetFramework(Task task)
{
try
{
var taskDllPath = task.FromAssembly;
if (!File.Exists(taskDllPath))
{
// `FromAssembly` might be an assembly name instead of a file path, e.g. "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
// Assuming that this assembly is an MSBuild assembly which is in the same directory as the MSBuild executable
var msbuildDirectory = Path.GetDirectoryName(task.GetNearestParent<Build>()?.MSBuildExecutablePath);
if (msbuildDirectory is not null)
{
var assemblyName = new AssemblyName(task.FromAssembly);
taskDllPath = Path.Combine(msbuildDirectory, $"{assemblyName.Name}.dll");
if (!File.Exists(taskDllPath))
{
return null;
}
}
}
var module = AssemblyDefinition.ReadAssembly(taskDllPath);
var attribute = module.CustomAttributes.FirstOrDefault(a => a.AttributeType.Name == "TargetFrameworkAttribute");
if (attribute == null || attribute.ConstructorArguments.Count != 1)
{
return null;
}
var targetFramework = attribute.ConstructorArguments[0].Value as string;
return targetFramework;
}
catch
{
return null;
}
}
private void ContextMenu_Opened(object sender, RoutedEventArgs e)
{
var node = treeView.SelectedItem as BaseNode;
var nameValueVisibility = node is NameValueNode ? Visibility.Visible : Visibility.Collapsed;
copyNameItem.Visibility = nameValueVisibility;
copyValueItem.Visibility = nameValueVisibility;
viewSourceItem.Visibility = CanView(node) ? Visibility.Visible : Visibility.Collapsed;
viewFullTextItem.Visibility = HasFullText(node) ? Visibility.Visible : Visibility.Collapsed;
openFileItem.Visibility = CanOpenFile(node) ? Visibility.Visible : Visibility.Collapsed;
copyFilePathItem.Visibility = node is Import || (node is IHasSourceFile file && !string.IsNullOrEmpty(file.SourceFilePath))
? Visibility.Visible
: Visibility.Collapsed;
var hasChildren = node is TreeNode t && t.HasChildren;
var hasChildrenVisibility = hasChildren ? Visibility.Visible : Visibility.Collapsed;
copySubtreeItem.Visibility = hasChildrenVisibility;
viewSubtreeTextItem.Visibility = hasChildrenVisibility;
copyChildrenItem.Visibility = hasChildrenVisibility;
sortChildrenItem.Visibility = hasChildrenVisibility;
filterChildrenItem.Visibility = hasChildrenVisibility;
preprocessItem.Visibility = node is IPreprocessable p && preprocessedFileManager.CanPreprocess(p) ? Visibility.Visible : Visibility.Collapsed;
searchNuGetItem.Visibility = node is IProjectOrEvaluation ? Visibility.Visible : Visibility.Collapsed;
Visibility canRun = Build?.LogFilePath != null && node is Task ? Visibility.Visible : Visibility.Collapsed;
runItem.Visibility = canRun;
debugItem.Visibility = canRun;
hideItem.Visibility = node is TreeNode ? Visibility.Visible : Visibility.Collapsed;
separator2.Visibility = Visibility.Visible;
if (node is SearchableItem searchItem)
{
searchThisNode.Visibility = Visibility.Visible;
searchThisNode.Header = $"Search {searchItem.SearchText}";
}
else
{
searchThisNode.Visibility = Visibility.Collapsed;
}
bool isFavorite = IsFavorite(node);
favoriteItem.Visibility = !isFavorite ? Visibility.Visible : Visibility.Collapsed;
unfavoriteItem.Visibility = isFavorite ? Visibility.Visible : Visibility.Collapsed;
if (node is TimedNode timedNode)
{
showTimeItem.Visibility = Visibility.Visible;
separator1.Visibility = Visibility.Visible;
searchInSubtreeItem.Visibility = hasChildren ? Visibility.Visible : Visibility.Collapsed;
excludeSubtreeFromSearchItem.Visibility = hasChildren ? Visibility.Visible : Visibility.Collapsed;
goToTimeLineItem.Visibility = Visibility.Visible;
goToTracingItem.Visibility = Visibility.Visible;
excludeNodeByNameFromSearch.Visibility = hasChildren ? Visibility.Visible : Visibility.Collapsed;
searchInclusiveWithinThisTimespan.Visibility = Visibility.Visible;
searchExclusiveWithinThisTimespan.Visibility = Visibility.Visible;
searchInNodeByNameItem.Visibility = hasChildren ? Visibility.Visible : Visibility.Collapsed;
if (excludeNodeByNameFromSearch.Visibility == Visibility.Visible)
{
excludeNodeByNameFromSearch.Header = $"Exclude '{timedNode.Name}' from search";
}
if (searchInNodeByNameItem.Visibility == Visibility.Visible)
{
searchInNodeByNameItem.Header = $"Search in '{timedNode.Name}'";
}
}
else
{
separator1.Visibility = Visibility.Collapsed;
showTimeItem.Visibility = Visibility.Collapsed;
searchInSubtreeItem.Visibility = Visibility.Collapsed;
excludeSubtreeFromSearchItem.Visibility = Visibility.Collapsed;
goToTimeLineItem.Visibility = Visibility.Collapsed;
goToTracingItem.Visibility = Visibility.Collapsed;
excludeNodeByNameFromSearch.Visibility = Visibility.Collapsed;
searchInclusiveWithinThisTimespan.Visibility = Visibility.Collapsed;
searchExclusiveWithinThisTimespan.Visibility = Visibility.Collapsed;
searchInNodeByNameItem.Visibility = Visibility.Collapsed;
if (!hasChildren)
{
separator2.Visibility = Visibility.Collapsed;
}
}
searchMenuGroup.Visibility = searchMenuGroup.Items.Cast<MenuItem>().Any(p => p.Visibility != Visibility.Collapsed) ?
Visibility.Visible : Visibility.Collapsed;