public void MergeFiles(BcfFile bcf) { var bcffiles = OpenBcfDialog(); if (bcffiles == null) { return; } bcf.MergeBcfFile(bcffiles); }
public void CloseFile(BcfFile bcf) { try { _bcfFiles.Remove(bcf); Utils.DeleteDirectory(bcf.TempPath); } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } }
private void BcfOpened(BcfFile newbcf) { if (newbcf != null) { BcfFiles.Add(newbcf); SelectedReportIndex = BcfFiles.Count - 1; if (newbcf.Issues.Any()) { newbcf.SelectedIssue = newbcf.Issues.First(); } } }
/// <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()); } }
/// <summary> /// Save BCF 1.0 as BCF 2.0 /// </summary> /// <param name="bcf1">BCF 1.0 file</param> public static void SaveBcf2FromBcf1(BCF bcf1) { try { BCF2.BcfFile bcf2 = new BCF2.BcfFile(); bcf2.TempPath = bcf1.path; // replace temp path with BCF 1.0's // bcf2.ProjectName = ; // from Jira? // bcf2.ProjectId = ; // from Jira? // Add issues (markups) foreach (IssueBCF bcf1Issue in bcf1.Issues) { // Convert header files List <BCF2.HeaderFile> bcf2Headers = new List <BCF2.HeaderFile>(); if (bcf1Issue.markup.Header != null) { foreach (HeaderFile bcf1Header in bcf1Issue.markup.Header) { bcf2Headers.Add(new BCF2.HeaderFile() { Date = bcf1Header.Date, Filename = bcf1Header.Filename, IfcProject = bcf1Header.IfcProject, IfcSpatialStructureElement = bcf1Header.IfcSpatialStructureElement, isExternal = true, // default true for now Reference = "" // default empty for now }); } } // Convert Comments ObservableCollection <BCF2.Comment> bcf2Comments = new ObservableCollection <BCF2.Comment>(); if (bcf1Issue.markup.Comment != null) { foreach (CommentBCF bcf1Comment in bcf1Issue.markup.Comment) { if (bcf1Comment != null) { bcf2Comments.Add(new BCF2.Comment() { Author = bcf1Comment.Author, Comment1 = bcf1Comment.Comment1, Date = bcf1Comment.Date, Guid = bcf1Comment.Guid, ModifiedAuthor = bcf1Comment.Author, // default the same as author for now //ModifiedDate = null, // mismatch attribute ReplyToComment = null, // mismatch attribute Status = bcf1Comment.Status.ToString(), Topic = new BCF2.CommentTopic() { Guid = bcf1Issue.markup.Topic.Guid }, // all referenced to markup's topic VerbalStatus = bcf1Comment.VerbalStatus, Viewpoint = null // mismatch attribute }); } } } // Convert Topic BCF2.Topic bcf2Topic = new BCF2.Topic() { AssignedTo = null, // mismatch attribute BimSnippet = null, // mismatch attribute CreationAuthor = null, // mismatch attribute //CreationDate = null, // mismatch attribute Description = null, // mismatch attribute DocumentReferences = null, // mismatch attribute Guid = bcf1Issue.markup.Topic.Guid, Index = null, // mismatch attribute Labels = null, // mismatch attribute ModifiedAuthor = null, // mismatch attribute //ModifiedDate = , // mismatch attribute Priority = null, // mismatch attribute ReferenceLink = bcf1Issue.markup.Topic.ReferenceLink, RelatedTopics = null, // mismatch attribute Title = bcf1Issue.markup.Topic.Title, TopicStatus = null, // mismatch attribute TopicType = null // mismatch attribute }; // Convert ClippingPlane List <BCF2.ClippingPlane> bcf2ClippingPlanes = new List <BCF2.ClippingPlane>(); if (bcf1Issue.viewpoint.ClippingPlanes != null) { foreach (ClippingPlane bcf1ClippingPlane in bcf1Issue.viewpoint.ClippingPlanes) { if (bcf1ClippingPlane != null) { bcf2ClippingPlanes.Add(new BCF2.ClippingPlane() { Direction = new BCF2.Direction() { X = bcf1ClippingPlane.Direction.X, Y = bcf1ClippingPlane.Direction.Y, Z = bcf1ClippingPlane.Direction.Z }, Location = new BCF2.Point() { X = bcf1ClippingPlane.Location.X, Y = bcf1ClippingPlane.Location.Y, Z = bcf1ClippingPlane.Location.Z } }); } } } // Convert Components List <BCF2.Component> bcf2Components = new List <BCF2.Component>(); if (bcf1Issue.viewpoint.Components != null) { foreach (Component bcf1Component in bcf1Issue.viewpoint.Components) { if (bcf1Component != null) { bcf2Components.Add(new BCF2.Component() { AuthoringToolId = bcf1Component.AuthoringToolId, // Color = bcf1Component, // mismatch attribute IfcGuid = bcf1Component.IfcGuid, OriginatingSystem = bcf1Component.OriginatingSystem // Selected = bcf1Component, // mismatch attribute // Visible = bcf1Component // mismatch attribute }); } } } // Convert Lines List <BCF2.Line> bcf2Lines = new List <BCF2.Line>(); if (bcf1Issue.viewpoint.Lines != null) { foreach (Line bcf1Line in bcf1Issue.viewpoint.Lines) { if (bcf1Line != null) { bcf2Lines.Add(new BCF2.Line() { StartPoint = new BCF2.Point() { X = bcf1Line.StartPoint.X, Y = bcf1Line.StartPoint.Y, Z = bcf1Line.StartPoint.Z }, EndPoint = new BCF2.Point() { X = bcf1Line.EndPoint.X, Y = bcf1Line.EndPoint.Y, Z = bcf1Line.EndPoint.Z } }); } } } // Convert VisualizationInfo BCF2.VisualizationInfo bcf2VizInfo = new BCF2.VisualizationInfo() { Bitmaps = null, // default null ClippingPlanes = bcf2ClippingPlanes.ToArray(), Components = bcf2Components, Lines = bcf2Lines.ToArray(), OrthogonalCamera = bcf1Issue.viewpoint.OrthogonalCamera == null ? null : new BCF2.OrthogonalCamera() { CameraDirection = new BCF2.Direction() { X = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.X, Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.Y, Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraDirection.Z }, CameraUpVector = new BCF2.Direction() { X = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.X, Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.Y, Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraUpVector.Z }, CameraViewPoint = new BCF2.Point() { X = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.X, Y = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.Y, Z = bcf1Issue.viewpoint.OrthogonalCamera.CameraViewPoint.Z }, ViewToWorldScale = bcf1Issue.viewpoint.OrthogonalCamera.ViewToWorldScale }, PerspectiveCamera = bcf1Issue.viewpoint.PerspectiveCamera == null ? null : new BCF2.PerspectiveCamera() { CameraDirection = new BCF2.Direction() { X = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.X, Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.Y, Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraDirection.Z }, CameraUpVector = new BCF2.Direction() { X = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.X, Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.Y, Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraUpVector.Z }, CameraViewPoint = new BCF2.Point() { X = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.X, Y = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.Y, Z = bcf1Issue.viewpoint.PerspectiveCamera.CameraViewPoint.Z }, FieldOfView = bcf1Issue.viewpoint.PerspectiveCamera.FieldOfView }, SheetCamera = bcf1Issue.viewpoint.SheetCamera == null ? null : new BCF2.SheetCamera() { SheetID = bcf1Issue.viewpoint.SheetCamera.SheetID, SheetName = null, // default null TopLeft = new BCF2.Point() { X = bcf1Issue.viewpoint.SheetCamera.TopLeft.X, Y = bcf1Issue.viewpoint.SheetCamera.TopLeft.Y, Z = bcf1Issue.viewpoint.SheetCamera.TopLeft.Z }, BottomRight = new BCF2.Point() { X = bcf1Issue.viewpoint.SheetCamera.BottomRight.X, Y = bcf1Issue.viewpoint.SheetCamera.BottomRight.Y, Z = bcf1Issue.viewpoint.SheetCamera.BottomRight.Z } } }; // Convert viewpoints // BCF 1.0 can only have one viewpoint ObservableCollection <BCF2.ViewPoint> bcf2ViewPoints = new ObservableCollection <BCF2.ViewPoint>(); bcf2ViewPoints.Add(new BCF2.ViewPoint() { //Guid = null, // no guid for viewpoint Snapshot = bcf1Issue.snapshot, Viewpoint = "viewpoint.bcfv", VisInfo = bcf2VizInfo }); // Add BCF 2.0 issues/markups bcf2.Issues.Add(new BCF2.Markup() { Header = bcf2Headers, Comment = bcf2Comments, Topic = bcf2Topic, Viewpoints = bcf2ViewPoints }); } // Save BCF 2.0 file BCF2.BcfContainer.SaveBcfFile(bcf2); bcf1.HasBeenSaved = true; } 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(); System.Windows.MessageBox.Show("Exception:" + line + "=====" + ex.ToString()); } }
public void SaveFile(BcfFile bcf) { SaveBcfFile(bcf); }
/// <summary> /// Serializes to a bcfzip and saves it to disk /// </summary> /// <param name="bcffile"></param> /// <returns></returns> public static bool SaveBcfFile(BcfFile bcffile) { try { if (bcffile.Issues.Count == 0) { MessageBox.Show("The current BCF Report is empty.", "No Issue", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!Directory.Exists(bcffile.TempPath)) { Directory.CreateDirectory(bcffile.TempPath); } // Show save file dialog box string name = !string.IsNullOrEmpty(bcffile.Filename) ? bcffile.Filename : "New BCF Report"; string filename = SaveBcfDialog(name); // Process save file dialog box results if (string.IsNullOrWhiteSpace(filename)) { return(false); } var bcfProject = new ProjectExtension { Project = new Project { Name = string.IsNullOrEmpty(bcffile.ProjectName) ? bcffile.Filename : bcffile.ProjectName, ProjectId = bcffile.ProjectId.Equals(Guid.Empty) ? Guid.NewGuid().ToString() : bcffile.ProjectId.ToString() }, ExtensionSchema = "" }; var bcfVersion = new Version { VersionId = "2.0", DetailedVersion = "2.0" }; var serializerP = new XmlSerializer(typeof(ProjectExtension)); Stream writerP = new FileStream(Path.Combine(bcffile.TempPath, "project.bcfp"), FileMode.Create); serializerP.Serialize(writerP, bcfProject); writerP.Close(); var serializerVers = new XmlSerializer(typeof(Version)); Stream writerVers = new FileStream(Path.Combine(bcffile.TempPath, "bcf.version"), FileMode.Create); serializerVers.Serialize(writerVers, bcfVersion); writerVers.Close(); var serializerV = new XmlSerializer(typeof(VisualizationInfo)); var serializerM = new XmlSerializer(typeof(Markup)); foreach (var issue in bcffile.Issues) { // Serialize the object, and close the TextWriter string issuePath = Path.Combine(bcffile.TempPath, issue.Topic.Guid); if (!Directory.Exists(issuePath)) { Directory.CreateDirectory(issuePath); } //BCF 1 compatibility //there needs to be a view whose viewpoint and snapshot are named as follows and not with a guid //uniqueness is still guarenteed by the guid field if (issue.Viewpoints != null) { if (issue.Viewpoints.Any() && (issue.Viewpoints.Count == 1 || issue.Viewpoints.All(o => o.Viewpoint != "viewpoint.bcfv"))) { if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint))) { File.Delete(Path.Combine(issuePath, issue.Viewpoints[0].Viewpoint)); } issue.Viewpoints[0].Viewpoint = "viewpoint.bcfv"; if (File.Exists(Path.Combine(issuePath, issue.Viewpoints[0].Snapshot))) { File.Move(Path.Combine(issuePath, issue.Viewpoints[0].Snapshot), Path.Combine(issuePath, "snapshot.png")); } issue.Viewpoints[0].Snapshot = "snapshot.png"; } } //serialize markup with updated content Stream writerM = new FileStream(Path.Combine(issuePath, "markup.bcf"), FileMode.Create); serializerM.Serialize(writerM, issue); writerM.Close(); //serialize views if (issue.Viewpoints != null) { foreach (var bcfViewpoint in issue.Viewpoints) { Stream writerV = new FileStream(Path.Combine(issuePath, bcfViewpoint.Viewpoint), FileMode.Create); serializerV.Serialize(writerV, bcfViewpoint.VisInfo); writerV.Close(); } } } //overwrite, without doubts if (File.Exists(filename)) { File.Delete(filename); } ZipFile.CreateFromDirectory(bcffile.TempPath, filename, CompressionLevel.Optimal, false); //Open browser at location Uri uri2 = new Uri(filename); string reportname = Path.GetFileName(uri2.LocalPath); if (File.Exists(filename)) { string argument = @"/select, " + filename; System.Diagnostics.Process.Start("explorer.exe", argument); } bcffile.HasBeenSaved = true; bcffile.Filename = reportname; } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } return(true); }
/// <summary> /// Logic that extracts files from a bcfzip and deserializes them /// </summary> /// <param name="bcfzipfile">Path to the .bcfzip file</param> /// <returns></returns> private static BcfFile OpenBcfFile(string bcfzipfile) { var bcffile = new BcfFile(); try { if (!File.Exists(bcfzipfile) || !String.Equals(Path.GetExtension(bcfzipfile), ".bcfzip", StringComparison.InvariantCultureIgnoreCase)) { return(bcffile); } bcffile.Filename = Path.GetFileNameWithoutExtension(bcfzipfile); bcffile.Fullname = bcfzipfile; using (ZipArchive archive = ZipFile.OpenRead(bcfzipfile)) { archive.ExtractToDirectory(bcffile.TempPath); } var dir = new DirectoryInfo(bcffile.TempPath); var projectFile = Path.Combine(bcffile.TempPath, "project.bcfp"); if (File.Exists(projectFile)) { var project = DeserializeProject(projectFile); var g = Guid.NewGuid(); Guid.TryParse(project.Project.ProjectId, out g); bcffile.ProjectId = g; } //ADD ISSUES FOR EACH SUBFOLDER foreach (var folder in dir.GetDirectories()) { //An issue needs at least the markup file var markupFile = Path.Combine(folder.FullName, "markup.bcf"); if (!File.Exists(markupFile)) { continue; } var bcfissue = DeserializeMarkup(markupFile); if (bcfissue == null) { continue; } //Is a BCF 2 file, has multiple viewpoints if (bcfissue.Viewpoints != null && bcfissue.Viewpoints.Any()) { foreach (var viewpoint in bcfissue.Viewpoints) { string viewpointpath = Path.Combine(folder.FullName, viewpoint.Viewpoint); if (File.Exists(viewpointpath)) { //deserializing the viewpoint into the issue viewpoint.VisInfo = DeserializeViewpoint(viewpointpath); viewpoint.SnapshotPath = Path.Combine(folder.FullName, viewpoint.Snapshot); } } } //Is a BCF 1 file, only one viewpoint //there is no Viewpoints tag in the markup //update it to BCF 2 else { bcfissue.Viewpoints = new ObservableCollection <ViewPoint>(); string viewpointFile = Path.Combine(folder.FullName, "viewpoint.bcfv"); if (File.Exists(viewpointFile)) { bcfissue.Viewpoints.Add(new ViewPoint(true) { VisInfo = DeserializeViewpoint(viewpointFile), SnapshotPath = Path.Combine(folder.FullName, "snapshot.png"), }); //update the comments foreach (var comment in bcfissue.Comment) { comment.Viewpoint = new CommentViewpoint(); comment.Viewpoint.Guid = bcfissue.Viewpoints.First().Guid; } } } bcfissue.Comment = new ObservableCollection <Comment>(bcfissue.Comment.OrderBy(x => x.Date)); //register the collectionchanged events, //it is needed since deserialization overwrites the ones set in the constructor bcfissue.RegisterEvents(); //ViewComment stuff bcffile.Issues.Add(bcfissue); } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } return(bcffile); }