示例#1
0
        public async Task <IList <ContainerItem> > ListBlobsAsync(string containerName, string delimiter, string prefix)
        {
            List <ContainerItem> containerItems = new List <ContainerItem>();
            string nextMarker = null;

            while (true)
            {
                Dictionary <string, string> queryParams =
                    new Dictionary <string, string>
                {
                    { "restype", "container" },
                    { "comp", "list" }
                };

                queryParams.AddIfValueNotNullOrWhitespace("delimiter", delimiter);
                queryParams.AddIfValueNotNullOrWhitespace("prefix", prefix);
                queryParams.AddIfValueNotNullOrWhitespace("marker", nextMarker);

                HttpRequestMessage request = BuildRequest(
                    containerName,
                    queryParams.ToQueryParameters(),
                    HttpMethod.Get);

                using (request)
                {
                    HttpResponseMessage responseMessage =
                        await SendRequestAsync(request).ConfigureAwait(false);

                    using (responseMessage)
                    {
                        EnumerationResults results =
                            await responseMessage.Content.ReadAsXmlObjectsync <EnumerationResults>()
                            .ConfigureAwait(false);

                        // Aggregate the blobs returned in the response
                        // Convert Internal.BlobPrefix to BlobPrefix and add to result
                        containerItems.AddRange(results.Blobs.OfType <DataModel.Internal.BlobPrefix>().Select(BlobPrefix.FromInternalResult));

                        // Convert Internal.Blob to Blob and add to result
                        containerItems.AddRange(results.Blobs.OfType <DataModel.Internal.Blob>().Select(Blob.FromInternalResult));

                        if (string.IsNullOrWhiteSpace(results.NextMarker))
                        {
                            return(containerItems);
                        }

                        nextMarker = results.NextMarker;
                    }
                }
            }
        }
示例#2
0
        public async Task <IList <Container> > ListContainersAsync()
        {
            List <Container> containers = new List <Container>();
            string           nextMarker = null;

            while (true)
            {
                Dictionary <string, string> queryParams = new Dictionary <string, string>()
                {
                    { "comp", "list" }
                };

                queryParams.AddIfValueNotNullOrWhitespace("marker", nextMarker);

                HttpRequestMessage request = BuildRequest(
                    null,
                    queryParams.ToQueryParameters(),
                    HttpMethod.Get);

                using (request)
                {
                    HttpResponseMessage responseMessage =
                        await SendRequestAsync(request).ConfigureAwait(false);

                    using (responseMessage)
                    {
                        EnumerationResults results =
                            await responseMessage.Content.ReadAsXmlObjectsync <EnumerationResults>().ConfigureAwait(false);

                        // Convert from the XML-based result object into our portable type
                        containers.AddRange(results.Containers.Select(Container.FromInternalResult));

                        if (string.IsNullOrWhiteSpace(results.NextMarker))
                        {
                            return(containers);
                        }

                        nextMarker = results.NextMarker;
                    }
                }
            }
        }