Exemplo n.º 1
0
        /// <summary>
        /// Get the latest copy of the locked object.
        /// </summary>
        /// <param name="throwOnFailure">A <see cref="bool"/> indicating if a failure to release the lock should throw an exception.</param>
        /// <returns>An instance of the base object.</returns>
        public async Task <TLockableObject> GetObjectAsync(bool throwOnFailure = false, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!LockAcquired)
            {
                if (throwOnFailure)
                {
                    throw new DistributedLockException("No lock is acquired.");
                }
                return(null);
            }

            Debug.Assert(LockedObjectLockId != null, nameof(LockedObjectLockId) + " != null");
            return(await _store.GetLockedObjectAsync(LockedObjectId, LockedObjectLockId.Value, cancellationToken));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the latest copy of the base object containing the locked object.
        /// </summary>
        /// <param name="throwOnFailure">A <see cref="bool"/> indicating if a failure to release the lock should throw an exception.</param>
        /// <returns>An instance of the base object.</returns>
        public async Task <TBaseObject> GetObjectAsync(bool throwOnFailure = false, CancellationToken cancellationToken = default)
        {
            if (!LockAcquired)
            {
                if (throwOnFailure)
                {
                    throw new DistributedLockException("No lock is acquired.");
                }
                return(null);
            }

            Debug.Assert(LockedObjectLockId != null, nameof(LockedObjectLockId) + " != null");

            if (_tLockableObjectFieldSelector != null)
            {
                return(await _store.GetLockedObjectAsync(BaseObjectId, LockedObjectId, LockedObjectLockId.Value, _tLockableObjectFieldSelector, cancellationToken).ConfigureAwait(false));
            }
            if (_tLockableObjectArrayFieldSelector != null)
            {
                return(await _store.GetLockedObjectAsync(BaseObjectId, LockedObjectId, LockedObjectLockId.Value, _tLockableObjectArrayFieldSelector, cancellationToken).ConfigureAwait(false));
            }

            throw new DistributedLockException("No fieldSelector found.");
        }