/// <summary>
        /// Constructs a web request to return a listing of all blobs in the container.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="listingContext">A set of parameters for the listing operation.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest List(Uri uri, int timeout, BlobListingContext listingContext)
        {
            UriQueryBuilder builder = ContainerRequest.GetContainerUriQueryBuilder();

            builder.Add(Constants.QueryConstants.Component, "list");

            if (listingContext != null)
            {
                if (listingContext.Prefix != null)
                {
                    builder.Add("prefix", listingContext.Prefix);
                }

                if (listingContext.Delimiter != null)
                {
                    builder.Add("delimiter", listingContext.Delimiter);
                }

                if (listingContext.Marker != null)
                {
                    builder.Add("marker", listingContext.Marker);
                }

                if (listingContext.MaxResults != null)
                {
                    builder.Add("maxresults", listingContext.MaxResults.ToString());
                }

                if (listingContext.Include != BlobListingDetails.None)
                {
                    StringBuilder sb = new StringBuilder();

                    bool started = false;

                    if ((listingContext.Include & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("snapshots");
                    }

                    if ((listingContext.Include & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("uncommittedblobs");
                    }

                    if ((listingContext.Include & BlobListingDetails.Metadata) == BlobListingDetails.Metadata)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("metadata");
                    }

                    builder.Add("include", sb.ToString());
                }
            }

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "GET";

            return(request);
        }
        /// <summary>
        /// Constructs a web request to return a listing of all blobs in the container.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="listingContext">A set of parameters for the listing operation.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest List(Uri uri, int timeout, BlobListingContext listingContext)
        {
            UriQueryBuilder builder = ContainerRequest.GetContainerUriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "list");

            if (listingContext != null)
            {
                if (listingContext.Prefix != null)
                {
                    builder.Add("prefix", listingContext.Prefix);
                }

                if (listingContext.Delimiter != null)
                {
                    builder.Add("delimiter", listingContext.Delimiter);
                }

                if (listingContext.Marker != null)
                {
                    builder.Add("marker", listingContext.Marker);
                }

                if (listingContext.MaxResults != null)
                {
                    builder.Add("maxresults", listingContext.MaxResults.ToString());
                }

                if (listingContext.Include != BlobListingDetails.None)
                {
                    StringBuilder sb = new StringBuilder();

                    bool started = false;

                    if ((listingContext.Include & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("snapshots");
                    }

                    if ((listingContext.Include & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("uncommittedblobs");
                    }

                    if ((listingContext.Include & BlobListingDetails.Metadata) == BlobListingDetails.Metadata)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("metadata");
                    }

                    builder.Add("include", sb.ToString());
                }
            }

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "GET";

            return request;
        }
        /// <summary>Core implementation of the ListBlobs method.</summary>
        /// <param name="prefix">The blob prefix. </param>
        /// <param name="options">An object that specifies any additional options for the request. </param>
        /// <param name="continuationToken">The continuation token. </param>
        /// <param name="pagination">The pagination. </param>
        /// <param name="setResult">The result report delegate. </param>
        /// <returns>A <see cref="TaskSequence"/> that lists the blobs. </returns>
        private TaskSequence ListBlobsImplCore(
            string prefix,
            BlobRequestOptions options,
            ResultContinuation continuationToken,
            ResultPagination pagination,
            Action<ResultSegment<IListBlobItem>> setResult)
        {
            CommonUtils.AssertContinuationType(continuationToken, ResultContinuation.ContinuationType.Blob);
            CommonUtils.AssertNotNull("options", options);

            if (!options.UseFlatBlobListing
                && (options.BlobListingDetails & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
            {
                throw new ArgumentException(SR.ListSnapshotsWithDelimiterError, "options");
            }

            var delimiter = options.UseFlatBlobListing ? null : this.ServiceClient.DefaultDelimiter;

            var listingContext = new BlobListingContext(
                prefix, pagination.GetNextRequestPageSize(), delimiter, options.BlobListingDetails)
                {
                   Marker = continuationToken != null ? continuationToken.NextMarker : null
                };

            var blobList = new List<IListBlobItem>();

            var request = ProtocolHelper.GetWebRequest(
                this.ServiceClient,
                options,
                timeout => BlobRequest.List(this.TransformedAddress, timeout, listingContext));
            this.ServiceClient.Credentials.SignRequest(request);
            var listTask = request.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout);
            yield return listTask;

            string nextMarker;
            using (var response = listTask.Result as HttpWebResponse)
            {
                var listBlobResponse = BlobResponse.List(response);
                blobList.AddRange(
                    listBlobResponse.Blobs.Select(
                        item => CloudBlobClient.SelectProtocolResponse(item, this.ServiceClient, this)));

                nextMarker = listBlobResponse.NextMarker;
            }

            var newContinuationToken = new ResultContinuation
                {
                   NextMarker = nextMarker, Type = ResultContinuation.ContinuationType.Blob
                };

            ResultSegment.CreateResultSegment(
                setResult,
                blobList,
                newContinuationToken,
                pagination,
                options.RetryPolicy,
                (paginationArg, continuationArg, resultSegmentArg) =>
                this.ListBlobsImplCore(prefix, options, continuationArg, paginationArg, resultSegmentArg));
        }