protected override IfcConstructionProductResource Mapping(Spare spare, IfcConstructionProductResource ifcConstructionProductResource) { ifcConstructionProductResource.Name = spare.Name; Exchanger.SetUserHistory(ifcConstructionProductResource, spare.ExternalSystem, (spare.CreatedBy == null) ? null : spare.CreatedBy.Email, (spare.CreatedOn == null) ? DateTime.Now : (DateTime)spare.CreatedOn); //using statement will set the Model.OwnerHistoryAddObject to IfcConstructionProductResource.OwnerHistory as OwnerHistoryAddObject is used to reset user history on any property changes, //then swaps the original OwnerHistoryAddObject back in the dispose, so set any properties within the using statement to keep user history set in line above SetUserHistory using (OwnerHistoryEditScope context = new OwnerHistoryEditScope(Exchanger.TargetRepository, ifcConstructionProductResource.OwnerHistory)) { #region Categories if (spare.Categories != null) { foreach (var category in spare.Categories) { Exchanger.ConvertCategoryToClassification(category, ifcConstructionProductResource); } } #endregion #region suppliers if (spare.Suppliers != null) { var emails = string.Join(":", spare.Suppliers.Select(s => s.Email)); if (!string.IsNullOrEmpty(emails)) { Exchanger.TryCreatePropertySingleValue(ifcConstructionProductResource, emails, "SpareSuppliers"); } } #endregion //description ifcConstructionProductResource.Description = spare.Description; //SetNumber Exchanger.TryCreatePropertySingleValue(ifcConstructionProductResource, spare.SetNumber, "SpareSetNumber"); //PartNumber Exchanger.TryCreatePropertySingleValue(ifcConstructionProductResource, spare.PartNumber, "SparePartNumber"); } return(ifcConstructionProductResource); }
protected override IfcBuilding Mapping(Facility facility, IfcBuilding ifcBuilding) { #region Properties ifcBuilding.Name = facility.Name; ifcBuilding.Description = facility.Description; ifcBuilding.CompositionType = IfcElementCompositionEnum.ELEMENT; #endregion #region Default units Exchanger.DefaultLinearUnit = new IfcUnitConverter(facility.LinearUnits.ToString()); Exchanger.DefaultAreaUnit = new IfcUnitConverter(facility.AreaUnits.ToString()); Exchanger.DefaultVolumeUnit = new IfcUnitConverter(facility.VolumeUnits.ToString()); Exchanger.DefaultCurrencyUnit = facility.CurrencyUnit; #endregion #region Contacts if (facility.Contacts != null && facility.Contacts.Any()) { var ContactMapping = Exchanger.GetOrCreateMappings <MappingContactToIfcPersonAndOrganization>(); foreach (var contact in facility.Contacts) { IfcPersonAndOrganization ifcPersonAndOrganization = ContactMapping.AddMapping(contact, ContactMapping.GetOrCreateTargetObject(contact.ExternalId)); //assign relationship //create IfcActor to set CreatedBy and CreatedOn for next time ifc is imported as IfcActor is derived from IfcRoot IfcActor actor = Exchanger.TargetRepository.Instances.New <IfcActor>(); Exchanger.SetUserHistory(actor, contact.ExternalSystem, (contact.CreatedBy == null) ? null : contact.CreatedBy.Email, (contact.CreatedOn == null) ? DateTime.Now : (DateTime)contact.CreatedOn); using (OwnerHistoryEditScope context = new OwnerHistoryEditScope(Exchanger.TargetRepository, actor.OwnerHistory)) { actor.TheActor = ifcPersonAndOrganization; } //assign the actor to the building IfcRelAssignsToActor ifcRelAssignsToActor = Exchanger.TargetRepository.Instances.New <IfcRelAssignsToActor>(); Exchanger.SetUserHistory(ifcRelAssignsToActor, contact.ExternalSystem, (contact.CreatedBy == null) ? null : contact.CreatedBy.Email, (contact.CreatedOn == null) ? DateTime.Now : (DateTime)contact.CreatedOn); using (OwnerHistoryEditScope context = new OwnerHistoryEditScope(Exchanger.TargetRepository, ifcRelAssignsToActor.OwnerHistory)) { ifcRelAssignsToActor.RelatingActor = actor; ifcRelAssignsToActor.RelatedObjects.Add(ifcBuilding); } } } #endregion #region Categories if (facility.Categories != null) { foreach (var category in facility.Categories) { Exchanger.ConvertCategoryToClassification(category, ifcBuilding); } } #endregion #region Project //COBie does nor require a project but Ifc does var ifcProject = Exchanger.TargetRepository.Instances.OfType <IfcProject>().FirstOrDefault(); if (ifcProject == null) { ifcProject = Exchanger.TargetRepository.Instances.New <IfcProject>(); } var projectMapping = Exchanger.GetOrCreateMappings <MappingProjectToIfcProject>(); projectMapping.AddMapping(facility.Project, ifcProject); InitialiseUnits(ifcProject); #endregion #region Site //add the relationship between the site and the building if a site exists if (facility.Site != null) { var siteMapping = Exchanger.GetOrCreateMappings <MappingSiteToIfcSite>(); var ifcSite = siteMapping.AddMapping(facility.Site, siteMapping.GetOrCreateTargetObject(facility.Site.ExternalId ?? Guid.NewGuid().ToString())); //add the relationship between the site and the project and the building ifcProject.AddSite(ifcSite); ifcSite.AddBuilding(ifcBuilding); } else //relate the building to the project { ifcProject.AddBuilding(ifcBuilding); } #endregion #region Floors //write out the floors if we have any if (facility.Floors != null) { var floorMapping = Exchanger.GetOrCreateMappings <MappingFloorToIfcBuildingStorey>(); foreach (var floor in facility.Floors) { var ifcFloor = floorMapping.AddMapping(floor, floorMapping.GetOrCreateTargetObject(floor.ExternalId)); ifcBuilding.AddToSpatialDecomposition(ifcFloor); } } #endregion #region AssetTypes //write out the floors if we have any if (facility.AssetTypes != null) { var assetTypeMapping = Exchanger.GetOrCreateMappings <MappingAssetTypeToIfcTypeObject>(); foreach (var assetType in facility.AssetTypes.OrderBy(a => a.ExternalEntity)) { Exchanger.BeginAssetTypeInfoType(); assetTypeMapping.AddMapping(assetType, assetTypeMapping.GetOrCreateTargetObject(assetType.ExternalId)); Exchanger.EndAssetTypeInfoType(); } } #endregion #region Attributes if (facility.Attributes != null) { foreach (var attribute in facility.Attributes) { Exchanger.ConvertAttributeTypeToIfcObjectProperty(ifcBuilding, attribute); } } #endregion #region Zones if (facility.Zones != null) { var zoneTypeMapping = Exchanger.GetOrCreateMappings <MappingZoneToIfcZone>(); foreach (var zone in facility.Zones) { zoneTypeMapping.AddMapping(zone, zoneTypeMapping.GetOrCreateTargetObject(zone.ExternalId)); } } #endregion #region Documents if (facility.Documents != null && facility.Documents.Any()) { Exchanger.ConvertDocumentsToDocumentSelect(ifcBuilding, facility.Documents); } #endregion #region Add Space Geometry CreateSpaceProxies(); #endregion return(ifcBuilding); }