private void TrackTaskProgress(Func <IProgress <RescanProgress>, Task> getTask) { var task = new InProgressTask(getTask, this.UpdateProgress); lock (this.tasks) { this.lastProgress = 0; this.tasks.Add(task); this.taskVersion++; } this.UpdateProgress(); task.Task.ContinueWith( _ => { lock (this.tasks) { this.tasks.Remove(task); this.taskVersion++; } this.UpdateProgress(); }, TaskScheduler.Current); }
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 { } }); } } }