/// <summary> /// Save Jira issues as BCF 2.0 /// </summary> /// <param name="jiraPan"></param> public static void SaveBcf2FromJira(UserControls.MainPanel mainPan) { try { BCF2.BcfFile bcf2 = new BCF2.BcfFile(); string ReportFolder = Path.Combine(Path.GetTempPath(), "BCFtemp", Path.GetRandomFileName()); bcf2.TempPath = ReportFolder; bcf2.ProjectName = ((Project)(mainPan.jiraPan.projCombo.SelectedItem)).name; //bcf2.ProjectId = ; // Is there a guid for a Jira project? int errors = 0; // Add issues (markups) foreach (object t in mainPan.jiraPan.issueList.SelectedItems) { int index = mainPan.jiraPan.issueList.Items.IndexOf(t); Issue issue = mainPan.jira.IssuesCollection[index]; if (issue.viewpoint == "" || issue.snapshotFull == "") { errors++; continue; } // Create temp. folder string issueGuid = issue.fields.guid; if (!Directory.Exists(Path.Combine(ReportFolder, issueGuid))) Directory.CreateDirectory(Path.Combine(ReportFolder, issueGuid)); // Convert header files List<BCF2.HeaderFile> bcf2Headers = new List<BCF2.HeaderFile>(); bcf2Headers.Add(new BCF2.HeaderFile() { Date = issue.fields.created == null ? new DateTime() : DateTime.Parse(issue.fields.created), Filename = "Jira Export " + DateTime.Now.ToShortDateString().Replace("/", "-"), isExternal = true, // default true for now Reference = "" // default empty for now }); // Convert Comments ObservableCollection<BCF2.Comment> bcf2Comments = new ObservableCollection<BCF2.Comment>(); foreach (var comm in issue.fields.comment.comments) { if (comm != null) { bcf2Comments.Add(new BCF2.Comment() { Author = comm.author == null ? null : comm.author.displayName, Comment1 = comm.body == null ? null : comm.body, Date = comm.created == null ? new DateTime() : DateTime.Parse(comm.created), Guid = Guid.NewGuid().ToString(), ModifiedAuthor = comm.updateAuthor == null ? null : comm.updateAuthor.displayName, ModifiedDate = comm.updated == null ? new DateTime() : DateTime.Parse(comm.updated), ReplyToComment = null, // default null Status = "Unknown", Topic = new BCF2.CommentTopic() { Guid = issueGuid }, // all referenced to markup's topic VerbalStatus = issue.fields.status == null ? null : issue.fields.status.name, Viewpoint = null }); } } // Convert Topic BCF2.Topic bcf2Topic = new BCF2.Topic() { AssignedTo = issue.fields.assignee == null ? null : issue.fields.assignee.displayName, BimSnippet = null, CreationAuthor = issue.fields.creator == null ? null : issue.fields.creator.displayName, CreationDate = issue.fields.created == null ? new DateTime() : DateTime.Parse(issue.fields.created), Description = issue.fields.description == null ? null : issue.fields.description, DocumentReferences = null, Guid = issueGuid, Index = null, Labels = null, ModifiedAuthor = null, ModifiedDate = issue.fields.updated == null ? new DateTime() : DateTime.Parse(issue.fields.updated), Priority = issue.fields.priority == null ? null : issue.fields.priority.name, ReferenceLink = null, RelatedTopics = null, Title = issue.fields.summary == null ? null : issue.fields.summary, TopicStatus = issue.fields.status == null ? null : issue.fields.status.name, TopicType = issue.fields.issuetype == null ? null : issue.fields.issuetype.name }; // Add BCF 2.0 issues/markups bcf2.Issues.Add(new BCF2.Markup() { Header = bcf2Headers, Comment = bcf2Comments, Topic = bcf2Topic, // Viewpoints = bcf2ViewPoints // use the one saved on Jira }); // Save viewpoint and snapshot try { mainPan.saveSnapshotViewpoint(issue.viewpoint, Path.Combine(ReportFolder, issueGuid, "viewpoint.bcfv")); mainPan.saveSnapshotViewpoint(issue.snapshotFull, Path.Combine(ReportFolder, issueGuid, "snapshot.png")); } catch (Exception ex) { MessageBox.Show("Failed to download viewpoint.bcfv and snapshot.png on Jira", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } } if (errors != 0) { MessageBox.Show(errors + " Issue/s were not exported because not formatted correctly.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); if (errors == mainPan.jiraPan.issueList.SelectedItems.Count) { mainPan.DeleteDirectory(ReportFolder); return; } } // Save BCF 2.0 file BCF2.BcfContainer.SaveBcfFile(bcf2); } catch (Exception ex) { // Get stack trace for the exception with source file information var st = new System.Diagnostics.StackTrace(ex, true); // Get the top stack frame var frame = st.GetFrame(0); // Get the line number from the stack frame var line = frame.GetFileLineNumber(); MessageBox.Show("Exception:" + line + "=====" + ex.ToString()); } }