private async Task RunJob(int jobNdx, bool simMode, bool debugMode, bool exportConfig, bool showLogFile, bool showErrFile, bool showDebugFile) { SetUIJobRunning(); runner = new BackupRunner(settings, settings.Jobs[jobNdx].ID); if (Program.cmdLineHelper.RunViaCommandLine == false) // no DirSearch delegate hooks if running via command-line { runner.OnFolderHit += Runner_OnFolderHit; } // run the slow part async to allow UI to be responsive await Task.Run(() => { runner.Run(simMode, debugMode); }); if (Program.cmdLineHelper.RunViaCommandLine == false) { runner.OnFolderHit -= Runner_OnFolderHit; } // this is an exception where we are showing an error dialog even if it might be run via command-line // this is because any errors indicate a fatal pre-run validation error if (runner.RanSuccessfully == false) { ShowErrMsg("Fatal error during job run. Error: " + runner.RunError); // processing errors start at -10 to -20 Program.cmdLineHelper.CmdErrorCode = AppError_JobFailedInternalValidation; SetUIJobReady(); return; } // export config only if instructed and simulation mode is off if (exportConfig && simMode == false) { string exportName = Path.Combine(runner.Stats.DestPathRoot, BackupSettings.GetBaseNameVersioned(runner.Stats.JobStamp)); BackupSettings.SaveSettings(settings, exportName); } string endHow = runner.CancelFlag ? "Cancelled by User" : "Completed"; UpdateStatusBarText($"{endHow} - Errors: {runner.Stats.NumErrors} Log File: {runner.Stats.StatsLogFileName}"); if (showLogFile) { Process.Start(runner.Stats.StatsLogFileName); } if (runner.Stats.NumErrors > 0) { ShowErrMsg($"Errors encountered: {runner.Stats.NumErrors}. See error log: {runner.Stats.ErrLogFileName}"); if (showErrFile) { Process.Start(runner.Stats.ErrLogFileName); } } if (showDebugFile) { Process.Start(runner.Stats.DebugFileName); } runner = null; SetUIJobReady(); }
private void SaveSettings() { BackupSettings.SaveSettings(settings); UpdateStatusBarText($"Configuration saved to: {BackupSettings.GetUserSaveName()} at {DateTime.Now}"); }