/// <summary> /// Get the file directory/location /// </summary> /// <param name="ifcDocumentReference">Document Reference Object</param> /// <returns>string</returns> private string GetFileDirectory(IIfcDocumentReference ifcDocumentReference) { if (ifcDocumentReference == null) { return(null); } if (!string.IsNullOrEmpty(ifcDocumentReference.Location)) { return(ifcDocumentReference.Location); } return(null); }
/// <summary> /// Convert a IfcDocumentReference to Document /// </summary> /// <param name="docReference">Document Reference Object</param> /// <param name="docInformation"></param> /// <returns>Document</returns> private CobieDocument ConvertToDocument(IIfcDocumentReference docReference, IIfcDocumentInformation docInformation) { var name = GetName(docInformation) ?? GetName(docReference); //fail to get from IfcDocumentReference, so try assign a default if (string.IsNullOrEmpty(name)) { name = "Document"; } //check for duplicates, if found add a (#) => "DocName(1)", if none return name unchanged name = Helper.GetNextName(name, UsedNames); var document = Exchanger.TargetRepository.Instances.New <CobieDocument>(); document.Name = name; document.Created = docInformation != null?GetCreatedInfo(docInformation) : null; document.DocumentType = (docInformation != null) && !string.IsNullOrEmpty(docInformation.Purpose) ? Helper.GetPickValue <CobieDocumentType>(docInformation.Purpose) : null; document.ApprovalType = (docInformation != null) && (!string.IsNullOrEmpty(docInformation.IntendedUse)) ? Helper.GetPickValue <CobieApprovalType>(docInformation.IntendedUse) : null; //once fixed document.Stage = (docInformation != null) && (!string.IsNullOrEmpty(docInformation.Scope)) ? Helper.GetPickValue <CobieStageType>(docInformation.Scope) : null; document.Directory = GetFileDirectory(docReference); document.File = GetFileName(docReference); document.ExternalSystem = null; document.ExternalObject = Helper.GetExternalObject(docReference); document.ExternalId = null; document.Description = (docInformation != null) && !string.IsNullOrEmpty(docInformation.Description) ? docInformation.Description.ToString() : null; document.Reference = docInformation != null ? docInformation.Identification : null; UsedNames.Add(document.Name); return(document); }
/// <summary> /// Get Name from IfcDocumentReference /// </summary> /// <param name="ifcDocumentReference">Document Reference Object</param> /// <returns>string or null</returns> private string GetName(IIfcDocumentReference ifcDocumentReference) { if (ifcDocumentReference == null) { return(null); } if (!string.IsNullOrEmpty(ifcDocumentReference.Name)) { return(ifcDocumentReference.Name); } if (!string.IsNullOrEmpty(ifcDocumentReference.Location)) { return(Path.GetFileNameWithoutExtension(ifcDocumentReference.Location)); } //we ignore ItemReference, "which refers to a system interpretable position within the document" from http://www.buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifcexternalreferenceresource/lexical/ifcdocumentreference.htm return(null); }
/// <summary> /// Convert a IfcDocumentReference to Document /// </summary> /// <param name="ifcDocumentReference">Document Reference Object</param> /// <param name="document">Document Object</param> /// <returns>Document</returns> private Document ConvertToDocument(IIfcDocumentReference ifcDocumentReference, IIfcDocumentInformation ifcDocumentInformation) { string name = GetName(ifcDocumentInformation) ?? GetName(ifcDocumentReference); //fail to get from IfcDocumentReference, so try assign a default if (string.IsNullOrEmpty(name)) { name = "Document"; } //check for duplicates, if found add a (#) => "DocName(1)", if none return name unchanged name = Helper.GetNextName(name, UsedNames); var document = new Document(); document.Name = name; document.CreatedBy = ifcDocumentInformation != null?GetCreatedBy(ifcDocumentInformation) : null; document.CreatedOn = ifcDocumentInformation != null?GetCreatedOn(ifcDocumentInformation) : null; document.Categories = (ifcDocumentInformation != null) && (!string.IsNullOrEmpty(ifcDocumentInformation.Purpose)) ? new List <Category>(new[] { new Category { Code = ifcDocumentInformation.Purpose } }) : null; document.ApprovalBy = (ifcDocumentInformation != null) && (!string.IsNullOrEmpty(ifcDocumentInformation.IntendedUse)) ? ifcDocumentInformation.IntendedUse : null; //once fixed document.Stage = (ifcDocumentInformation != null) && (!string.IsNullOrEmpty(ifcDocumentInformation.Scope)) ? ifcDocumentInformation.Scope : null; document.Directory = GetFileDirectory(ifcDocumentReference); document.File = GetFileName(ifcDocumentReference); document.ExternalSystem = null; document.ExternalEntity = ifcDocumentReference.GetType().Name; document.ExternalId = null; document.Description = (ifcDocumentInformation != null) && (!string.IsNullOrEmpty(ifcDocumentInformation.Description)) ? ifcDocumentInformation.Description.ToString() : null; document.Reference = ifcDocumentInformation.Identification; UsedNames.Add(document.Name); return(document); }
/// <summary> /// Get file name /// </summary> /// <param name="ifcDocumentReference">Document Reference Object</param> /// <returns>string</returns> private string GetFileName(IIfcDocumentReference ifcDocumentReference) { if (ifcDocumentReference == null) { return(null); } if (!string.IsNullOrEmpty(ifcDocumentReference.Name)) { return(ifcDocumentReference.Name); } if (!string.IsNullOrEmpty(ifcDocumentReference.Location)) { try { return(Path.GetFileName(ifcDocumentReference.Location)); } catch (Exception) //if exception just return the stored string { return(ifcDocumentReference.Location); } } return(null); }