private static void OnSaveAsExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     Infrastructure.Container.GetExportedValue<IGameSerializer>().SaveGame(e.ExtractDataContext<ClearMineViewModel>().Game);
 }
 private static void OnSaveSettingsExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     e.ExtractDataContext<ITransaction>(vm =>
     {
         vm.Commit();
         (sender as DependencyObject).CloseParentWindow(true);
     });
 }
 private static void OnRefreshExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     e.ExtractDataContext<ClearMineViewModel>().Game.Restart();
 }
        private static void OnOptionExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var viewModel = e.ExtractDataContext<ClearMineViewModel>();
            bool shouldResume = false;
            if (viewModel.Game.GameState == GameState.Started)
            {
                shouldResume = true;

                // Pause the game may takes long time. Needn't wait that finish;
                Application.Current.Dispatcher.BeginInvoke(new Action(viewModel.Game.PauseGame), DispatcherPriority.Background);
            }

            var result = MessageManager.SendMessage<ShowDialogMessage>(e.OriginalSource, PopupDialog.Options, new OptionsViewModel());

            if ((bool)result)
            {
                viewModel.StartNewGame();
            }
            else if (shouldResume)
            {
                viewModel.Game.ResumeGame();
            }
        }
 private static void OnOptionCloseExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     e.ExtractDataContext<ITransaction>(vm =>
     {
         if (vm != null)
             vm.Rollback();
         (sender as DependencyObject).CloseParentWindow(false);
     });
 }
 private static void OnOpenExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     var openFileDialog = new OpenFileDialog();
     openFileDialog.DefaultExt = Settings.Default.SavedGameExt;
     openFileDialog.Filter = ResourceHelper.FindText("SavedGameFilter", Settings.Default.SavedGameExt);
     if (openFileDialog.ShowDialog() == true)
     {
         Infrastructure.Container.GetExportedValue<IGameSerializer>().LoadGame(openFileDialog.FileName,
             e.ExtractDataContext<ClearMineViewModel>().Game.GetType());
     }
 }
 private static void OnNewGameExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     e.ExtractDataContext<ClearMineViewModel>().StartNewGame();
 }