Ejemplo n.º 1
0
        /// <summary>
        /// Renews the claim by resetting the age and updating the TTL for the claim.
        /// </summary>
        /// <remarks>
        /// This method calls <see cref="IQueueingService.UpdateClaimAsync"/> to renew the
        /// current claim, and then synchronously updates the current instance to reflect
        /// the new age and time-to-live values.
        /// </remarks>
        /// <param name="timeToLive">
        /// The new Time-To-Live value for the claim. This value may differ from the original TTL of the claim.
        /// </param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that the task will observe.</param>
        /// <returns>A <see cref="Task"/> object representing the asynchronous operation.</returns>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="timeToLive"/> is negative or <see cref="TimeSpan.Zero"/>.</exception>
        /// <exception cref="InvalidOperationException">If the claim is empty (i.e. <see cref="Messages"/> is empty).</exception>
        public Task RenewAsync(TimeSpan timeToLive, CancellationToken cancellationToken)
        {
            if (timeToLive <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("timeToLive");
            }
            if (_location == null)
            {
                throw new InvalidOperationException("Empty claims cannot be renewed.");
            }

            Action <Task> applyChanges =
                task =>
            {
                _age       = TimeSpan.Zero;
                TimeToLive = timeToLive;
            };

            return(_service.UpdateClaimAsync(_queueName, this, timeToLive, cancellationToken).Select(applyChanges));
        }