private async Task SaveAs()
        {
            if (currentBuild != null)
            {
                var saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filters.Add(new FileDialogFilter {
                    Name = "Binary (compact) Structured Build Log (*.buildlog)", Extensions = { "buildlog" }
                });
                saveFileDialog.Filters.Add(new FileDialogFilter {
                    Name = "Readable (large) XML Log (*.xml)", Extensions = { "xml" }
                });
                saveFileDialog.Title = "Save log file as";
                var result = await saveFileDialog.ShowAsync(this);

                if (result == null)
                {
                    return;
                }

                logFilePath = result;
                System.Threading.Tasks.Task.Run(() =>
                {
                    Serialization.Write(currentBuild.Build, logFilePath);
                    Dispatcher.UIThread.InvokeAsync(() =>
                    {
                        currentBuild.UpdateBreadcrumb(new Message {
                            Text = $"Saved {logFilePath}"
                        });
                    });
                    SettingsService.AddRecentLogFile(logFilePath);
                });
            }
        }
Ejemplo n.º 2
0
        private async void OpenLogFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                return;
            }

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

            var progress = new BuildProgress()
            {
                IsIndeterminate = true
            };

            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)
                {
                    ex            = ExceptionHandler.Unwrap(ex);
                    shouldAnalyze = false;
                    return(GetErrorBuild(filePath, ex.ToString()));
                }
            });

            if (build == null)
            {
                build         = GetErrorBuild(filePath, "");
                shouldAnalyze = false;
            }

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

            progress.ProgressText = "Rendering tree...";
            await Dispatcher.UIThread.InvokeAsync(() => { }, DispatcherPriority.Loaded); // let the progress message be rendered before we block the UI again

            DisplayBuild(build);
        }