Ejemplo n.º 1
0
        } // doWork method

        protected void RegisterWithGeodatabase(
            IObjectClass objectClass,
            String oidFieldName)
        {
            if (oidFieldName == "")
            {
                oidFieldName = "OBJECTID";
            }
            // Attempt to acquire an exclusive schema lock for the object class.
            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            try {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                // If this point is reached, the exclusive lock was acquired. We can cast the object
                // class to IClassSchemaEdit and call RegisterAsObjectClass.
                IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)objectClass;
                classSchemaEdit.RegisterAsObjectClass(oidFieldName, "");
            }
            catch (COMException comExc) {
                // Re-throw the exception.
                throw comExc;
            }
            finally {
                // Reset the lock on the object class to a shared lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        } // RegisterWithGeodatabase method
Ejemplo n.º 2
0
        /// <summary>
        /// Register the newly created table with the Geodatabase.
        /// </summary>
        /// <param name="pTable"></param>
        /// <param name="oidFieldName"></param>
        private static void RegisterWithGeodatabase(ITable pTable, string oidFieldName)
        {
            if (!(IsArcInfoLicense()))
            {
                return;
            }

            IObjectClass oc = (IObjectClass)pTable;

            if (oidFieldName == "")
            {
                oidFieldName = "OBJECTID";
            }
            // Attempt to acquire an exclusive schema lock for the object class.
            ISchemaLock schemaLock = (ISchemaLock)oc;

            try
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
                // If this point is reached, the exclusive lock was acquired. We can cast the object
                // class to IClassSchemaEdit and call RegisterAsObjectClass.
                IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)oc;
                classSchemaEdit.RegisterAsObjectClass(oidFieldName, "");
            }
            catch (COMException comExc)
            {
                // Re-throw the exception.
                throw comExc;
            }
            finally
            {
                // Reset the lock on the object class to a shared lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        } // method RegisterWithGeodatabase
Ejemplo n.º 3
0
        /// <summary>
        /// 创建属性表
        /// </summary>
        /// <param name="pWorkspace"></param>
        /// <returns></returns>
        public ITable CreateTable(IWorkspace pWorkspace, string strName, string strAliasName, IFields fields)
        {
            if (pWorkspace == null)
            {
                return(null);
            }
            IFeatureWorkspace featureWorkspace = pWorkspace as IFeatureWorkspace;

            if (featureWorkspace == null)
            {
                return(null);
            }
            ITable table = null;

            try
            {
                table = featureWorkspace.CreateTable(strName, fields, null, null, null);
                if (!string.IsNullOrEmpty(strAliasName))
                {
                    IClassSchemaEdit classSchemaEdit = table as IClassSchemaEdit;
                    if (null != classSchemaEdit)
                    {
                        classSchemaEdit.RegisterAsObjectClass("OBJECTID", null);
                        classSchemaEdit.AlterAliasName(strAliasName);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(table);
        }