/// <summary> /// This method is used to cancel record of coauthoring session or schema lock. /// </summary> /// <param name="fileUrl">Specify the file URL which get the coauth lock.</param> /// <param name="clientId">Specify the client ID of the coauth lock.</param> /// <param name="schemaLockId">Specify the schema ID of the coauth lock.</param> public void CancelSharedLock(string fileUrl, string clientId, string schemaLockId) { SharedLockKey key = new SharedLockKey(fileUrl, clientId, schemaLockId); if (this.releaseSharedLockFunctions.Keys.Contains(key)) { this.releaseSharedLockFunctions.Remove(key); } }
/// <summary> /// This method is used to add or update the key/value pairs with the specified key status. /// </summary> /// <param name="key">Specify the key.</param> /// <param name="value">Specify the value.</param> /// <param name="keyStatus">Specify the key status.</param> private void AddOrUpdate(string key, Action value, KeyStatus keyStatus) { switch (keyStatus) { case KeyStatus.CheckOut: if (this.fileCheckOutRollbackFunctions.Keys.Contains(key)) { this.fileCheckOutRollbackFunctions[key] = value; } else { this.fileCheckOutRollbackFunctions.Add(key, value); } break; case KeyStatus.ExclusiveLock: if (this.releaseExclusiveLockFunctions.Keys.Contains(key)) { // There is no way to record twice exclusive lock for just one file this.site.Assert.Fail("Fail to record the exclusive lock on the file {0} more than once.", key); } else { // If the file already lock by the shared lock, then remove the shared lock record. SharedLockKey findKey = this.releaseSharedLockFunctions.Keys.FirstOrDefault(k => k.FileUrl == key); if (findKey != null) { this.releaseSharedLockFunctions.Remove(findKey); } this.releaseExclusiveLockFunctions.Add(key, value); } break; case KeyStatus.UploadTextFile: if (this.removeFileFunctions.Keys.Contains(key)) { this.removeFileFunctions[key] = value; } else { this.removeFileFunctions.Add(key, value); } break; default: this.site.Assert.Fail("Unsupported operation."); break; } }
/// <summary> /// Override the equals function. /// </summary> /// <param name="obj">Specify the other instance need to be compared.</param> /// <returns>Return true if equals, otherwise return false.</returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if (this.GetType() == obj.GetType()) { SharedLockKey other = (SharedLockKey)obj; return(this.ClientId == other.ClientId && this.FileUrl == other.FileUrl && this.SchemaLockId == other.SchemaLockId); } else { return(false); } }
/// <summary> /// This method is used to add or update the ReleaseSharedLockFunctions key/value pairs. /// </summary> /// <param name="key">Specify the key.</param> /// <param name="value">Specify the value.</param> private void AddOrUpdate(SharedLockKey key, Action value) { if (this.releaseSharedLockFunctions.Keys.Contains(key)) { this.releaseSharedLockFunctions[key] = value; } else { // If the file already lock by the exclusive lock, then remove the exclusive lock record. string findKey = this.releaseExclusiveLockFunctions.Keys.FirstOrDefault(fileUrl => fileUrl == key.FileUrl); if (findKey != null) { this.releaseExclusiveLockFunctions.Remove(findKey); } this.releaseSharedLockFunctions.Add(key, value); } }