//................................................................................................. public void ToSql(string ServerName, string DatabaseName = "ifcSQL_instance", eWriteMode WriteMode = eWriteMode.CreateNewProject, int ProjectId = 0) { ENTITY.ifcSqlInstance = new ifcSQL._ifcSQL_for_ifcSQL_instance(ServerName: ServerName, DatabaseName: DatabaseName); ifcSQL._ifcSQL_for_ifcSQL_instance ifcSQL = ENTITY.ifcSqlInstance; long LastGlobalId = 0; ifcSQL.conn.Open(); if (WriteMode == eWriteMode.CreateNewProject) { ifcSQL.ExecuteNonQuery("app.NewProject '" + Header.name + "'"); ProjectId = 0; } if (ProjectId == 0) { ProjectId = ifcSQL.ExecuteIntegerScalar("SELECT cp.ProjectId()"); } else { ifcSQL.ExecuteNonQuery("app.SelectProject " + ProjectId); } int EntityCount = ifcSQL.ExecuteIntegerScalar("SELECT count(*) from cp.Entity"); if (WriteMode == eWriteMode.OnlyIfEmpty) { if (EntityCount > 0) { ifcSQL.conn.Close(); throw new NetSystem.Exception("Project with ProjectId=" + ProjectId + " is not empty while using eWriteMode.OnlyIfEmpty"); } } if (WriteMode == eWriteMode.DeleteBeforeWrite) { ifcSQL.ExecuteNonQuery("app.DeleteProjectEntities " + ProjectId); } ifcSQL.ExecuteNonQuery("ifcProject.NewLastGlobalId " + ProjectId + ", " + ifc.Repository.CurrentModel.EntityList.Count); LastGlobalId = ifcSQL.ExecuteLongScalar("SELECT ifcProject.LastGlobalId(" + ProjectId + ")"); ifcSQL.conn.Close(); long CurrentGlobalId = LastGlobalId - ifc.Repository.CurrentModel.EntityList.Count; FillTables(ProjectId: ProjectId, StartGlobalId: LastGlobalId - ifc.Repository.CurrentModel.EntityList.Count + 1); ifcSQL.conn.Open(); foreach (TableBase tb in OrderedInsertList) { if (tb.Count > 0) { tb.BulkInsert(); } } ifcSQL.conn.Close(); }//................................................................................................
public static Model FromSql(string ServerName, string DatabaseName = "ifcSQL_Instance", int ProjectId = 0) { ifcSQL._ifcSQL_for_ifcSQL_instance ifcSQLin = new ifcSQL._ifcSQL_for_ifcSQL_instance(ServerName: ServerName, DatabaseName: DatabaseName); ifcSQLin.conn.Open(); if (ProjectId > 0) { ifcSQLin.ExecuteNonQuery("app.SelectProject " + ProjectId); } ifcSQLin.conn.Close(); ifcSQLin.LoadAllTables(); Dictionary <long, ifcSQL.ifcInstance.Entity_Row> Entity_RowDict = new Dictionary <long, ifcSQL.ifcInstance.Entity_Row>(); foreach (ifcSQL.ifcInstance.Entity_Row e in ifcSQLin.cp.Entity) { e.AttributeValueDict = new Dictionary <int, RowBase>(); Entity_RowDict.Add(e.GlobalEntityInstanceId, e); } ifc.ENTITY.TypeDictionary.FillEntityTypeComponentsDict(); // fill Type Dict foreach (ifcSQL.ifcInstance.EntityAttributeOfString_Row a in ifcSQLin.cp.EntityAttributeOfString) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); } foreach (ifcSQL.ifcInstance.EntityAttributeOfVector_Row a in ifcSQLin.cp.EntityAttributeOfVector) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); } foreach (ifcSQL.ifcInstance.EntityAttributeOfBinary_Row a in ifcSQLin.cp.EntityAttributeOfBinary) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); } foreach (ifcSQL.ifcInstance.EntityAttributeOfBoolean_Row a in ifcSQLin.cp.EntityAttributeOfBoolean) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); } foreach (ifcSQL.ifcInstance.EntityAttributeOfEntityRef_Row a in ifcSQLin.cp.EntityAttributeOfEntityRef) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); } foreach (ifcSQL.ifcInstance.EntityAttributeOfEnum_Row a in ifcSQLin.cp.EntityAttributeOfEnum) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); } foreach (ifcSQL.ifcInstance.EntityAttributeOfFloat_Row a in ifcSQLin.cp.EntityAttributeOfFloat) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); } foreach (ifcSQL.ifcInstance.EntityAttributeOfInteger_Row a in ifcSQLin.cp.EntityAttributeOfInteger) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); } foreach (ifcSQL.ifcInstance.EntityAttributeOfList_Row a in ifcSQLin.cp.EntityAttributeOfList) { Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict.Add(a.OrdinalPosition, a); a.AttributeValueDict = new Dictionary <int, RowBase>(); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfEntityRef_Row a in ifcSQLin.cp.EntityAttributeListElementOfEntityRef) { ((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]).AttributeValueDict.Add(a.ListDim1Position, a); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfBinary_Row a in ifcSQLin.cp.EntityAttributeListElementOfBinary) { ((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]).AttributeValueDict.Add(a.ListDim1Position, a); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfFloat_Row a in ifcSQLin.cp.EntityAttributeListElementOfFloat) { ((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]).AttributeValueDict.Add(a.ListDim1Position, a); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfInteger_Row a in ifcSQLin.cp.EntityAttributeListElementOfInteger) { ((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]).AttributeValueDict.Add(a.ListDim1Position, a); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfString_Row a in ifcSQLin.cp.EntityAttributeListElementOfString) { ((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]).AttributeValueDict.Add(a.ListDim1Position, a); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfList_Row a in ifcSQLin.cp.EntityAttributeListElementOfList) { ifcSQL.ifcInstance.EntityAttributeOfList_Row lr = ((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]); lr.AttributeValueDict.Add(a.ListDim1Position, a); a.AttributeValueDict = new Dictionary <int, RowBase>(); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfListElementOfEntityRef_Row a in ifcSQLin.cp.EntityAttributeListElementOfListElementOfEntityRef) { ((ifcSQL.ifcInstance.EntityAttributeListElementOfList_Row)((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]).AttributeValueDict[a.ListDim1Position]).AttributeValueDict.Add(a.ListDim2Position, a); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfListElementOfFloat_Row a in ifcSQLin.cp.EntityAttributeListElementOfListElementOfFloat) { ((ifcSQL.ifcInstance.EntityAttributeListElementOfList_Row)((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]).AttributeValueDict[a.ListDim1Position]).AttributeValueDict.Add(a.ListDim2Position, a); } foreach (ifcSQL.ifcInstance.EntityAttributeListElementOfListElementOfInteger_Row a in ifcSQLin.cp.EntityAttributeListElementOfListElementOfInteger) { ((ifcSQL.ifcInstance.EntityAttributeListElementOfList_Row)((ifcSQL.ifcInstance.EntityAttributeOfList_Row)Entity_RowDict[a.GlobalEntityInstanceId].AttributeValueDict[a.OrdinalPosition]).AttributeValueDict[a.ListDim1Position]).AttributeValueDict.Add(a.ListDim2Position, a); } ifcSQL.ifcProject.Project_Row CurrentProJect = (ifcSQL.ifcProject.Project_Row)ifcSQLin.cp.Project[0]; Model NewModel = new Model(); foreach (ifcSQL.ifcProject.EntityInstanceIdAssignment_Row eia in ifcSQLin.cp.EntityInstanceIdAssignment) { NewModel.LocalIdFromGlobalIdDict[eia.GlobalEntityInstanceId] = (int)eia.ProjectEntityInstanceId; // create and fill LocalGlobal Dict } NewModel.Header.Init(name: CurrentProJect.ProjectName, description: CurrentProJect.ProjectDescription, author: "Bernhard Simon Bock, Friedrich Eder", preprocessor_version: "IfcSharp"); foreach (ifcSQL.ifcInstance.Entity_Row e in ifcSQLin.cp.Entity) { NewModel.EvalIfcRow(e); } NewModel.AssignEntities(); return(NewModel); } // of FromSql