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 Browse1_Click(object sender, RoutedEventArgs e) { // Displays an OpenFileDialog so the user can select a Cursor. OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "BCF Files|*.bcf|BCF Files|*.bcfzip"; dlg.Title = "Open Bcf file"; if (dlg.ShowDialog() == true) { byte[] fileBytes = File.ReadAllBytes(dlg.FileName); fileName.Text = dlg.FileName; BcfFile curFile = new BcfFile(fileBytes); ResultItems = new ObservableCollection <Markup>(curFile.markups.Values); DataContext = this; // (new BcfFile(fileBytes)).markups; /* * if (bcfFile != null) * { * //Set markups to interface * foreach (KeyValuePair<string, Markup> entry in bcfFile.markups) * { * issuesList.Items.Add(entry.Value); * } * } */ } }
public void ReadExample1() { Assert.IsTrue(File.Exists(@"Resources\Bcf21\Example1.bcfzip")); var example1 = BcfFile.ReadFrom(@"Resources\Bcf21\Example1.bcfzip"); Assert.IsNotNull(example1); var issues = example1.Issues.ToArray(); Assert.IsNotNull(issues); Assert.AreEqual(16, issues.Length); Assert.IsTrue(issues.All(i => null != i.Markup.Topic && 0 < i.Viewpoints.Length)); }
private void ServiceSetupForm_Load(object sender, EventArgs e) { // Fill active services resultList.Items.Clear(); Entity ent = uiDoc.Document.ProjectInformation.GetEntity(RevitBimbot.Schema); if (ent != null) { IList <Entity> services = ent.Get <IList <Entity> >("services"); foreach (Entity service in services) { if (service.Get <String>("resultType").Equals("bcf")) { BcfFile bcf = new BcfFile(Convert.FromBase64String(service.Get <String>("resultData"))); if (bcf != null) { //Set markups to interface foreach (KeyValuePair <string, Markup> entry in bcf.markups) { ListViewItem item = resultList.Items.Add(entry.Value.Topic.Title); item.SubItems.Add(service.Get <String>("srvcName")); item.SubItems.Add(service.Get <String>("resultDate")); item.SubItems.Add(service.Get <String>("resultType")); item.Tag = entry.Value; } } } else { ListViewItem item = resultList.Items.Add(service.Get <String>("srvcName")); item.SubItems.Add(service.Get <String>("srvcName")); item.SubItems.Add(service.Get <String>("resultDate")); item.SubItems.Add(service.Get <String>("resultType")); item.Tag = service.Get <String>("resultData"); } //resultList.Columns[1].Width = 0; //resultList.Columns[2].Width = 0; //resultList.Columns[3].Width = 0; //resultList.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); } } }
public void ReadExample2() { Assert.IsTrue(File.Exists(@"Resources\Bcf21\Example2.bcfzip")); var example2 = BcfFile.ReadFrom(@"Resources\Bcf21\Example2.bcfzip"); Assert.IsNotNull(example2); var issues = example2.Issues.ToArray(); Assert.IsNotNull(issues); Assert.AreEqual(2, issues.Length); Assert.IsTrue(issues.All(i => null != i.Markup.Topic)); Assert.AreEqual(1, issues.Count(i => i.Viewpoints.Length == 0)); var extensions = example2.Extensions; Assert.AreEqual(6, extensions.Count); Assert.AreEqual(3, extensions.First(e => e.Key == "TopicType").Count()); }
/// <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; }
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); }
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); } }
public void Load(BcfFile file) { _vm.File = file; }
/// <summary> /// Main Command Entry Point /// </summary> /// <param name="commandData"></param> /// <param name="message"></param> /// <param name="elements"></param> /// <returns></returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; BcfContainer bcfContainer = new BcfContainer(); BcfFile bcfFile = new BcfFile(); IList <Reference> selectedIssues = uidoc.Selection.PickObjects(ObjectType.Element, "Select issues"); //Get the UI view UIView uiview = null; IList <UIView> uiviews = uidoc.GetOpenUIViews(); foreach (UIView uv in uiviews) { if (uv.ViewId.Equals(doc.ActiveView.Id)) { uiview = uv; break; } } using (Transaction t = new Transaction(doc, "Export selected issues")) { t.Start(); //Isolate the objects to select them easily. Reset the temporary view mode before exporting the images uidoc.ActiveView.DisableTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate); foreach (Reference item in selectedIssues) { Element issueElement = doc.GetElement(item); string checkStatus = issueElement.LookupParameter("Status").AsValueString(); string checkPosition = issueElement.LookupParameter("Position Check").AsString(); Markup issue = new Markup(DateTime.Now); Topic tp = new Topic(); tp.Title = issueElement.Name; tp.Description = checkStatus; issue.Topic = tp; var view = new ViewPoint(issue.Viewpoints.Any()); if (!Directory.Exists(Path.Combine(bcfFile.TempPath, issue.Topic.Guid))) { Directory.CreateDirectory(Path.Combine(bcfFile.TempPath, issue.Topic.Guid)); } var c = new Comment { Comment1 = checkPosition, Author = Utils.GetUsername(), //Status = comboStatuses.SelectedValue.ToString(), //VerbalStatus = VerbalStatus.Text, Date = DateTime.Now, Viewpoint = new CommentViewpoint { Guid = view.Guid } }; issue.Comment.Add(c); // Zoom to the selected element uidoc.ShowElements(item.ElementId); SetViewZoomExtent(uiview, 1.2); string path = Path.Combine(bcfFile.TempPath, issue.Topic.Guid, view.Snapshot); // Export image SaveRevitSnapshot(uidoc.Document, path); view.SnapshotPath = path; issue.Viewpoints.Add(view); issue.Viewpoints.Last().VisInfo = Data.RevitView.GenerateViewpoint(uiapp.ActiveUIDocument); if (uidoc.Document.Title != null) { issue.Header[0].Filename = uidoc.Document.Title; } else { issue.Header[0].Filename = "Unknown"; } bcfFile.Issues.Add(issue); } t.Commit(); } bcfContainer.SaveFile(bcfFile); return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Result.Failed); } }