Пример #1
0
        private void button_RefreshGroups_Click(object sender, EventArgs e)
        {
            // Before we do anything, we need to be authenticated
            string reviewboardServer = Names.Url[(int)Names.Type.Reviewboard];

            if (Credentials.Available(reviewboardServer) == false)
            {
                m_logger.Log("Requesting Reviewboard credentials");

                DialogResult dialogResult = MessageBox.Show(this, "You must be authenticated with the Reviewboard server before refreshing the review groups.\n\nDo you want to authenticate now?", "Authentication Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    RB_Tools.Shared.Authentication.Targets.Reviewboard.Authenticate(m_logger);
                }

                // Check if we're still unauthenticated
                if (Credentials.Available(reviewboardServer) == false)
                {
                    m_logger.Log("Credentials still unavailable");
                    return;
                }
            }

            // Turn off the buttons and lock the settings
            UpdateCreateReviewDialogState(State.RefreshGroups);

            // Lose everything in the box
            checkedListBox_ReviewGroups.Items.Clear();
            m_reviewGroups = new Reviewboard.ReviewGroup[0];

            Settings.Settings.Default.Selected = string.Empty;
            Settings.Settings.Default.Groups   = string.Empty;

            Settings.Settings.Default.Save();

            // Build up the background work
            BackgroundWorker updateThread = new BackgroundWorker();

            // Called when we need to trigger the request
            updateThread.DoWork += (object objectSender, DoWorkEventArgs args) =>
            {
                m_logger.Log("Starting group refresh");

                // Get our credentials
                Simple credentials = Credentials.Create(reviewboardServer, m_logger) as Simple;
                if (credentials == null)
                {
                    throw new FileNotFoundException(@"Unable to find the credentials for " + reviewboardServer);
                }

                // Get the groups
                Reviewboard.ReviewGroup[] result = Reviewboard.GetReviewGroups(m_requestDirectory, credentials.Server, credentials.User, credentials.Password, m_logger);

                // Save the result
                args.Result = result;
            };
            // Called when the thread is complete
            updateThread.RunWorkerCompleted += (object objectSender, RunWorkerCompletedEventArgs args) =>
            {
                // Check if we had an error
                if (args.Error != null)
                {
                    m_logger.Log("Error raised when updating review groups - {0}", args.Error.Message);
                    string body = string.Format("Exception thrown when trying to retrive the review groups\n\nException: {0}\n\nDescription: {1}", args.Error.GetType().Name, args.Error.Message);

                    // Was it an authentication error?
                    bool authenticationRequired = false;
                    if (args.Error.Message.Contains("username or password was not correct") == true)
                    {
                        authenticationRequired = true;
                        body += "\n\nDo you want to attempt to reauthenticate with the server?";
                    }

                    // Show the options
                    MessageBoxButtons buttonTypes = (authenticationRequired == true ? MessageBoxButtons.YesNo : MessageBoxButtons.OK);
                    DialogResult      result      = MessageBox.Show(this, body, @"Unable to update group list", buttonTypes, MessageBoxIcon.Error);

                    // Continue?
                    if (result == DialogResult.Yes && authenticationRequired == true)
                    {
                        RB_Tools.Shared.Authentication.Targets.Reviewboard.Authenticate(m_logger);
                    }
                }
                else
                {
                    m_logger.Log("Review groups successfully updated");

                    // Update the list
                    m_reviewGroups = args.Result as Reviewboard.ReviewGroup[];
                    UpdateSelectedReviewGroups(null);

                    // Save the groups we have returned
                    string groupsJson = JsonConvert.SerializeObject(m_reviewGroups);
                    Settings.Settings.Default.Groups = groupsJson;
                    Settings.Settings.Default.Save();
                }

                // Set the button state back
                UpdateCreateReviewDialogState(State.Idle);
            };

            // Kick off the request
            updateThread.RunWorkerAsync();
        }
Пример #2
0
        //
        // Validates the Jira ticket if needed
        //
        bool ValidateJiraTicket(string jiraId)
        {
            // If we have no ticker, we're fine
            if (string.IsNullOrEmpty(jiraId) == true)
            {
                return(true);
            }

            // Get our credentials
            string serverName  = Names.Url[(int)Names.Type.Jira];
            Simple credentials = Credentials.Create(serverName, m_logger) as Simple;

            if (credentials == null)
            {
                m_logger.Log("Unable to create credentials for '{0}'", serverName);
                throw new FileNotFoundException(@"Unable to find the credentials for " + serverName);
            }

            // Split out ticket IDs so we validate them all
            string[] jiras = jiraId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            if (jiras == null || jiras.Length == 0)
            {
                jiras = new string[] { jiraId }
            }
            ;

            // Validate the ticker
            foreach (string thisTicket in jiras)
            {
                string ticketToCheck = thisTicket.Trim();
                bool   tickerValid   = RB_Tools.Shared.Targets.Jira.ValidateJiraTicker(credentials, ticketToCheck).Result;
                if (tickerValid == false)
                {
                    string message = string.Format("Unable to find ticket '{0}' on {1}", jiraId, serverName);

                    m_logger.Log(message);
                    throw new InvalidOperationException(message);
                }
            }

            // We're done
            return(true);
        }

        //
        // Requests a new review
        //
        object RequestReview(ReviewRequestProperties thisRequest)
        {
            if (thisRequest.ReviewProperties.ReviewLevel == RB_Tools.Shared.Review.Properties.Level.FullReview)
            {
                // Get our credentials
                string serverName  = Names.Url[(int)Names.Type.Reviewboard];
                Simple credentials = Credentials.Create(serverName, m_logger) as Simple;
                if (credentials == null)
                {
                    m_logger.Log("Unable to create credentials for '{0}'", serverName);
                    throw new FileNotFoundException(@"Unable to find the credentials for " + serverName);
                }

                // Request the review
                m_logger.Log("Requesting review");
                Reviewboard.ReviewRequestResult result = Reviewboard.RequestReview(
                    thisRequest.WorkingCopy,
                    credentials.Server,
                    credentials.User,
                    credentials.Password,
                    thisRequest.ReviewProperties,
                    m_logger);

                // Save the result
                m_logger.Log("Review request finished");
                return(result);
            }
            else
            {
                // Save the result
                m_logger.Log("Review request skipped as a review is not being carried out");
                return(new Reviewboard.ReviewRequestResult(null, null, thisRequest.ReviewProperties));
            }
        }