//WS: attached an instance of a class to element. If already exists, delete it and re-attach. private void AttachInstanceAndValues(BCOM.Element oEle, string strClassName, GeoTagDataBase oGeoTagData) { //WS: create an empty class instance. ECOI.IECInstance pInstance = oECAdaptor.CreateClassInstance(oECAdaptor.Schema, strClassName); //WS: populate instance values oECAdaptor.SetInstancePropertyValue(ref pInstance, "Tag_Number", oGeoTagData.Tag_Number); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Tag_Status", oGeoTagData.Tag_Status); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Location", oGeoTagData.Location); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Service_Description", oGeoTagData.Service_Description); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Type", oGeoTagData.Type); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Plot_Plan_Document_Number", oGeoTagData.Plot_Plan_Document_Number); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Detail_Drawing_Document_Number", oGeoTagData.Detail_Drawing_Document_Number); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Construction_Month", oGeoTagData.Construction_Month); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Construction_Year", oGeoTagData.Construction_Year); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Originating_Contractor", oGeoTagData.Originating_Contractor); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Document_Number", oGeoTagData.Document_Number); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Material_Main", oGeoTagData.Material_Main); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Procument_Package_Number", oGeoTagData.Procument_Package_Number); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Contract_Package_Number", oGeoTagData.Contract_Package_Number); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Construction_Contractor_Name", oGeoTagData.Construction_Contractor_Name); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Construction_Specification_Document_Number", oGeoTagData.Construction_Specification_Document_Number); if (strClassName == "Pond") { oECAdaptor.SetInstancePropertyValue(ref pInstance, "Supplier_Name", (oGeoTagData as Pond).Supplier_Name); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Supplier_Reference_Drawing_Doc_Number", (oGeoTagData as Pond).Supplier_Reference_Drawing_Doc_Number); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Design_Capacity", (oGeoTagData as Pond).Design_Capacity); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Fluid_Description", (oGeoTagData as Pond).Fluid_Description); oECAdaptor.SetInstancePropertyValue(ref pInstance, "Max_Fluid_Level", (oGeoTagData as Pond).Max_Fluid_Level); } if (strClassName == "Road") { oECAdaptor.SetInstancePropertyValue(ref pInstance, "Number_of_Lanes", (oGeoTagData as Road).Number_of_Lanes); } if (strClassName == "OpenChannel") { oECAdaptor.SetInstancePropertyValue(ref pInstance, "Fluid_Description", (oGeoTagData as OpenChannel).Fluid_Description); } //WS: check if an instance of the class already exists in the element. if (!oECAdaptor.HasECInstanceAttached(oEle, strClassName)) { //WS: attach to element oECAdaptor.CreateInstance(oEle, ref pInstance); } else //WS: if already has instance attached, delete it first, and then create a new one. { //WS: update instance, need to modify.. //oECAdaptor.UpdateInstance(oEle, ref pInstance); oECAdaptor.DeleteInstancesOnElement(oEle, strClassName); oECAdaptor.CreateInstance(oEle, ref pInstance); } }
//WS: create an empty instance internal IECInstance CreateClassInstance(IECSchema Schema, string clsName) { ECOI.IECInstance pInstance = null; ECOS.IECClass pClass; //ECOS.IECSchema pSchema = LocateExampleSchema(connection, schema); pClass = Schema[clsName]; pInstance = pClass.CreateInstance(); return(pInstance); }
//WS: create a class instance based on schema internal IECInstance CreateClassInstance(IECSchema Schema, string clsName, string propertyAccessString, string propertyValue) { ECOI.IECInstance pInstance = null; ECOS.IECClass pClass; //ECOS.IECSchema pSchema = LocateExampleSchema(connection, schema); pClass = Schema[clsName]; pInstance = pClass.CreateInstance(); try { pInstance.SetAsString(propertyAccessString, propertyValue); return(pInstance); } catch (Exception ex) { Debug.Print("{0} in {1}\n\t{2}", ex, ex.TargetSite, ex.Message); return(null); } }