예제 #1
0
        /// <summary>
        /// This is for internal use only.
        /// Removes the lock context
        /// </summary>
        /// <param name="lockManager">Lock manager object which contains the lock to be removed</param>
        /// <param name="lockOrKey">name of the lock</param>
        /// <returns>LockContext object if found. null otherwise</returns>
        public LockContext RemoveLockContext(ILockManager lockManager, object lockOrKey)
        {
            if (lockManager == null)
            {
                throw new ArgumentNullException(
                          string.Format(CultureInfo.CurrentCulture, SR.Error_NullArgument_Formatted, "lockManager"));
            }

            if (lockOrKey == null)
            {
                throw new ArgumentNullException(
                          string.Format(CultureInfo.CurrentCulture, SR.Error_NullArgument_Formatted, "lockOrKey"));
            }

            LockContext removedLockContext = null;

            for (var i = 0; i < this.LockContexts.Count; i++)
            {
                var lockContext = this.LockContexts[i];
                if (lockContext.IsEqual(lockManager, lockOrKey) == true)
                {
                    this.LockContexts.RemoveAt(i);
                    removedLockContext = lockContext;
                    break;
                }
            }

            return(removedLockContext);
        }
예제 #2
0
        private void AddReadLock(LockContext lockContext)
        {
            if (this.readLockContexts == null)
            {
                throw new InvalidOperationException("Read locks cannot be added once the read locks has been released.");
            }

            this.readLockContexts.Add(lockContext);
        }
예제 #3
0
        /// <summary>
        /// This is for internal use only.
        /// Removes the lock context
        /// </summary>
        /// <param name="lockContext">The lock context to be removed</param>
        public void RemoveLockContext(LockContext lockContext)
        {
            if (lockContext == null)
            {
                throw new ArgumentNullException(
                          string.Format(CultureInfo.CurrentCulture, SR.Error_NullArgument_Formatted, "lockContext"));
            }

            for (var i = 0; i < this.LockContexts.Count; i++)
            {
                if (this.LockContexts[i] == lockContext)
                {
                    this.LockContexts.RemoveAt(i);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Adds a lock context.
        /// </summary>
        /// <param name="lockContext">
        /// The lock context.
        /// </param>
        /// <param name="lockMode">
        /// Mode of the lock.
        /// For committing transaction read locks are released before IO.
        /// </param>
        public void AddLockContext(LockContext lockContext, LockContextMode lockMode = LockContextMode.Write)
        {
            if (lockContext == null)
            {
                throw new ArgumentNullException(
                          string.Format(CultureInfo.CurrentCulture, SR.Error_NullArgument_Formatted, "lockContext"));
            }

            if (lockMode == LockContextMode.Write)
            {
                this.LockContexts.Add(lockContext);
            }
            else
            {
                this.AddReadLock(lockContext);
            }
        }