コード例 #1
0
        private void MyTurnListBox_DoubleClick(object sender, EventArgs e)
        {
            GuiGame selectedGame = MyTurnListBox.SelectedItem as GuiGame;

            if (null == selectedGame)
            {
                return;
            }

            this.SuspendLayout();
            this.FreezeUI(true);

            this.Invoke(new Action(() =>
            {
            }));

            Action <GuiGame> action = null;

            if (!selectedGame.Game.CurrentTurn.IsFirstTurn)
            {
                action = AnyTurnButTheFirstOne;
            }
            else
            {
                action = DoFirstTimeTurn;
            }

            //Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);

            using (BackgroundWorker bw = new BackgroundWorker())
            {
                bw.DoWork += (bwsender, bwe) => action(selectedGame);
                bw.RunWorkerAsync();
            }
        }
コード例 #2
0
 private void DownloadGame(GuiGame selectedGame)
 {
     if ((null != selectedGame) && (this.m_MainViewModel.GMRMainViewModel.Authenticate.Result.Authenticated))
     {
         var cmd = m_MainViewModel.GMRMainViewModel.GetLatestSaveFileBytes;
         cmd.Execute(new GetLatestSaveFileBytesCommandParam(selectedGame.Game.GameId));
     }
 }
コード例 #3
0
        private void DoFirstTimeTurn(GuiGame guiGame)
        {
            Trace.WriteLine("starting...");

            this.Invoke(new Action(() =>
            {
                var dialogResult = MessageBox.Show("This is your first turn." + Environment.NewLine + "Launch Steam ?", "first turn", MessageBoxButtons.YesNo);
                if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    Trace.WriteLine("launching steam (takes a while)");
                    this.m_MainViewModel.CoreMainViewModel.LaunchSteam.Execute();
                }
            }));

            this.Invoke(new Action(() =>
            {
                FileInfo uploadThisFile;
                bool doUploadThisFile = this.TryGetFileToUpload(out uploadThisFile);

                if ((doUploadThisFile) && (null != uploadThisFile))
                {
                    //upload and finish
                    Trace.WriteLine("uploading (takes a while)");
                    SubmitTurnCommand submitTurncmd = this.m_MainViewModel.GMRMainViewModel.SubmitTurn;

                    submitTurncmd.Execute(new SubmitTurnCommandParam(guiGame.Game.GameId, m_Config.keepFilesInArchiveFolder, uploadThisFile));

                    SubmitTurnResult submitTurnResult = submitTurncmd.Result;

                    this.Invoke(new Action(() =>
                    {
                        MessageBox.Show("Result: " + submitTurnResult.ResultType.ToString() + " Points: " + submitTurnResult.PointsEarned.ToString());
                    }));
                }
            }));

            this.Invoke(new Action(() =>
            {
                this.FreezeUI(false);
                this.ResumeLayout(false);
                this.UpdateUI();

                Trace.TraceInformation("finished");
            }));
        }
コード例 #4
0
        private void AnyTurnButTheFirstOne(GuiGame guiGame)
        {
            Trace.WriteLine("starting...");

            Trace.WriteLine("downloading game (takes a while)");
            DownloadGame(guiGame);

            Trace.WriteLine("finished downloading game");

            this.Invoke(new Action(() =>
            {
                var dialogResult = MessageBox.Show("Launch Steam ?", "Launch Steam", MessageBoxButtons.YesNo);
                if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    Trace.WriteLine("launching steam (takes a while)");
                    this.m_MainViewModel.CoreMainViewModel.LaunchSteam.Execute();
                }
            }));

            this.Invoke(new Action(() =>
            {
                SubmitTurnCommand submitTurncmd  = this.m_MainViewModel.GMRMainViewModel.SubmitTurn;
                SubmitTurnCommandParam parameter = new SubmitTurnCommandParam(guiGame.Game.GameId, this.m_Config.keepFilesInArchiveFolder);

                var dialogResult = MessageBox.Show("Submit Turn ?", "Submit Turn", MessageBoxButtons.YesNo);
                if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    bool askTheUserAgainAndAgain = false;
                    do
                    {
                        if (submitTurncmd.CanExecute(parameter))
                        {
                            askTheUserAgainAndAgain = false;
                            Trace.WriteLine("submitting turn (takes a while)");

                            submitTurncmd.Execute(parameter);

                            SubmitTurnResult submitTurnResult = submitTurncmd.Result;

                            this.Invoke(new Action(() =>
                            {
                                MessageBox.Show("Result: " + submitTurnResult.ResultType.ToString() + " Points: " + submitTurnResult.PointsEarned.ToString());
                            }));
                        }
                        else
                        {
                            var resultuploadDialog  = MessageBox.Show("It is not possible to upload the file." + Environment.NewLine + "Did you overwrite your downloaded game ?", "I will not uploadthe game", MessageBoxButtons.RetryCancel);
                            askTheUserAgainAndAgain = resultuploadDialog == System.Windows.Forms.DialogResult.Retry;
                        }
                    }while(askTheUserAgainAndAgain);
                }
            }));

            this.Invoke(new Action(() =>
            {
                this.FreezeUI(false);
                this.ResumeLayout(false);
                this.UpdateUI();

                Trace.TraceInformation("finished");
            }));
        }