コード例 #1
0
        public void Handle(MatchInfo matchInfo, Snapshot snapshot)
        {
            FileNameMatcher   fileNameMatcher   = getFileNameMatcher(_git, getMergeRequestKey(snapshot));
            LineNumberMatcher lineNumberMatcher = new LineNumberMatcher(_git);

            DiffPosition position = new DiffPosition(null, null, null, null, snapshot.Refs);

            try
            {
                if (!fileNameMatcher.Match(matchInfo, position, out position))
                {
                    return;
                }

                lineNumberMatcher.Match(matchInfo, position, out position);
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException || ex is MatchingException)
                {
                    ExceptionHandlers.Handle("Cannot create DiffPosition", ex);
                    MessageBox.Show("Cannot create a discussion. Unexpected file name and/or line number passed",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                    return;
                }
                throw;
            }

            NewDiscussionForm form = new NewDiscussionForm(
                matchInfo.LeftFileName, matchInfo.RightFileName, position, _git,
                async(body, includeContext) =>
            {
                try
                {
                    await submitDiscussionAsync(matchInfo, snapshot, position, body, includeContext);
                    _onDiscussionSubmitted?.Invoke(getMergeRequestKey(snapshot));
                }
                catch (DiscussionCreatorException ex)
                {
                    string message = "Cannot create a discussion at GitLab";
                    ExceptionHandlers.Handle(message, ex);
                    MessageBox.Show(String.Format("{0}. Check your connection and try again.", message),
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                                    MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                }
            });

            form.Show();
        }
コード例 #2
0
        private MatchResult matchLineNumber(string leftPath, string rightPath, Core.Matching.DiffRefs refs,
                                            int lineNumber, bool isLeftSideLine, out string leftLineNumber, out string rightLineNumber)
        {
            leftLineNumber = rightLineNumber = null;
            LineNumberMatcher matcher = new LineNumberMatcher(_git);

            try
            {
                matcher.Match(refs, leftPath, rightPath, lineNumber, isLeftSideLine, out leftLineNumber, out rightLineNumber);
                return(MatchResult.Success);
            }
            catch (ArgumentException ex)
            {
                ExceptionHandlers.Handle("Cannot create DiffPosition", ex);
            }
            catch (MatchingException ex)
            {
                ExceptionHandlers.Handle("Cannot create DiffPosition", ex);
            }
            return(MatchResult.Error);
        }