public void ExceptionOnExternalReference() { var container = new BCFv2Container(); var docRef = new TopicDocumentReferences(); docRef.isExternal = true; Assert.Throws <ArgumentException>(() => { var data = container.GetAttachmentForDocumentReference(docRef); }); }
/// <summary> /// Returns the raw byte array of the attachment /// </summary> /// <param name="topicDocumentReference"></param> /// <returns></returns> public byte[] GetAttachmentForDocumentReference(TopicDocumentReferences topicDocumentReference) { if (topicDocumentReference.isExternal) { throw new ArgumentException("Reference is external"); } return(FileAttachments[GetFilenameFromReference(topicDocumentReference.ReferencedDocument)]); }
/// <summary> /// Organize raw data into BCFZIP class structure /// </summary> /// <param name="bcfzip"></param> /// <param name="tempVisInfoHolder"></param> /// <param name="tempFileContentHolder"></param> /// <param name="tempExtInfoHolder"></param> /// <returns></returns> private static BCFZIP MapContents(BCFZIP bcfzip, Dictionary <string, Dictionary <string, VisualizationInfo> > tempVisInfoHolder, Dictionary <string, Dictionary <string, byte[]> > tempFileContentHolder, Dictionary <string, Dictionary <string, ComponentExtensionInfo> > tempExtInfoHolder) { BCFZIP mappedBCF = null; try { Dictionary <string /*guid*/, RevitExtension> extensions = new Dictionary <string, RevitExtension>(); foreach (RevitExtension ext in bcfzip.ExtensionColor.Extensions) { if (!extensions.ContainsKey(ext.Guid)) { extensions.Add(ext.Guid, ext); } } for (int i = 0; i < bcfzip.Markups.Count; i++) { Markup markup = bcfzip.Markups[i]; string topicId = markup.Topic.Guid; //BimSnippet BimSnippet bimSnippet = markup.Topic.BimSnippet; if (!string.IsNullOrEmpty(bimSnippet.Reference) && !bimSnippet.isExternal) { if (tempFileContentHolder.ContainsKey(topicId)) { if (tempFileContentHolder[topicId].ContainsKey(bimSnippet.Reference)) { bimSnippet.FileContent = tempFileContentHolder[topicId][bimSnippet.Reference]; } } } bimSnippet.TopicGuid = topicId; markup.Topic.BimSnippet = bimSnippet; //DocumentReferences List <TopicDocumentReferences> docList = new List <TopicDocumentReferences>(); foreach (TopicDocumentReferences doc in markup.Topic.DocumentReferences) { TopicDocumentReferences docRef = doc; docRef.TopicGuid = topicId; if (!string.IsNullOrEmpty(docRef.ReferencedDocument) && !docRef.isExternal) { if (tempFileContentHolder.ContainsKey(topicId)) { if (tempFileContentHolder[topicId].ContainsKey(docRef.ReferencedDocument)) { docRef.FileContent = tempFileContentHolder[topicId][docRef.ReferencedDocument]; } } } docList.Add(docRef); } markup.Topic.DocumentReferences = docList; if (markup.Viewpoints.Count > 0) { ViewPoint firstViewpoint = markup.Viewpoints.First(); for (int j = 0; j < markup.Comment.Count; j++) { string viewPointGuid = markup.Comment[j].Viewpoint.Guid; if (string.IsNullOrEmpty(viewPointGuid)) { markup.Comment[j].Viewpoint.Guid = firstViewpoint.Guid; } } } //viewpoints for (int j = 0; j < markup.Viewpoints.Count; j++) { ViewPoint viewpoint = markup.Viewpoints[j]; //bitmap if (tempVisInfoHolder.ContainsKey(topicId)) { if (tempVisInfoHolder[topicId].ContainsKey(viewpoint.Viewpoint)) { VisualizationInfo visInfo = tempVisInfoHolder[topicId][viewpoint.Viewpoint]; visInfo.ViewPointGuid = viewpoint.Guid; List <VisualizationInfoBitmaps> bitmapList = new List <VisualizationInfoBitmaps>(); foreach (VisualizationInfoBitmaps bitmap in visInfo.Bitmaps) { VisualizationInfoBitmaps visBitmap = bitmap; if (!string.IsNullOrEmpty(bitmap.Reference)) { if (tempFileContentHolder.ContainsKey(topicId)) { if (tempFileContentHolder[topicId].ContainsKey(bitmap.Reference)) { visBitmap.BitmapImage = tempFileContentHolder[topicId][bitmap.Reference]; } } } visBitmap.ViewPointGuid = viewpoint.Guid; bitmapList.Add(visBitmap); } visInfo.Bitmaps = bitmapList; string viewpointExt = viewpoint.Viewpoint.Replace(".bcfv", ".bcfvx"); if (tempExtInfoHolder.ContainsKey(topicId)) { if (tempExtInfoHolder[topicId].ContainsKey(viewpointExt)) { ComponentExtensionInfo extInfo = tempExtInfoHolder[topicId][viewpointExt]; if (visInfo.Components.Count > 0) { foreach (ComponentExtension compExt in extInfo.Extensions) { var compFound = from comp in visInfo.Components where comp.IfcGuid == compExt.IfcGuid select comp; if (compFound.Count() > 0) { int compIndex = visInfo.Components.IndexOf(compFound.First()); visInfo.Components[compIndex].ElementName = compExt.ElementName; visInfo.Components[compIndex].Action = (extensions.ContainsKey(compExt.ActionGuid)) ? extensions[compExt.ActionGuid] : new RevitExtension(); visInfo.Components[compIndex].Responsibility = (extensions.ContainsKey(compExt.ResponsibilityGuid)) ? extensions[compExt.ResponsibilityGuid] : new RevitExtension(); } } } } } markup.Viewpoints[j].VisInfo = visInfo; } } //snapshot if (tempFileContentHolder.ContainsKey(topicId)) { if (tempFileContentHolder[topicId].ContainsKey(viewpoint.Snapshot)) { markup.Viewpoints[j].SnapshotImage = tempFileContentHolder[topicId][viewpoint.Snapshot]; if (null == markup.TopicImage && null != markup.Viewpoints[j].SnapshotImage) { markup.TopicImage = markup.Viewpoints[j].SnapshotImage; } } } } if (markup.Viewpoints.Count > 0) { markup.SelectedViewpoint = markup.Viewpoints.First(); } bcfzip.Markups[i] = markup; } mappedBCF = bcfzip; } catch (Exception ex) { MessageBox.Show("Failed to create maps from BCF contents.\n" + ex.Message, "Mapping BCF Contents", MessageBoxButton.OK, MessageBoxImage.Warning); } return(mappedBCF); }