Exemple #1
0
        async private Task showDiscussionsFormAsync()
        {
            GitClient client = getGitClient(_workflow.State.HostName, _workflow.State.Project.Path_With_Namespace);

            if (client != null)
            {
                enableControlsOnGitAsyncOperation(false);
                try
                {
                    // Using remote checker because there are might be discussions reported by other users on newer commits
                    await _gitClientUpdater.UpdateAsync(client,
                                                        _updateManager.GetRemoteProjectChecker(_workflow.State.MergeRequestDescriptor), updateGitStatusText);
                }
                catch (Exception ex)
                {
                    if (ex is RepeatOperationException)
                    {
                        return;
                    }
                    else if (ex is CancelledByUserException)
                    {
                        if (MessageBox.Show("Without up-to-date git repository, some context code snippets might be missing. "
                                            + "Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                            DialogResult.No)
                        {
                            return;
                        }
                        else
                        {
                            client = null;
                        }
                    }
                    else
                    {
                        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
            {
                if (MessageBox.Show("Without git repository, context code snippets will be missing. "
                                    + "Do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) ==
                    DialogResult.No)
                {
                    return;
                }
                else
                {
                    client = null;
                }
            }

            List <Discussion> discussions = await loadDiscussionsAsync();

            if (discussions == null)
            {
                return;
            }

            labelWorkflowStatus.Text = "Rendering Discussions Form...";
            labelWorkflowStatus.Update();

            DiscussionsForm form;

            try
            {
                form = new DiscussionsForm(_workflow.State.MergeRequestDescriptor, _workflow.State.MergeRequest.Title,
                                           _workflow.State.MergeRequest.Author, client, int.Parse(comboBoxDCDepth.Text), _colorScheme,
                                           discussions, _discussionManager, _workflow.State.CurrentUser,
                                           async(mrd) =>
                {
                    try
                    {
                        if (!getGitClient(mrd.HostName, mrd.ProjectName).DoesRequireClone())
                        {
                            // Using remote checker because there are might be discussions reported by other users on newer commits
                            await getGitClient(mrd.HostName, mrd.ProjectName).Updater.ManualUpdateAsync(
                                _updateManager.GetRemoteProjectChecker(_workflow.State.MergeRequestDescriptor), null);
                        }
                    }
                    catch (GitOperationException ex)
                    {
                        ExceptionHandlers.Handle(ex, "Cannot update git repository on refreshing discussions");
                    }
                });
            }
            catch (NoDiscussionsToShow)
            {
                MessageBox.Show("No discussions to show.", "Information",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                labelWorkflowStatus.Text = "No discussions to show";
                return;
            }
            catch (ArgumentException ex)
            {
                ExceptionHandlers.Handle(ex, "Cannot show Discussions form");
                MessageBox.Show("Cannot show Discussions form", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                labelWorkflowStatus.Text = "Cannot show Discussions";
                return;
            }

            labelWorkflowStatus.Text = "Discussions opened";

            Trace.TraceInformation(String.Format("[MainForm] Opened Discussions for MR IId {0} (at {1})",
                                                 _workflow.State.MergeRequestDescriptor.IId, (client?.Path ?? "null")));

            form.Show();
        }
        private void showDiscussionForm(GitLabInstance gitLabInstance, DataCache dataCache, ILocalCommitStorage storage,
                                        User currentUser, MergeRequestKey mrk, IEnumerable <Discussion> discussions, string title, User author)
        {
            if (currentUser == null || discussions == null || author == null)
            {
                return;
            }

            bool doesMatchTag(object tag) => tag != null && ((MergeRequestKey)(tag)).Equals(mrk);

            Form formExisting = findFormByTag("DiscussionsForm", doesMatchTag);

            if (formExisting != null)
            {
                formExisting.Activate();
                return;
            }

            labelWorkflowStatus.Text = "Rendering discussion contexts...";
            labelWorkflowStatus.Refresh();

            DiscussionsForm form;

            try
            {
                IAsyncGitCommandService git = storage?.Git;

                DiscussionsForm discussionsForm = new DiscussionsForm(dataCache, gitLabInstance, _modificationNotifier,
                                                                      git, currentUser, mrk, discussions, title, author, int.Parse(comboBoxDCDepth.Text), _colorScheme,
                                                                      async(key, discussionsUpdated) =>
                {
                    if (storage != null && storage.Updater != null)
                    {
                        try
                        {
                            await storage.Updater.StartUpdate(new DiscussionBasedContextProvider(discussionsUpdated),
                                                              status => onStorageUpdateProgressChange(status, mrk), () => onStorageUpdateStateChange());
                        }
                        catch (LocalCommitStorageUpdaterException ex)
                        {
                            ExceptionHandlers.Handle("Cannot update a storage on refreshing discussions", ex);
                        }
                    }
                    else
                    {
                        Trace.TraceInformation("[MainForm] User tried to refresh Discussions without a storage");
                        MessageBox.Show("Cannot update a storage, some context code snippets may be missing. ",
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                },
                                                                      () => dataCache?.DiscussionCache?.RequestUpdate(mrk, Constants.DiscussionCheckOnNewThreadInterval, null))
                {
                    Tag = mrk
                };
                form = discussionsForm;
            }
            catch (NoDiscussionsToShow)
            {
                MessageBox.Show("No discussions to show.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                labelWorkflowStatus.Text = "No discussions to show";
                return;
            }
            catch (ArgumentException ex)
            {
                string errorMessage = "Cannot show Discussions form";
                ExceptionHandlers.Handle(errorMessage, ex);
                MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                labelWorkflowStatus.Text = "Cannot show Discussions";
                return;
            }

            labelWorkflowStatus.Text = "Opening Discussions view...";
            labelWorkflowStatus.Refresh();

            Trace.TraceInformation(String.Format("[MainForm] Opened Discussions for MR IId {0} (at {1})",
                                                 mrk.IId, (storage?.Path ?? "null")));

            form.Show();

            labelWorkflowStatus.Text = "Discussions opened";
        }
Exemple #3
0
        private void showDiscussionForm(DataCache dataCache, ILocalCommitStorage storage, User currentUser,
                                        MergeRequestKey mrk, IEnumerable <Discussion> discussions, string title, User author, string webUrl,
                                        string customActionFileName)
        {
            if (currentUser == null || discussions == null || author == null || currentUser.Id == 0)
            {
                return;
            }

            bool doesMatchTag(object tag) => tag != null && ((MergeRequestKey)(tag)).Equals(mrk);

            Form formExisting = WinFormsHelpers.FindFormByTag("DiscussionsForm", doesMatchTag);

            if (formExisting is DiscussionsForm existingDiscussionsForm)
            {
                existingDiscussionsForm.Restore();
                Trace.TraceInformation(String.Format("[MainForm] Activated an existing Discussions view for MR {0}", mrk.IId));
                return;
            }

            addOperationRecord("Rendering discussion contexts has started");
            labelOperationStatus.Refresh();

            DiscussionsForm form;

            try
            {
                IAsyncGitCommandService git = storage?.Git;

                AsyncDiscussionLoader discussionLoader = new AsyncDiscussionLoader(mrk, dataCache,
                                                                                   async(key, discussionsUpdated) =>
                {
                    if (storage != null && storage.Updater != null)
                    {
                        try
                        {
                            await storage.Updater.StartUpdate(new DiscussionBasedContextProvider(discussionsUpdated),
                                                              status => onStorageUpdateProgressChange(status, mrk), () => onStorageUpdateStateChange());
                        }
                        catch (LocalCommitStorageUpdaterException ex)
                        {
                            ExceptionHandlers.Handle("Cannot update a storage on refreshing discussions", ex);
                        }
                    }
                    else
                    {
                        Trace.TraceInformation("[MainForm] User tried to refresh Discussions without a storage");
                        MessageBox.Show("Cannot update a storage, some context code snippets may be missing. ",
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }, this);

                AsyncDiscussionHelper discussionHelper = new AsyncDiscussionHelper(mrk, title, currentUser, _shortcuts);

                IEnumerable <ICommand> getCommands(ICommandCallback callback) =>
                loadCustomCommands(customActionFileName, callback);

                DiscussionsForm discussionsForm = new DiscussionsForm(
                    git, currentUser, mrk, discussions, title, author, _colorScheme,
                    discussionLoader, discussionHelper, webUrl, _shortcuts, getCommands)
                {
                    Tag = mrk
                };
                form = discussionsForm;
            }
            catch (NoDiscussionsToShow)
            {
                MessageBox.Show("No discussions to show.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Trace.TraceInformation(String.Format("[MainForm] No discussions to show for MR IID {0}", mrk.IId));
                addOperationRecord("No discussions to show");
                return;
            }

            addOperationRecord("Opening Discussions view has started");
            labelOperationStatus.Refresh();

            form.Show();

            Trace.TraceInformation(String.Format("[MainForm] Opened Discussions for MR IId {0} (at {1})",
                                                 mrk.IId, (storage?.Path ?? "null")));

            addOperationRecord("Discussions view has opened");
            ensureMergeRequestInRecentDataCache(mrk);
        }