コード例 #1
0
        /// <summary>
        /// Gets all existing load balancers through a series of asynchronous operations,
        /// each of which requests a subset of the available load balancers.
        /// </summary>
        /// <param name="provider">The load balancer service.</param>
        /// <param name="limit">The maximum number of <see cref="LoadBalancer"/> objects to return from a single task. If this value is <c>null</c>, a provider-specific default is used.</param>
        /// <returns>
        /// A collection of <see cref="LoadBalancer"/> objects describing the available load
        /// balancers.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="provider"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        private static IEnumerable<LoadBalancer> ListAllLoadBalancers(ILoadBalancerService provider, int? limit, CancellationToken cancellationToken)
        {
            if (limit <= 0)
                throw new ArgumentOutOfRangeException("limit");

            LoadBalancer lastLoadBalancer = null;

            do
            {
                LoadBalancerId marker = lastLoadBalancer != null ? lastLoadBalancer.Id : null;
                IEnumerable<LoadBalancer> loadBalancers = provider.ListLoadBalancersAsync(marker, limit, cancellationToken).Result;
                lastLoadBalancer = null;
                foreach (LoadBalancer loadBalancer in loadBalancers)
                {
                    yield return loadBalancer;
                    lastLoadBalancer = loadBalancer;
                }

                // pagination for this call does not match the documentation.
            } while (false && lastLoadBalancer != null);
        }