private bool method_2(IObjectClass iobjectClass_1) { bool flag; try { IEnumSchemaLockInfo info; (iobjectClass_1 as ISchemaLock).GetCurrentSchemaLocks(out info); info.Reset(); for (ISchemaLockInfo info2 = info.Next(); info2 != null; info2 = info.Next()) { if (info2.SchemaLockType == esriSchemaLock.esriExclusiveSchemaLock) { goto Label_0041; } } return(true); Label_0041: flag = false; } catch { flag = false; } return(flag); }
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); }
/// <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); }