//********************************************************************************************************************************************************************************************** private async Task SavePuzzle() { try { if (PuzzleHandle == null) { return; } System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog(); saveFileDialog.Title = "Please enter the output file name"; saveFileDialog.Filter = "XML file|*.xml"; saveFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(PuzzleHandle.PuzzleXMLOutputPath); saveFileDialog.RestoreDirectory = true; saveFileDialog.FileName = System.IO.Path.GetFileName(PuzzleHandle.PuzzleXMLOutputPath); if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { PuzzleSavingState = PuzzleSavingStates.SAVING; logHandle.Report(new LogEventInfo("Saving puzzle to \"" + PuzzleHandle.PuzzleXMLOutputPath + "\"")); PuzzleHandle.PuzzleXMLOutputPath = saveFileDialog.FileName; await Task.Run(() => { PuzzleHandle.Save(PuzzleHandle.PuzzleXMLOutputPath, PluginFactory.GetGeneralSettingsPlugin().CompressPuzzleOutputFile); }); PuzzleSavingState = PuzzleSavingStates.SAVED; logHandle.Report(new LogEventInfo("Saving puzzle ready.")); CommandManager.InvalidateRequerySuggested(); } } catch (Exception ex) { PuzzleSavingState = PuzzleSavingStates.ERROR; logHandle.Report(new LogEventError("Error while saving: " + ex.Message)); } }
//********************************************************************************************************************************************************************************************** private async void StartSolving() { if (PuzzleHandle == null) { return; } ScrollLogEntries = false; cancelTokenSource = new CancellationTokenSource(); PuzzleHandle.SetCancelToken(cancelTokenSource.Token); PluginFactory.CancelToken = cancelTokenSource.Token; stopWatchDispatcherTimer.Start(); StopWatchSolver.Restart(); try { workerTask = PuzzleHandle.Init(); await workerTask; if (PuzzleHandle.CurrentSolverState != PuzzleSolverState.ERROR) { workerTask = PuzzleHandle.Solve(); await workerTask; } } catch (Exception) { /* the exceptions are catches inside the methods */ } StopWatchSolver.Stop(); stopWatchDispatcherTimer.Stop(); CommandManager.InvalidateRequerySuggested(); ScrollLogEntries = true; }