コード例 #1
0
ファイル: MainForm.Async.cs プロジェクト: GrimMaple/mrHelper
        async private Task onLaunchDiffToolAsync()
        {
            GitClient client = getGitClient(_workflow.State.HostName, _workflow.State.Project.Path_With_Namespace);

            if (client != null)
            {
                enableControlsOnGitAsyncOperation(false);
                try
                {
                    // Using local checker because it does not make a GitLab request and it is quite enough here because
                    // user may select only those commits that already loaded and cached and have timestamps less
                    // than latest merge request version
                    await _gitClientUpdater.UpdateAsync(client,
                                                        _updateManager.GetLocalProjectChecker(_workflow.State.MergeRequest.Id), updateGitStatusText);
                }
                catch (Exception ex)
                {
                    if (ex is CancelledByUserException)
                    {
                        // User declined to create a repository
                        MessageBox.Show("Cannot launch a diff tool without up-to-date git repository", "Warning",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (!(ex is RepeatOperationException))
                    {
                        Debug.Assert(ex is ArgumentException || ex is GitOperationException);
                        ExceptionHandlers.Handle(ex, "Cannot initialize/update git repository");
                        MessageBox.Show("Cannot initialize git repository",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return;
                }
                finally
                {
                    enableControlsOnGitAsyncOperation(true);
                }
            }
            else
            {
                MessageBox.Show("Cannot launch a diff tool without up-to-date git repository", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (comboBoxLeftCommit.SelectedItem == null || comboBoxRightCommit.SelectedItem == null)
            {
                // State changed during async git client update
                return;
            }

            string leftSHA  = getGitTag(true /* left */);
            string rightSHA = getGitTag(false /* right */);

            labelWorkflowStatus.Text = "Launching diff tool...";

            int pid;

            try
            {
                pid = client.DiffTool(mrHelper.DiffTool.DiffToolIntegration.GitDiffToolName,
                                      leftSHA, rightSHA);
            }
            catch (GitOperationException ex)
            {
                string message = "Could not launch diff tool";
                ExceptionHandlers.Handle(ex, message);
                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                labelWorkflowStatus.Text = message;
                return;
            }

            labelWorkflowStatus.Text = "Diff tool launched";

            Trace.TraceInformation(String.Format("[MainForm] Launched DiffTool for SHA {0} vs SHA {1} (at {2}). PID {3}",
                                                 leftSHA, rightSHA, client.Path, pid.ToString()));

            saveInterprocessSnapshot(pid, leftSHA, rightSHA);
        }