Exemplo n.º 1
0
        /// <summary>
        /// Gets all existing queues through a series of asynchronous operations,
        /// each of which requests a subset of the available queues.
        /// </summary>
        /// <param name="provider">The queueing service.</param>
        /// <param name="limit">The maximum number of <see cref="CloudQueue"/> objects to return from a single task. If this value is <see langword="null"/>, a provider-specific default is used.</param>
        /// <param name="detailed"><see langword="true"/> to return detailed information about each queue; otherwise, <see langword="false"/>.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that the task will observe.</param>
        /// <param name="progress">An optional callback object to receive progress notifications. If this is <see langword="null"/>, no progress notifications are sent.</param>
        /// <returns>
        /// A <see cref="Task"/> object representing the asynchronous operation. When the operation
        /// completes successfully, the <see cref="Task{TResult}.Result"/> property will contain a
        /// read-only collection containing the complete set of available queues.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="provider"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        private static async Task <ReadOnlyCollection <CloudQueue> > ListAllQueuesAsync(IQueueingService provider, int?limit, bool detailed, CancellationToken cancellationToken, net.openstack.Core.IProgress <ReadOnlyCollectionPage <CloudQueue> > progress)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (limit <= 0)
            {
                throw new ArgumentOutOfRangeException("limit");
            }

            return(await(await provider.ListQueuesAsync(null, limit, detailed, cancellationToken)).GetAllPagesAsync(cancellationToken, progress));
        }
        /// <summary>
        /// Gets all existing message queues through a series of asynchronous operations,
        /// each of which requests a subset of the available queues.
        /// </summary>
        /// <remarks>
        /// Each of the returned tasks is executed asynchronously but sequentially. This
        /// method will not send concurrent requests to the queueing service.
        /// <para>
        /// Due to the way the list end is detected, the final task will return an empty
        /// collection of <see cref="CloudQueue"/> instances.
        /// </para>
        /// </remarks>
        /// <param name="provider">The queueing service.</param>
        /// <param name="limit">The maximum number of <see cref="CloudQueue"/> to return from a single task. If this value is <c>null</c>, a provider-specific default is used.</param>
        /// <param name="detailed"><c>true</c> to return detailed information for each queue; otherwise, <c>false</c>.</param>
        /// <returns>
        /// A collections of <see cref="Task{TResult}"/> objects, each of which
        /// represents an asynchronous operation to gather a subset of the available
        /// queues.
        /// </returns>
        private static IEnumerable<Task<IEnumerable<CloudQueue>>> ListAllQueuesAsync(IQueueingService provider, int? limit, bool detailed, CancellationToken cancellationToken)
        {
            if (limit <= 0)
                throw new ArgumentOutOfRangeException("limit");

            CloudQueue lastQueue = null;

            do
            {
                QueueName marker = lastQueue != null ? lastQueue.Name : null;
                Task<IEnumerable<CloudQueue>> queues = provider.ListQueuesAsync(marker, limit, detailed, cancellationToken);
                lastQueue = null;
                yield return queues.ContinueWith(task =>
                {
                    return task.Result.Select(queue =>
                    {
                        lastQueue = queue;
                        return queue;
                    });
                });
            } while (lastQueue != null);
        }