private void SubmitButton_Click(object sender, RoutedEventArgs e) { Settings settings = Settings.Default; MantisData data = MantisService.Data; Session session = MantisService.MantisSession; // Validating if (ProjectComboBox.SelectedItem == null || CategoryComboBox.SelectedItem == null || PriorityComboBox.SelectedItem == null || EtaComboBox.SelectedItem == null || SeverityComboBox.SelectedItem == null || ReproducibilityComboBox.SelectedItem == null || String.IsNullOrEmpty(SummaryTextBox.Text) || String.IsNullOrEmpty(DescriptionTextBox.Text)) { MessageBox.Show("You must fill every required fields.", App.Current.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Stop); return; } // Get issue properties int? issueId = null; string summary = SummaryTextBox.Text; string project = (string)ProjectComboBox.SelectedItem; string severity = (string)SeverityComboBox.SelectedItem; string priority = (string)PriorityComboBox.SelectedItem; string reproducibility = (string)ReproducibilityComboBox.SelectedItem; string eta = (string)EtaComboBox.SelectedItem; string category = (string)CategoryComboBox.SelectedItem; string productVersion = (string)ProductVersionComboBox.SelectedItem; string targetVersion = (string)TargetVersionComboBox.SelectedItem; string description = DescriptionTextBox.Text; string comment = CommentTextBox.Text; string assignedToString = (string)AssignedToComboBox.SelectedItem; User assignedTo; if (String.IsNullOrEmpty(assignedToString)) assignedTo = new User { Id = 0, Name = "", Email = "", RealName = "" }; else assignedTo = data.Users[project].Single(w => w.Name == (string)AssignedToComboBox.SelectedItem); Controls.Attachment[] attachments = Attachments.Items.OfType<Controls.Attachment>().ToArray(); // Set last properties settings.LastProject = project; settings.LastCategory = category; settings.LastProductVersion = productVersion; settings.LastTargetVersion = targetVersion; settings.LastSeverity = severity; settings.LastReproducibility = reproducibility; settings.Save(); // Clear form fields SummaryTextBox.Text = ""; DescriptionTextBox.Text = ""; CommentTextBox.Text = ""; Attachments.ClearWithAnimation(); BackgroundWorkerService.EnqueueTask("Submitting issue", (param) => { Issue issue = new Issue(); issue.Summary = summary; issue.Project = new ObjectRef(project); issue.Priority = new ObjectRef(priority); issue.Severity = new ObjectRef(severity); issue.Reproducibility = new ObjectRef(reproducibility); issue.Eta = new ObjectRef(eta); issue.Category = new ObjectRef(category); issue.ProductVersion = productVersion; issue.TargetVersion = targetVersion; issue.Description = description; issue.AssignedTo = assignedTo; issue.ReportedBy = new User { Name = session.Username, }; issueId = session.Request.IssueAdd(issue); }); BackgroundWorkerService.EnqueueTask("Submitting issue note", (param) => { if (!String.IsNullOrEmpty(comment) && issueId.HasValue) { IssueNote issueNote = new IssueNote(); issueNote.Author = new User { Name = session.Username, }; issueNote.Text = comment; session.Request.IssueNoteAdd(issueId.Value, issueNote); } }); foreach (Controls.Attachment attachment in attachments) { BackgroundWorkerService.EnqueueTask("Submitting " + attachment.FileName, attachment, (param) => { Controls.Attachment currentAttachment = (Controls.Attachment)param; if (issueId.HasValue) { session.Request.IssueAddFile(issueId.Value, currentAttachment.FileName, "application/octet-stream", currentAttachment.Data); } }); } }
/// <summary> /// Validates an issue note and raises an exception if it is not valid. /// </summary> /// <param name="note">The note to be validated</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentOutOfRangeException"></exception> private static void ValidateIssueNote(IssueNote note) { if (note == null) throw new ArgumentNullException("note"); if (note.Text == null) throw new ArgumentNullException("note.Text"); if (note.Text.Trim().Length == 0) throw new ArgumentOutOfRangeException("note"); }
/// <summary> /// /// </summary> /// <param name="notes"></param> /// <returns></returns> internal static MantisConnectWebservice.IssueNoteData[] ConvertArrayToWebservice(IssueNote[] notes) { if (notes == null) return null; MantisConnectWebservice.IssueNoteData[] notesForWebservice = new MantisConnectWebservice.IssueNoteData[notes.Length]; int i = 0; foreach (IssueNote note in notes) notesForWebservice[i++] = note.ToWebservice(); return notesForWebservice; }
/// <summary> /// Adds a note to the specified issue. /// </summary> /// <param name="issueId">Issue id to add note to.</param> /// <param name="note">The note to add</param> /// <remarks> /// The user must have write access to the issue and the issue must not be readonly. /// </remarks> /// <returns></returns> /// <exception cref="ArgumentNullException">Note is null</exception> /// <exception cref="ArgumentOutOfRangeException">The issue id is 0 or negative. Or note is empty or blank.</exception> public int IssueNoteAdd(int issueId, IssueNote note) { ValidateIssueId(issueId); ValidateIssueNote(note); return Convert.ToInt32(mc.mc_issue_note_add(session.Username, session.Password, issueId.ToString(CultureInfo.InvariantCulture), note.ToWebservice())); }
/// <summary> /// /// </summary> /// <param name="issueNotesData"></param> /// <returns></returns> internal static IssueNote[] ConvertArray(MantisConnectWebservice.IssueNoteData[] issueNotesData) { if (issueNotesData == null) return null; IssueNote[] notes = new IssueNote[issueNotesData.Length]; for (int i = 0; i < issueNotesData.Length; ++i) notes[i] = new IssueNote(issueNotesData[i]); return notes; }