// // Checks we're authenticated against the Jira server // private static Simple CheckJiraServerAuthentication(Form owner) { // Get our server string jiraServer = Names.Url[(int)Names.Type.Jira]; // Check our credentials s_logger.Log(@"Checking Jira credentials against {0}", jiraServer); if (Credentials.Available(jiraServer) == false) { // Kick off the request s_logger.Log(@"Jira credentials not found for {0}", jiraServer); owner.Invoke((MethodInvoker) delegate { DialogResult dialogResult = MessageBox.Show(owner, "You must be authenticated with the Jira server before generating review statistics.\n\nDo you want to authenticate now?", "Authentication Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { RB_Tools.Shared.Authentication.Targets.Jira.Authenticate(s_logger); } }); // Check if we're still unauthenticated s_logger.Log(@"Jira authentication completed"); if (Credentials.Available(jiraServer) == false) { s_logger.Log(@"Jira authentication still not present"); return(null); } } // We're good s_logger.Log(@"Creating Jira credentials object for {0}", jiraServer); return(Credentials.Create(jiraServer, s_logger) as Simple); }
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(); }
// // Starts a review // private void button_CreateReview_Click(object sender, EventArgs e) { // We need a sumary before we raise the review if (string.IsNullOrWhiteSpace(textBox_Summary.Text) == true) { MessageBox.Show(this, "You need to provide a summary before you can post a review", "Unable to post review", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Do we need a Jira ticket? if (Settings.Settings.Default.JiraRequired == true) { if (string.IsNullOrWhiteSpace(textBox_JiraId.Text) == true) { MessageBox.Show(this, "You need to provide a Jira ticket before you can continue", "Unable to post review", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } // Only bother checking against the reviewboard server if we are doing a review RB_Tools.Shared.Review.Properties.Level reviewLevel = (RB_Tools.Shared.Review.Properties.Level)comboBox_ReviewLevel.SelectedIndex; if (reviewLevel == RB_Tools.Shared.Review.Properties.Level.FullReview) { 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 generating a review.\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; } } } // Check Jira authentication if needed if (string.IsNullOrWhiteSpace(textBox_JiraId.Text) == false) { string jiraServer = Names.Url[(int)Names.Type.Jira]; if (Credentials.Available(jiraServer) == false) { m_logger.Log("Requesting Jira credentials"); DialogResult dialogResult = MessageBox.Show(this, "You must be authenticated with the Jira server before continuing.\n\nDo you want to authenticate now?", "Authentication Error", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { RB_Tools.Shared.Authentication.Targets.Jira.Authenticate(m_logger); } // Check if we're still unauthenticated if (Credentials.Available(jiraServer) == false) { m_logger.Log("Credentials still unavailable"); return; } } } // Save the state of our review groups SaveSelectedReviewGroups(); // Update our state UpdateCreateReviewDialogState(State.PostReview); // Do we need to keep our artifacts? if (checkBox_KeepArtifacts.Checked == true) { Utilities.Storage.KeepAssets(textBox_Summary.Text, m_logger); } Utilities.Storage.Keep(m_originalRequest, "Original File List.txt", false, m_logger); // Build up the list of review groups List <string> selectedReviewGroups = new List <string>(); foreach (int thisIndex in checkedListBox_ReviewGroups.CheckedIndices) { Reviewboard.ReviewGroup thisGroup = m_reviewGroups[thisIndex]; selectedReviewGroups.Add(thisGroup.InternalName); } // Build up the properties of this review Review.Review.Properties reviewProperties = new Review.Review.Properties( m_requestDirectory, m_reviewSource, textBox_ReviewId.Text, textBox_Summary.Text, textBox_Description.Text, textBox_Testing.Text, textBox_JiraId.Text.Trim().Replace(" ", ""), selectedReviewGroups, reviewLevel, checkBox_CopiesAsAdds.Checked ); // Trigger the correct state depending on whether we are reviewing TriggerReviewRequest(reviewProperties); }