コード例 #1
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();

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

            bool shouldAnalyze = true;

            var stopwatch = Stopwatch.StartNew();

            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.InvokeAsync(() => { }, DispatcherPriority.Loaded); // let the progress message be rendered before we block the UI again

            DisplayBuild(build);

            var elapsed = stopwatch.Elapsed;

            if (currentBuild != null)
            {
                currentBuild.UpdateBreadcrumb($"Load time: {elapsed}");
            }
        }
コード例 #2
0
        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);
                });
            }
        }
コード例 #3
0
        private void SaveAs()
        {
            if (currentBuild != null)
            {
                var saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter          = Serialization.FileDialogFilter;
                saveFileDialog.Title           = "Save log file as";
                saveFileDialog.CheckFileExists = false;
                saveFileDialog.OverwritePrompt = true;
                saveFileDialog.ValidateNames   = true;
                var result = saveFileDialog.ShowDialog(this);
                if (result != true)
                {
                    return;
                }

                logFilePath = saveFileDialog.FileName;
                System.Threading.Tasks.Task.Run(() =>
                {
                    currentBuild.LogFilePath       = logFilePath;
                    currentBuild.Build.LogFilePath = logFilePath;
                    Serialization.Write(currentBuild.Build, logFilePath);
                    Dispatcher.InvokeAsync(() =>
                    {
                        currentBuild.UpdateBreadcrumb(new Message {
                            Text = $"Saved {logFilePath}"
                        });
                    });
                    SettingsService.AddRecentLogFile(logFilePath);
                });
            }
        }
コード例 #4
0
        private void SaveAs()
        {
            if (currentBuild != null)
            {
                string currentFilePath = currentBuild.LogFilePath;

                var saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter          = currentFilePath != null && currentFilePath.EndsWith(".binlog", StringComparison.OrdinalIgnoreCase) ? Serialization.BinlogFileDialogFilter : Serialization.FileDialogFilter;
                saveFileDialog.Title           = "Save log file as";
                saveFileDialog.CheckFileExists = false;
                saveFileDialog.OverwritePrompt = true;
                saveFileDialog.ValidateNames   = true;
                var result = saveFileDialog.ShowDialog(this);
                if (result != true)
                {
                    return;
                }

                string newFilePath = saveFileDialog.FileName;
                if (string.IsNullOrEmpty(newFilePath) || string.Equals(currentFilePath, newFilePath, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }

                logFilePath = saveFileDialog.FileName;

                lock (inProgressOperationLock)
                {
                    InProgressTask = InProgressTask.ContinueWith(t =>
                    {
                        try
                        {
                            if (logFilePath.EndsWith(".binlog", StringComparison.OrdinalIgnoreCase))
                            {
                                File.Copy(currentFilePath, logFilePath, overwrite: true);
                            }
                            else
                            {
                                Serialization.Write(currentBuild.Build, logFilePath);
                            }

                            currentBuild.Build.LogFilePath = logFilePath;

                            Dispatcher.InvokeAsync(() =>
                            {
                                currentBuild.UpdateBreadcrumb(new Message {
                                    Text = $"Saved {logFilePath}"
                                });
                            });
                            SettingsService.AddRecentLogFile(logFilePath);
                        }
                        catch
                        {
                        }
                    });
                }
            }
        }