コード例 #1
0
ファイル: LockingComponent.cs プロジェクト: shrgup/repo1
        /// <summary>
        /// Acquire one or more locks, in the order specified by resource names.
        /// </summary>
        /// <returns>True if all locks were acquired. False otherwise.</returns>
        public override bool AcquireLocks(TeamFoundationLockMode lockMode, Int32 lockTimeout, String[] resources, out String timedoutLockName)
        {
            resources = AppendPartitionIds(resources);

            // SQL uses 0 for an infinite wait, we using Timeout.Infinite which
            // we need to adjust our timeout for. If the lockTimeout is shorter
            // than command timeout use the command timeout and the lock will
            // fail in the sproc faster.
            Int32 sqlTimeout = lockTimeout;

            if (lockTimeout == Timeout.Infinite)
            {
                sqlTimeout = 0;
            }
            else
            {
                sqlTimeout = Math.Max(lockTimeout, CommandTimeout);
            }

            // This request is different from most, it should never timeout.
            // These connections must stay open until the lock is released.
            PrepareStoredProcedure("prc_AcquireLocks", sqlTimeout);

            BindString("@lockMode", lockMode.ToString(), 32, false, System.Data.SqlDbType.NVarChar);
            BindInt("@lockTimeout", lockTimeout);
            this.BindOrderedStringTable("@resources", resources);

            SqlDataReader reader = ExecuteReader();

            if (!reader.Read())
            {
                throw new UnexpectedDatabaseResultException(ProcedureName);
            }

            AcquireLocksColumns acquireLocksColumns = new AcquireLocksColumns();

            Int32 result = acquireLocksColumns.StatusColumn.GetInt32(reader);

            timedoutLockName = acquireLocksColumns.ResourceColumn.GetString(reader, allowNulls: true);

            // We need to release verification lock to ensure that we can perform schema updates while this component is holding a lock.
            ReleaseVerificationLock();

            //  0: The lock was successfully granted synchronously.
            //  1: The lock was granted successfully after waiting for other incompatible locks to be released.
            // -1: The lock request timed out.
            // Any other negative result is raised as an error in prc_AcquireLock.
            return(result >= 0);
        }
コード例 #2
0
ファイル: LockingComponent.cs プロジェクト: shrgup/repo1
        /// <summary>
        /// Acquires the app lock for the resource with the given lock mode.
        /// </summary>
        /// <param name="resource"></param>
        /// <param name="lockMode"></param>
        /// <returns>True if the lock was granted successfully. False if the lock request timed out.</returns>
        public virtual bool AcquireLock(String resource, TeamFoundationLockMode lockMode, Int32 lockTimeout)
        {
            // SQL uses 0 for an infinite wait, we using Timeout.Infinite which
            // we need to adjust our timeout for. If the lockTimeout is shorter
            // than command timeout use the command timeout and the lock will
            // fail in the sproc faster.
            resource = AppendPartitionId(resource);
            Int32 sqlTimeout = lockTimeout;

            if (lockTimeout == Timeout.Infinite)
            {
                sqlTimeout = 0;
            }
            else
            {
                sqlTimeout = Math.Max(lockTimeout, CommandTimeout);
            }

            // This request is different from most, it should never timeout.
            // These connections must stay open until the lock is released.
            PrepareStoredProcedure("prc_AcquireLock", sqlTimeout);


            BindString("@lockMode", lockMode.ToString(), 32, false, System.Data.SqlDbType.NVarChar);
            BindString("@resource", resource, 255, false, System.Data.SqlDbType.NVarChar);
            BindInt("@lockTimeout", lockTimeout);

            //  0: The lock was successfully granted synchronously.
            //  1: The lock was granted successfully after waiting for other incompatible locks to be released.
            // -1: The lock request timed out.
            // Any other negative result is raised as an error in prc_AcquireLock.
            bool result = (Int32)ExecuteScalar() >= 0;

            // We need to release verification lock to ensure that we can perform schema updates while this component is holding a lock.
            ReleaseVerificationLock();

            return(result);
        }
コード例 #3
0
ファイル: LockingComponent.cs プロジェクト: shrgup/repo1
 public virtual bool AcquireLocks(TeamFoundationLockMode lockMode, Int32 lockTimeout, String[] resources, out String timedoutLockName)
 {
     throw new InvalidServiceVersionException(ServiceNameConstants.Locking, 1, 2);
 }