//[Fact]
        public void SimpleBuild()
        {
            var build = new Build();

            build.Succeeded = true;
            build.AddChild(new Message()
            {
                Text = "MessageText"
            });
            build.AddChild(new Property()
            {
                Name = "PropertyName", Value = "PropertyValue"
            });
            var file1 = @"D:\1.xml";
            var file2 = @"D:\2.xml";

            Serialization.Write(build, file1);
            var filePath = @"D:\1.buildlog";

            Serialization.Write(build, filePath);
            build = Serialization.Read(filePath);
            Serialization.Write(build, file2);
            Serialization.Write(build, @"D:\2.buildlog");
            Differ.AreDifferent(file1, file2);
        }
Esempio n. 2
0
        public Task <Build> BuildAndGetResult(BuildProgress progress)
        {
            var msBuildFile      = SettingsService.GetMSBuildFile();
            var isLibraryMsBuild = msBuildFile?.EndsWith(".dll", StringComparison.OrdinalIgnoreCase);

            msBuildFile = msBuildFile.QuoteIfNeeded();

            var postfixArguments = GetPostfixArguments();

            // the command line we pass to Process.Start doesn't need exec file
            var commandLine = $"{projectFilePath.QuoteIfNeeded()} {customArguments} {postfixArguments}";

            commandLine = isLibraryMsBuild == true ? $"{msBuildFile} {commandLine}" : commandLine;
            var fileExe = isLibraryMsBuild == true ? "dotnet " : msBuildFile;

            // the command line we display to the user should contain the full path to msbuild file
            progress.MSBuildCommandLine = $"{fileExe} {commandLine}";

            return(System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    var processStartInfo = new ProcessStartInfo(fileExe, commandLine);
                    processStartInfo.WorkingDirectory = Path.GetDirectoryName(projectFilePath);
                    var process = Process.Start(processStartInfo);
                    process.WaitForExit();

                    var logFilePath = Path.Combine(currentDirectory, "msbuild.binlog");

                    var build = Serialization.Read(logFilePath);
                    //File.Delete(logFilePath);

                    //var projectImportsZip = Path.ChangeExtension(logFilePath, ".ProjectImports.zip");
                    //if (File.Exists(projectImportsZip))
                    //{
                    //    File.Delete(projectImportsZip);
                    //}

                    return build;
                }
                catch (Exception ex)
                {
                    ex = ExceptionHandler.Unwrap(ex);
                    var build = new Build();
                    build.Succeeded = false;
                    build.AddChild(new Message()
                    {
                        Text = "Exception occurred during build:"
                    });
                    build.AddChild(new Error()
                    {
                        Text = ex.ToString()
                    });
                    return build;
                }
            }));
        }
        private async void OpenLogFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

            DisplayBuild(null);
            this.logFilePath = filePath;
            SettingsService.AddRecentLogFile(filePath);
            UpdateRecentItemsMenu();
            Title = DefaultTitle + " - " + filePath;

            var progress = new BuildProgress();

            progress.ProgressText = "Opening " + filePath + "...";
            SetContent(progress);

            bool shouldAnalyze = true;

            Build build = await System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    return(Serialization.Read(filePath));
                }
                catch (Exception ex)
                {
                    shouldAnalyze = false;
                    build         = new Build()
                    {
                        Succeeded = false
                    };
                    build.AddChild(new Error()
                    {
                        Text = "Error when opening file: " + filePath
                    });
                    build.AddChild(new Error()
                    {
                        Text = ex.ToString()
                    });
                    return(build);
                }
            });

            if (shouldAnalyze)
            {
                progress.ProgressText = "Analyzing " + filePath + "...";
                await System.Threading.Tasks.Task.Run(() => BuildAnalyzer.AnalyzeBuild(build));
            }

            DisplayBuild(build);
        }
        public Task <Build> BuildAndGetResult(BuildProgress progress)
        {
            var msbuildExe       = SettingsService.GetMSBuildExe();
            var postfixArguments = GetPostfixArguments();

            // the command line we pass to Process.Start doesn't need msbuild.exe
            var commandLine = $"{QuoteIfNeeded(projectFilePath)} {customArguments} {postfixArguments}";

            // the command line we display to the user should contain the full path to msbuild.exe
            progress.MSBuildCommandLine = $"{QuoteIfNeeded(msbuildExe)} {commandLine}";

            return(System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    var arguments = commandLine;
                    var processStartInfo = new ProcessStartInfo(msbuildExe, arguments);
                    processStartInfo.WorkingDirectory = Path.GetDirectoryName(projectFilePath);
                    var process = Process.Start(processStartInfo);
                    process.WaitForExit();

                    var build = Serialization.Read(logFilePath);
                    File.Delete(logFilePath);

                    var projectImportsZip = Path.ChangeExtension(logFilePath, ".ProjectImports.zip");
                    if (File.Exists(projectImportsZip))
                    {
                        File.Delete(projectImportsZip);
                    }

                    return build;
                }
                catch (Exception ex)
                {
                    ex = ExceptionHandler.Unwrap(ex);
                    var build = new Build();
                    build.Succeeded = false;
                    build.AddChild(new Message()
                    {
                        Text = "Exception occurred during build:"
                    });
                    build.AddChild(new Error()
                    {
                        Text = ex.ToString()
                    });
                    return build;
                }
            }));
        }
        private static Build GetErrorBuild(string filePath, string message)
        {
            var build = new Build()
            {
                Succeeded = false
            };

            build.AddChild(new Error()
            {
                Text = "Error when opening file: " + filePath
            });
            build.AddChild(new Error()
            {
                Text = message
            });
            return(build);
        }
        public Task <Build> BuildAndGetResult(BuildProgress progress)
        {
            var msbuildExe       = GetMSBuildExe();
            var prefixArguments  = GetPrefixArguments(projectFilePath);
            var postfixArguments = GetPostfixArguments();

            // the command line we display to the user should contain the full path to msbuild.exe
            var commandLine = $@"{prefixArguments} {customArguments} {postfixArguments}";

            progress.MSBuildCommandLine = commandLine;

            // the command line we pass to Process.Start doesn't need msbuild.exe
            commandLine = $@"""{projectFilePath}"" {customArguments} {postfixArguments}";

            return(System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    var arguments = commandLine;
                    var processStartInfo = new ProcessStartInfo(msbuildExe, arguments);
                    processStartInfo.WorkingDirectory = Path.GetDirectoryName(projectFilePath);
                    var process = Process.Start(processStartInfo);
                    process.WaitForExit();

                    var build = XmlLogReader.ReadFromXml(xmlLogFile);
                    File.Delete(xmlLogFile);
                    return build;
                }
                catch (Exception ex)
                {
                    var build = new Build();
                    build.Succeeded = false;
                    build.AddChild(new Message()
                    {
                        Text = "Exception occurred during build:"
                    });
                    build.AddChild(new Error()
                    {
                        Text = ex.ToString()
                    });
                    return build;
                }
            }));
        }
        public BuildControl(Build build, string logFilePath)
        {
            DataContext = build;

            InitializeComponent();

            UpdateWatermark();

            searchLogControl.ExecuteSearch = (searchText, maxResults, cancellationToken) =>
            {
                var search  = new Search(new[] { Build }, Build.StringTable.Instances, maxResults, SettingsService.MarkResultsInTree);
                var results = search.FindNodes(searchText, cancellationToken);
                return(results);
            };
            searchLogControl.ResultsTreeBuilder  = BuildResultTree;
            searchLogControl.WatermarkDisplayed += () =>
            {
                Search.ClearSearchResults(Build);
                UpdateWatermark();
            };

            findInFilesControl.ExecuteSearch      = FindInFiles;
            findInFilesControl.ResultsTreeBuilder = BuildFindResults;

            Build = build;

            LogFilePath = logFilePath;

            if (build.SourceFilesArchive != null)
            {
                // first try to see if the source archive was embedded in the log
                sourceFileResolver = new SourceFileResolver(build.SourceFiles.Values);
            }
            else
            {
                // otherwise try to read from the .zip file on disk if present
                sourceFileResolver = new SourceFileResolver(logFilePath);
            }

            sharedTreeContextMenu = new ContextMenu();
            copyAllItem           = new MenuItem()
            {
                Header = "Copy All"
            };
            copyAllItem.Click += (s, a) => CopyAll();
            sharedTreeContextMenu.AddItem(copyAllItem);

            var contextMenu = new ContextMenu();

            // TODO
            //contextMenu.Opened += ContextMenu_Opened;
            copyItem = new MenuItem()
            {
                Header = "Copy"
            };
            copySubtreeItem = new MenuItem()
            {
                Header = "Copy subtree"
            };
            sortChildrenItem = new MenuItem()
            {
                Header = "Sort children"
            };
            copyNameItem = new MenuItem()
            {
                Header = "Copy name"
            };
            copyValueItem = new MenuItem()
            {
                Header = "Copy value"
            };
            viewItem = new MenuItem()
            {
                Header = "View"
            };
            preprocessItem = new MenuItem()
            {
                Header = "Preprocess"
            };
            hideItem = new MenuItem()
            {
                Header = "Hide"
            };
            copyItem.Click         += (s, a) => Copy();
            copySubtreeItem.Click  += (s, a) => CopySubtree();
            sortChildrenItem.Click += (s, a) => SortChildren();
            copyNameItem.Click     += (s, a) => CopyName();
            copyValueItem.Click    += (s, a) => CopyValue();
            viewItem.Click         += (s, a) => Invoke(treeView.SelectedItem as BaseNode);
            preprocessItem.Click   += (s, a) => Preprocess(treeView.SelectedItem as IPreprocessable);
            hideItem.Click         += (s, a) => Delete();
            contextMenu.AddItem(viewItem);
            contextMenu.AddItem(preprocessItem);
            contextMenu.AddItem(copyItem);
            contextMenu.AddItem(copySubtreeItem);
            contextMenu.AddItem(sortChildrenItem);
            contextMenu.AddItem(copyNameItem);
            contextMenu.AddItem(copyValueItem);
            contextMenu.AddItem(hideItem);

            var treeViewItemStyle = new Style(s => s.OfType <TreeViewItem>())
            {
                Setters = new ISetter[]
                {
                    new Setter(TreeViewItem.IsExpandedProperty, new Binding("IsExpanded")
                    {
                        Mode = BindingMode.TwoWay
                    }),
                    new Setter(TreeViewItem.IsSelectedProperty, new Binding("IsSelected")
                    {
                        Mode = BindingMode.TwoWay
                    }),
                    new Setter(IsVisibleProperty, new Binding("IsVisible")
                    {
                        Mode = BindingMode.TwoWay
                    })
                }
            };

            treeView.ContextMenu = contextMenu;
            treeView.Styles.Add(treeViewItemStyle);
            RegisterTreeViewHandlers(treeView);
            treeView.KeyDown         += TreeView_KeyDown;
            treeView.PropertyChanged += TreeView_SelectedItemChanged;
            treeView.GotFocus        += (s, a) => ActiveTreeView = treeView;

            ActiveTreeView = treeView;

            searchLogControl.ResultsList.Styles.Add(treeViewItemStyle);
            RegisterTreeViewHandlers(searchLogControl.ResultsList);
            searchLogControl.ResultsList.SelectionChanged += ResultsList_SelectionChanged;
            searchLogControl.ResultsList.GotFocus         += (s, a) => ActiveTreeView = searchLogControl.ResultsList;
            searchLogControl.ResultsList.ContextMenu       = sharedTreeContextMenu;

            findInFilesControl.GotFocus += (s, a) => ActiveTreeView = findInFilesControl.ResultsList;
            findInFilesControl.ResultsList.Styles.Add(treeViewItemStyle);
            RegisterTreeViewHandlers(findInFilesControl.ResultsList);
            findInFilesControl.ResultsList.GotFocus   += (s, a) => ActiveTreeView = findInFilesControl.ResultsList;
            findInFilesControl.ResultsList.ContextMenu = sharedTreeContextMenu;

            if (archiveFile != null)
            {
                filesTab.IsVisible       = true;
                findInFilesTab.IsVisible = true;
                PopulateFilesTab();
                filesTree.Styles.Add(treeViewItemStyle);
                RegisterTreeViewHandlers(filesTree);

                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.";
                build.Unseal();
                build.AddChild(new Note {
                    Text = text
                });
                build.Seal();
            }

            breadCrumb.SelectionChanged += BreadCrumb_SelectionChanged;

            TemplateApplied += BuildControl_Loaded;

            preprocessedFileManager              = new PreprocessedFileManager(Build, sourceFileResolver);
            preprocessedFileManager.DisplayFile += path => DisplayFile(path);

            //PopulateTimeline();
        }
Esempio n. 8
0
        public BuildControl(Build build, string logFilePath)
        {
            InitializeComponent();

            UpdateWatermark();

            searchLogControl.ExecuteSearch = searchText =>
            {
                var search  = new Search(Build);
                var results = search.FindNodes(searchText);
                return(results);
            };
            searchLogControl.ResultsTreeBuilder  = BuildResultTree;
            searchLogControl.WatermarkDisplayed += () => UpdateWatermark();

            findInFilesControl.ExecuteSearch      = FindInFiles;
            findInFilesControl.ResultsTreeBuilder = BuildFindResults;

            VirtualizingPanel.SetIsVirtualizing(treeView, SettingsService.EnableTreeViewVirtualization);

            DataContext = build;
            Build       = build;

            LogFilePath = logFilePath;

            if (build.SourceFilesArchive != null)
            {
                // first try to see if the source archive was embedded in the log
                sourceFileResolver = new SourceFileResolver(build.SourceFilesArchive);
            }
            else
            {
                // otherwise try to read from the .zip file on disk if present
                sourceFileResolver = new SourceFileResolver(logFilePath);
            }

            sharedTreeContextMenu = new ContextMenu();
            copyAllItem           = new MenuItem()
            {
                Header = "Copy All"
            };
            copyAllItem.Click += (s, a) => CopyAll();
            sharedTreeContextMenu.Items.Add(copyAllItem);

            var contextMenu = new ContextMenu();

            contextMenu.Opened += ContextMenu_Opened;
            copyItem            = new MenuItem()
            {
                Header = "Copy"
            };
            copySubtreeItem = new MenuItem()
            {
                Header = "Copy subtree"
            };
            sortChildrenItem = new MenuItem()
            {
                Header = "Sort children"
            };
            copyNameItem = new MenuItem()
            {
                Header = "Copy name"
            };
            copyValueItem = new MenuItem()
            {
                Header = "Copy value"
            };
            viewItem = new MenuItem()
            {
                Header = "View"
            };
            preprocessItem = new MenuItem()
            {
                Header = "Preprocess"
            };
            hideItem = new MenuItem()
            {
                Header = "Hide"
            };
            copyItem.Click         += (s, a) => Copy();
            copySubtreeItem.Click  += (s, a) => CopySubtree();
            sortChildrenItem.Click += (s, a) => SortChildren();
            copyNameItem.Click     += (s, a) => CopyName();
            copyValueItem.Click    += (s, a) => CopyValue();
            viewItem.Click         += (s, a) => Invoke(treeView.SelectedItem as ParentedNode);
            preprocessItem.Click   += (s, a) => Preprocess(treeView.SelectedItem as Project);
            hideItem.Click         += (s, a) => Delete();
            contextMenu.Items.Add(viewItem);
            contextMenu.Items.Add(preprocessItem);
            contextMenu.Items.Add(copyItem);
            contextMenu.Items.Add(copySubtreeItem);
            contextMenu.Items.Add(sortChildrenItem);
            contextMenu.Items.Add(copyNameItem);
            contextMenu.Items.Add(copyValueItem);
            contextMenu.Items.Add(hideItem);

            var existingTreeViewItemStyle = (Style)Application.Current.Resources[typeof(TreeViewItem)];
            var treeViewItemStyle         = new Style(typeof(TreeViewItem), existingTreeViewItemStyle);

            treeViewItemStyle.Setters.Add(new Setter(TreeViewItem.IsExpandedProperty, new Binding("IsExpanded")
            {
                Mode = BindingMode.TwoWay
            }));
            treeViewItemStyle.Setters.Add(new Setter(TreeViewItem.IsSelectedProperty, new Binding("IsSelected")
            {
                Mode = BindingMode.TwoWay
            }));
            treeViewItemStyle.Setters.Add(new Setter(TreeViewItem.VisibilityProperty, new Binding("IsVisible")
            {
                Mode = BindingMode.TwoWay, Converter = new BooleanToVisibilityConverter()
            }));
            treeViewItemStyle.Setters.Add(new EventSetter(MouseDoubleClickEvent, (MouseButtonEventHandler)OnItemDoubleClick));
            treeViewItemStyle.Setters.Add(new EventSetter(PreviewMouseRightButtonDownEvent, (MouseButtonEventHandler)OnPreviewMouseRightButtonDown));
            treeViewItemStyle.Setters.Add(new EventSetter(RequestBringIntoViewEvent, (RequestBringIntoViewEventHandler)TreeViewItem_RequestBringIntoView));
            treeViewItemStyle.Setters.Add(new EventSetter(KeyDownEvent, (KeyEventHandler)OnItemKeyDown));

            treeView.ContextMenu          = contextMenu;
            treeView.ItemContainerStyle   = treeViewItemStyle;
            treeView.KeyDown             += TreeView_KeyDown;
            treeView.SelectedItemChanged += TreeView_SelectedItemChanged;
            treeView.GotFocus            += (s, a) => ActiveTreeView = treeView;

            ActiveTreeView = treeView;

            searchLogControl.ResultsList.ItemContainerStyle   = treeViewItemStyle;
            searchLogControl.ResultsList.SelectedItemChanged += ResultsList_SelectionChanged;
            searchLogControl.ResultsList.GotFocus            += (s, a) => ActiveTreeView = searchLogControl.ResultsList;
            searchLogControl.ResultsList.ContextMenu          = sharedTreeContextMenu;

            findInFilesControl.GotFocus += (s, a) => ActiveTreeView = findInFilesControl.ResultsList;
            findInFilesControl.ResultsList.ItemContainerStyle = treeViewItemStyle;
            findInFilesControl.ResultsList.GotFocus          += (s, a) => ActiveTreeView = findInFilesControl.ResultsList;
            findInFilesControl.ResultsList.ContextMenu        = sharedTreeContextMenu;

            if (archiveFile != null)
            {
                filesTab.Visibility       = Visibility.Visible;
                findInFilesTab.Visibility = Visibility.Visible;
                PopulateFilesTab();
                filesTree.ItemContainerStyle = treeViewItemStyle;

                var filesNote = new TextBlock();
                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.";
                build.Unseal();
                build.AddChild(new Note {
                    Text = text
                });
                build.Seal();
            }

            breadCrumb.SelectionChanged += BreadCrumb_SelectionChanged;

            Loaded += BuildControl_Loaded;

            preprocessedFileManager = new PreprocessedFileManager(this, sourceFileResolver);
        }