public bool IsFeatureClassLockable(IFeatureClass checkFeatureClass)
        {
            IObjectClass objectClass = checkFeatureClass as IObjectClass;

            if (objectClass == null)
            {
                return(false);
            }

            ISchemaLock schemaLock = (ISchemaLock)objectClass;

            if (schemaLock == null)
            {
                return(false);
            }

            // Get an enumerator over the current schema locks.
            IEnumSchemaLockInfo enumSchemaLockInfo = null;

            schemaLock.GetCurrentSchemaLocks(out enumSchemaLockInfo);

            // Iterate through the locks.
            ISchemaLockInfo schemaLockInfo = null;
            int             lockCount      = 0;

            while ((schemaLockInfo = enumSchemaLockInfo.Next()) != null)
            {
                lockCount++;
                Trace.WriteLine(string.Format("{0} : {1} : {2}", schemaLockInfo.TableName,
                                              schemaLockInfo.UserName, schemaLockInfo.SchemaLockType));
            }

            // Note: 1 sharedLock for this process is normal, so we test for > 1 lock
            return(lockCount < 2);
        }
Ejemplo n.º 2
0
        private void TopologyGeneralPropertyPage_Load(object sender, EventArgs e)
        {
            ISchemaLock         @lock          = this.itopology_0 as ISchemaLock;
            IEnumSchemaLockInfo schemaLockInfo = null;

            @lock.GetCurrentSchemaLocks(out schemaLockInfo);
            schemaLockInfo.Reset();
            if (schemaLockInfo.Next() == null)
            {
                this.txtName.Properties.ReadOnly             = true;
                this.txtClusterTolerance.Properties.ReadOnly = true;
            }
            this.txtName.Text             = (this.itopology_0 as IDataset).Name;
            this.txtClusterTolerance.Text = this.itopology_0.ClusterTolerance.ToString();
            this.bool_0 = true;
            switch (this.itopology_0.State)
            {
            case esriTopologyState.esriTSUnanalyzed:
                this.lblTopoError1.Text = "没有校验";
                this.lblTopoError2.Text = "在拓扑中存在一个或多个脏区。脏区是指被编辑过的区域";
                break;

            case esriTopologyState.esriTSAnalyzedWithErrors:
                this.lblTopoError1.Text = "已经校验 - 存在错误";
                this.lblTopoError2.Text = "所有编辑过的拓扑已经被校验过。有一个或多个拓扑错误存在";
                break;

            case esriTopologyState.esriTSAnalyzedWithoutErrors:
                this.lblTopoError1.Text = "已经校验 - 没有错误误";
                this.lblTopoError2.Text = "所有编辑过的拓扑已经被校验过。没有拓扑错误存在";
                break;
            }
        }
        /// <summary>Method to perform the actual schema lock</summary>
        /// <remarks>
        /// - If the schema is already locked by a different user, an exception is thrown with lock info (name / table)
        /// - If the schema is already locked by the current user, no lock is performed
        /// - When an exclusive lock is successfully established, the lock is added to the list of managed locks
        ///   for demotion at disposal
        /// </remarks>
        public void LockDatasetSchema(ITable fc)
        {
            ResourceManager resourceManager = new ResourceManager(
                "ESRI.ArcGIS.OSM.OSMClassExtension.OSMClassExtensionStrings", this.GetType().Assembly);

            ISchemaLock schemaLock = fc as ISchemaLock;

            if (schemaLock == null)
            {
                throw new ArgumentNullException("schemaLock");
            }

            // make sure that are not any existing exclusive locks
            IEnumSchemaLockInfo currentlyExistingLocks;

            try
            {
                schemaLock.GetCurrentSchemaLocks(out currentlyExistingLocks);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(resourceManager.GetString("OSMClassExtensionManager_Reading_Lock_Exception"));
            }

            bool            gdbAlreadyLockedbyUser = false;
            ISchemaLockInfo schemaLockInfo         = null;

            while ((schemaLockInfo = currentlyExistingLocks.Next()) != null)
            {
                if (schemaLockInfo.SchemaLockType == esriSchemaLock.esriExclusiveSchemaLock &&
                    !String.IsNullOrEmpty(schemaLockInfo.UserName))
                {
                    throw new ApplicationException(string.Format(
                                                       resourceManager.GetString("OSMClassExtensionManager_Exclusive_Lock_Exception"),
                                                       schemaLockInfo.TableName, schemaLockInfo.UserName));
                }
                else if (schemaLockInfo.SchemaLockType == esriSchemaLock.esriExclusiveSchemaLock)
                {
                    gdbAlreadyLockedbyUser = true;
                    break;
                }
            }

            if (!gdbAlreadyLockedbyUser)
            {
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);
            }

            _managedLocks.Add(schemaLock);
        }