private static void ShowSaveGame(SaveGameMessage message) { string fileName = null; try { SaveFileDialog dialog = new SaveFileDialog { Title = "Save Game", DefaultExt = ".pgn", Filter = "Portable Game Notation|*.pgn", AddExtension = true, FileName = Path.GetFileNameWithoutExtension(message.GameRecording.FileName) }; if (dialog.ShowDialog(Application.Current.MainWindow).GetValueOrDefault()) { using (Stream outputStream = dialog.OpenFile()) { message.GameRecording.SavePGN(outputStream); fileName = dialog.SafeFileName; } } } catch (Exception ex) { ExceptionUtils.HandleException(ex); } finally { message.Process(fileName); } }
private void InitMessageHandlers() { // Receive any move and update the primary game's state. CommitMoveMessage.Register(MessengerInstance, this, action => UpdateGame(action, PrimaryGame)); // These message handlers stay irrespective of the ActiveMode UndoMessage.Register(MessengerInstance, this, () => Undo(ModeSpecificGame())); RedoMessage.Register(MessengerInstance, this, () => Redo(ModeSpecificGame())); SwitchGameViewModeMessage.Register(MessengerInstance, this, mode => ActiveMode = mode); PauseGameMessage.Register(MessengerInstance, this, () => _aiLoopCanRun = false); // someone requested that the current state of the game be saved RequestSaveToGameScreenMessage.Register( MessengerInstance, this, () => { SaveGameMessage.Send(MessengerInstance, (GameId, PrimaryGame.Memento)); PrimaryNeedsSaving = false; });