private bool RemoveClsExt(IClass classExtension)
        {
            ISchemaLock schemaLock = (ISchemaLock)classExtension;
            bool        result     = false;

            try
            {
                // Attempt to get an exclusive schema lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Cast the object class to the IClassSchemaEdit2 interface.
                IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)classExtension;

                // Clear the class extension.
                classSchemaEdit.AlterClassExtensionCLSID(null, null);

                IObjectClassDescription featureClassDescription = new FeatureClassDescriptionClass();
                classSchemaEdit.AlterInstanceCLSID(featureClassDescription.InstanceCLSID);

                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }

            return(result);
        }
Exemplo n.º 2
0
        private bool RemoveClsInstance(IClass classInstance, UID uid)
        {
            ISchemaLock schemaLock = (ISchemaLock)classInstance;
            bool        result     = false;

            try
            {
                // Attempt to get an exclusive schema lock.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Cast the object class to the IClassSchemaEdit2 interface.
                IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)classInstance;

                classSchemaEdit.AlterInstanceCLSID(uid);

                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }

            return(result);
        }
        /// <summary>
        /// This method should be called the first time the extension is initialized, when the
        /// extension properties are null. This will create a new set of properties with the default
        /// field names.
        /// </summary>
        private void InitNewExtension()
        {
            // First time the extension has been run, initialize the extension properties.
            extensionProperties = new PropertySetClass();
            extensionProperties.SetProperty(Resources.CreatedFieldKey, createdFieldName);
            extensionProperties.SetProperty(Resources.ModifiedFieldKey, modifiedFieldName);
            extensionProperties.SetProperty(Resources.UserFieldKey, userFieldName);

            // Store the properties.
            IClass            baseClass       = classHelper.Class;
            IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)baseClass;

            classSchemaEdit.AlterClassExtensionProperties(extensionProperties);
        }
        /// <summary>
        /// Changes the member variables and extension properties to store the provided field names
        /// as the created, modified and user fields (positions are also refreshed). Empty strings
        /// indicate the values should not be saved in a field.
        /// </summary>
        /// <param name="createdField">The name of the "created" field.</param>
        /// <param name="modifiedField">The name of the "modified" field.</param>
        /// <param name="userField">The name of the "user" field.</param>
        public void SetTimestampFields(String createdField, String modifiedField, String userField)
        {
            IClass      baseClass  = classHelper.Class;
            ISchemaLock schemaLock = (ISchemaLock)baseClass;

            try
            {
                // Get an exclusive lock. We want to do this prior to making any changes
                // to ensure the member variables and extension properties remain synchronized.
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Set the name member variables.
                createdFieldName  = createdField;
                modifiedFieldName = modifiedField;
                userFieldName     = userField;

                // Set the positions of the fields.
                SetFieldIndexes();

                // Modify the extension properties.
                extensionProperties.SetProperty(Resources.CreatedFieldKey, createdFieldName);
                extensionProperties.SetProperty(Resources.ModifiedFieldKey, modifiedFieldName);
                extensionProperties.SetProperty(Resources.UserFieldKey, userFieldName);

                // Change the properties.
                IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)baseClass;
                classSchemaEdit.AlterClassExtensionProperties(extensionProperties);
            }
            catch (COMException comExc)
            {
                throw new Exception(Resources.FailedToSavePropertiesMsg, comExc);
            }
            finally
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }