/// <summary> /// Serializes to a bcfzip and saves it to disk /// </summary> /// <param name="bcffile"></param> /// <returns></returns> private 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 Bcf2.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(Bcf2.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.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 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; }
public void MergeFiles(BcfFile bcf) { var bcffiles = OpenBcfDialog(); if (bcffiles == null) return; bcf.MergeBcfFile(bcffiles); }
private bool CheckSaveBcf(BcfFile bcf) { try { if (BcfTabControl.SelectedIndex != -1 && bcf != null && !bcf.HasBeenSaved && bcf.Issues.Any()) { MessageBoxResult answer = MessageBox.Show(bcf.Filename + " has been modified.\nDo you want to save changes?", "Save Report?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Cancel); if (answer == MessageBoxResult.Yes) { _bcf.SaveFile(bcf); return false; } if (answer == MessageBoxResult.Cancel) { return false; } } } catch (System.Exception ex1) { MessageBox.Show("exception: " + ex1); } return true; }
private void BcfOpened(BcfFile newbcf) { if (newbcf != null) { BcfFiles.Add(newbcf); SelectedReportIndex = BcfFiles.Count - 1; if (newbcf.Issues.Any()) { newbcf.SelectedIssue = newbcf.Issues.First(); } foreach (var issue in newbcf.Issues) { if (!Globals.OpenStatuses.Contains(issue.Topic.TopicStatus)) { Globals.OpenStatuses.Add(issue.Topic.TopicStatus); } if (!Globals.OpenTypes.Contains(issue.Topic.TopicType)) { Globals.OpenTypes.Add(issue.Topic.TopicType); } } } }
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(); } } }
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> /// 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; }
public void SaveFile(BcfFile bcf) { SaveBcfFile(bcf); }
/// <summary> /// Serializes to a bcfzip and saves it to disk /// </summary> /// <param name="bcffile"></param> /// <returns></returns> private 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 Project(); var bcfVersion = new Bcf2.Version { VersionId = "2.0", DetailedVersion = "2.0" }; var serializerP = new XmlSerializer(typeof(Project)); Stream writerP = new FileStream(Path.Combine(bcffile.TempPath, "project.bcfp"), FileMode.Create); serializerP.Serialize(writerP, bcfProject); writerP.Close(); var serializerVers = new XmlSerializer(typeof(Bcf2.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.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 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.Fastest, 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) || Path.GetExtension(bcfzipfile) != ".bcfzip") { 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); //ADD ISSUES FOR EACH SUBFOLDER foreach (var folder in dir.GetDirectories()) { //An issue needs at least the markup file if (!File.Exists(Path.Combine(folder.FullName, "markup.bcf"))) { continue; } var bcfissue = DeserializeMarkup(Path.Combine(folder.FullName, "markup.bcf")); 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 viewpointpath = Path.Combine(folder.FullName, "viewpoint.bcfv"); if (File.Exists(viewpointpath)) { bcfissue.Viewpoints.Add(new ViewPoint(true) { VisInfo = DeserializeViewpoint(viewpointpath), 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); }
/// <summary> /// Serializes to a bcfzip and saves it to disk /// </summary> /// <param name="bcffile"></param> /// <returns></returns> private 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 Bcf2.Version { VersionId = "2.1", DetailedVersion = "2.1" }; 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(Bcf2.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)); var i = 0; foreach (var issue in bcffile.Issues) { //set topic index issue.Topic.Index = i; issue.Topic.IndexSpecified = true; i++; // serialize the object, and close the TextWriter string issuePath = Path.Combine(bcffile.TempPath, issue.Topic.Guid); if (!Directory.Exists(issuePath)) { Directory.CreateDirectory(issuePath); } //set viewpoint index for (var l = 0; l < issue.Viewpoints.Count; l++) { issue.Viewpoints[l].Index = l; issue.Viewpoints[l].IndexSpecified = true; } //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.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 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); } //added encoder to address backslashes issue #11 //issue: https://github.com/teocomi/BCFier/issues/11 //ref: http://stackoverflow.com/questions/27289115/system-io-compression-zipfile-net-4-5-output-zip-in-not-suitable-for-linux-mac ZipFile.CreateFromDirectory(bcffile.TempPath, filename, CompressionLevel.Optimal, false, new ZipEncoder()); //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); }