/// <summary>
        /// Get the related object information for the document
        /// </summary>
        /// <param name="ifcRelAssociatesDocument">IfcRelAssociatesDocument object</param>
        /// <returns>RelatedObjectInformation structure</returns>
        private RelatedObjectInformation GetRelatedObjectInformation(IfcRelAssociatesDocument ifcRelAssociatesDocument)
        {
            RelatedObjectInformation objectInfo = new RelatedObjectInformation {
                SheetName = DEFAULT_STRING, Name = DEFAULT_STRING, ExtIdentifier = DEFAULT_STRING, ExtObject = DEFAULT_STRING, CreatedBy = DEFAULT_STRING, CreatedOn = DEFAULT_STRING, ExtSystem = DEFAULT_STRING
            };

            if (ifcRelAssociatesDocument != null)
            {
                IfcRoot relatedObject = ifcRelAssociatesDocument.RelatedObjects.FirstOrDefault();
                if (relatedObject != null)
                {
                    string value = GetSheetByObjectType(relatedObject.GetType());

                    if (!string.IsNullOrEmpty(value))
                    {
                        objectInfo.SheetName = value;
                    }
                    value = relatedObject.Name.ToString();
                    if (!string.IsNullOrEmpty(value))
                    {
                        objectInfo.Name = value;
                    }
                    objectInfo.ExtObject     = relatedObject.GetType().Name;
                    objectInfo.ExtIdentifier = ifcRelAssociatesDocument.GlobalId;
                    objectInfo.ExtSystem     = GetExternalSystem(ifcRelAssociatesDocument.OwnerHistory);

                    objectInfo.CreatedBy = GetTelecomEmailAddress(ifcRelAssociatesDocument.OwnerHistory);
                    objectInfo.CreatedOn = GetCreatedOnDateAsFmtString(ifcRelAssociatesDocument.OwnerHistory);
                }
            }
            return(objectInfo);
        }
        /// <summary>
        /// Fill sheet rows for Document sheet
        /// </summary>
        /// <returns>COBieSheet</returns>
        public override COBieSheet <COBieDocumentRow> Fill()
        {
            ProgressIndicator.ReportMessage("Starting Documents...");
            var ifcProject = Model.Instances.FirstOrDefault <IIfcProject>();

            Debug.Assert(ifcProject != null);

            //create new sheet
            COBieSheet <COBieDocumentRow> documents = new COBieSheet <COBieDocumentRow>(Constants.WORKSHEET_DOCUMENT);

            // get all IfcBuildingStory objects from IFC file
            IEnumerable <IfcDocumentInformation> docInfos = Model.FederatedInstances.OfType <IfcDocumentInformation>();

            ProgressIndicator.Initialise("Creating Documents", docInfos.Count());

            foreach (IfcDocumentInformation di in docInfos)
            {
                ProgressIndicator.IncrementAndUpdate();

                COBieDocumentRow doc = new COBieDocumentRow(documents);


                doc.Name = (di == null) ? "" : di.Name.ToString();
                //get the first associated document to extract the objects the document refers to
                IfcRelAssociatesDocument ifcRelAssociatesDocument = DocumentInformationForObjects(di).FirstOrDefault();


                if ((ifcRelAssociatesDocument != null) && (ifcRelAssociatesDocument.OwnerHistory != null))
                {
                    doc.CreatedBy = GetTelecomEmailAddress(ifcRelAssociatesDocument.OwnerHistory);
                }
                else if (di.DocumentOwner != null)
                {
                    if (di.DocumentOwner is IfcPersonAndOrganization)
                    {
                        doc.CreatedBy = GetTelecomEmailAddress(di.DocumentOwner as IfcPersonAndOrganization);
                    }
                    else if (di.DocumentOwner is IfcPerson)
                    {
                        doc.CreatedBy = GetEmail(null, di.DocumentOwner as IfcPerson);
                    }
                    else if (di.DocumentOwner is IfcOrganization)
                    {
                        doc.CreatedBy = GetEmail(di.DocumentOwner as IfcOrganization, null);
                    }
                }
                else if (ifcProject.OwnerHistory != null)
                {
                    doc.CreatedBy = GetTelecomEmailAddress(ifcProject.OwnerHistory);
                }


                if ((ifcRelAssociatesDocument != null) && (ifcRelAssociatesDocument.OwnerHistory != null))
                {
                    doc.CreatedOn = GetCreatedOnDateAsFmtString(ifcRelAssociatesDocument.OwnerHistory);
                }
                else if (di.CreationTime != null)
                {
                    doc.CreatedOn = di.CreationTime.ToString();
                }
                else if (ifcProject.OwnerHistory != null)
                {
                    doc.CreatedOn = Context.RunDateTime;
                }


                doc.Category = (string.IsNullOrEmpty(di.Purpose.ToString())) ? DEFAULT_STRING :di.Purpose.ToString();

                doc.ApprovalBy = (string.IsNullOrEmpty(di.IntendedUse.ToString())) ? DEFAULT_STRING : di.IntendedUse.ToString();
                doc.Stage      = (string.IsNullOrEmpty(di.Scope.ToString())) ? DEFAULT_STRING : di.Scope.ToString();


                RelatedObjectInformation relatedObjectInfo = GetRelatedObjectInformation(ifcRelAssociatesDocument);
                doc.SheetName     = relatedObjectInfo.SheetName;
                doc.RowName       = relatedObjectInfo.Name;
                doc.ExtObject     = relatedObjectInfo.ExtObject;
                doc.ExtIdentifier = relatedObjectInfo.ExtIdentifier;
                doc.ExtSystem     = relatedObjectInfo.ExtSystem;

                if (ifcRelAssociatesDocument != null)
                {
                    FileInformation fileInfo = GetFileInformation(ifcRelAssociatesDocument);
                    doc.File      = fileInfo.Name;
                    doc.Directory = GetDirectory(!string.IsNullOrWhiteSpace(fileInfo.Location) ? fileInfo.Location : fileInfo.Name);
                }

                doc.Description = (string.IsNullOrEmpty(di.Description)) ? DEFAULT_STRING : di.Description.ToString();
                doc.Reference   = (string.IsNullOrEmpty(di.DocumentId.Value.ToString())) ? DEFAULT_STRING : di.DocumentId.Value.ToString();

                documents.AddRow(doc);
            }

            documents.OrderBy(s => s.Name);

            ProgressIndicator.Finalise();
            return(documents);
        }