/// <summary>
 /// Constructs a web request to return a listing of all containers in this storage account.
 /// </summary>
 /// <param name="uri">A <see cref="System.Uri"/> specifying the Blob service endpoint.</param>
 /// <param name="timeout">An integer specifying the server timeout interval.</param>
 /// <param name="listingContext">A <see cref="ListingContext"/> object.</param>
 /// <param name="detailsIncluded">A <see cref="ContainerListingDetails"/> enumeration value that indicates whether to return container metadata with the listing.</param>
 /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
 /// <returns>A web request for the specified operation.</returns>
 public static HttpWebRequest List(Uri uri, int? timeout, ListingContext listingContext, ContainerListingDetails detailsIncluded, OperationContext operationContext)
 {
     return ContainerHttpWebRequestFactory.List(uri, timeout, listingContext, detailsIncluded, true /* useVersionHeader */, operationContext);
 }
        /// <summary>
        /// Constructs a web request to return a listing of all containers in this storage account.
        /// </summary>
        /// <param name="uri">A <see cref="System.Uri"/> specifying the Blob service endpoint.</param>
        /// <param name="timeout">An integer specifying the server timeout interval.</param>
        /// <param name="listingContext">A <see cref="ListingContext"/> object.</param>
        /// <param name="detailsIncluded">A <see cref="ContainerListingDetails"/> enumeration value that indicates whether to return container metadata with the listing.</param>
        /// <param name="useVersionHeader">A boolean value indicating whether to set the <i>x-ms-version</i> HTTP header.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        /// <returns>A web request for the specified operation.</returns>
        public static HttpWebRequest List(Uri uri, int? timeout, ListingContext listingContext, ContainerListingDetails detailsIncluded, bool useVersionHeader, OperationContext operationContext)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "list");

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

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

                if (listingContext.MaxResults.HasValue)
                {
                    builder.Add("maxresults", listingContext.MaxResults.ToString());
                }
            }

            if ((detailsIncluded & ContainerListingDetails.Metadata) != 0)
            {
                builder.Add("include", "metadata");
            }

            HttpWebRequest request = HttpWebRequestFactory.CreateWebRequest(WebRequestMethods.Http.Get, uri, timeout, builder, useVersionHeader, operationContext);
            return request;
        }
        /// <summary>
        /// Constructs a web request to return a listing of all containers in this storage account.
        /// </summary>
        /// <param name="uri">The absolute URI for the account.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="listingContext">A set of parameters for the listing operation.</param>
        /// <param name="detailsIncluded">Additional details to return with the listing.</param>
        /// <returns>A web request for the specified operation.</returns>
        public static HttpRequestMessage List(Uri uri, int? timeout, ListingContext listingContext, ContainerListingDetails detailsIncluded, HttpContent content, OperationContext operationContext)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "list");

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

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

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

            if ((detailsIncluded & ContainerListingDetails.Metadata) != 0)
            {
                builder.Add("include", "metadata");
            }

            HttpRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Get, uri, timeout, builder, content, operationContext);
            return request;
        }
        /// <summary>
        /// Core implementation for the ListContainers method.
        /// </summary>
        /// <param name="prefix">The container prefix.</param>
        /// <param name="detailsIncluded">The details included.</param>
        /// <param name="currentToken">The continuation token.</param>
        /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned 
        /// in the result segment, up to the per-operation limit of 5000. If this value is null, the maximum possible number of results will be returned, up to 5000.</param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies any additional options for the request.</param>
        /// <returns>A <see cref="ResultSegment{T}"/> that lists the containers.</returns>
        private RESTCommand<ResultSegment<CloudBlobContainer>> ListContainersImpl(string prefix, ContainerListingDetails detailsIncluded, BlobContinuationToken currentToken, int? maxResults, BlobRequestOptions options)
        {
            ListingContext listingContext = new ListingContext(prefix, maxResults)
            {
                Marker = currentToken != null ? currentToken.NextMarker : null
            };

            RESTCommand<ResultSegment<CloudBlobContainer>> getCmd = new RESTCommand<ResultSegment<CloudBlobContainer>>(this.Credentials, this.BaseUri);

            getCmd.ApplyRequestOptions(options);
            getCmd.RetrieveResponseStream = true;
            getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => ContainerHttpWebRequestFactory.List(uri, serverTimeout, listingContext, detailsIncluded, ctx);
            getCmd.SignRequest = this.AuthenticationHandler.SignRequest;
            getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx);
            getCmd.PostProcessResponse = (cmd, resp, ex, ctx) =>
            {
                ListContainersResponse listContainersResponse = new ListContainersResponse(cmd.ResponseStream);
                List<CloudBlobContainer> containersList = new List<CloudBlobContainer>(
                    listContainersResponse.Containers.Select(item => new CloudBlobContainer(item.Properties, item.Metadata, item.Name, this)));
                BlobContinuationToken continuationToken = null;
                if (listContainersResponse.NextMarker != null)
                {
                    continuationToken = new BlobContinuationToken()
                    {
                        NextMarker = listContainersResponse.NextMarker,
                    };
                }

                return new ResultSegment<CloudBlobContainer>(containersList)
                {
                    ContinuationToken = continuationToken,
                };
            };

            return getCmd;
        }
예제 #5
0
        /// <summary>
        /// Core implementation for the ListQueues method.
        /// </summary>
        /// <param name="prefix">The queue prefix.</param>
        /// <param name="detailsIncluded">The details included.</param>
        /// <param name="currentToken">The continuation token.</param>
        /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the 
        /// per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.</param>
        /// <returns>A <see cref="TaskSequence"/> that lists the queues.</returns>
        private RESTCommand<ResultSegment<CloudQueue>> ListQueuesImpl(string prefix, QueueListingDetails detailsIncluded, QueueContinuationToken currentToken, int? maxResults)
        {
            ListingContext listingContext = new ListingContext(prefix, maxResults)
            {
                Marker = currentToken != null ? currentToken.NextMarker : null
            };

            RESTCommand<ResultSegment<CloudQueue>> getCmd = new RESTCommand<ResultSegment<CloudQueue>>(this.Credentials, this.BaseUri);

            getCmd.RetrieveResponseStream = true;
            getCmd.Handler = this.AuthenticationHandler;
            getCmd.BuildClient = HttpClientFactory.BuildHttpClient;
            getCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.List(cmd.Uri, cmd.ServerTimeoutInSeconds, listingContext, detailsIncluded, cnt, ctx);
            getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx);
            getCmd.PostProcessResponse = (cmd, resp, ex, ctx) =>
            {
                return Task.Factory.StartNew(() =>
                {
                    ListQueuesResponse listQueuesResponse = new ListQueuesResponse(cmd.ResponseStream);

                    List<CloudQueue> queuesList = new List<CloudQueue>(
                        listQueuesResponse.Queues.Select(item => new CloudQueue(item.Name, this)));

                    QueueContinuationToken continuationToken = null;
                    if (listQueuesResponse.NextMarker != null)
                    {
                        continuationToken = new QueueContinuationToken()
                        {
                            NextMarker = listQueuesResponse.NextMarker,
                        };
                    }

                    return new ResultSegment<CloudQueue>(queuesList)
                    {
                        ContinuationToken = continuationToken,
                    };
                });
            };

            return getCmd;
        }
        /// <summary>
        /// Core implementation for the ListContainers method.
        /// </summary>
        /// <param name="prefix">The container prefix.</param>
        /// <param name="detailsIncluded">The details included.</param>
        /// <param name="currentToken">The continuation token.</param>
        /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the 
        /// per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.</param>         
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies execution options, such as retry policy and timeout settings, for the operation.</param>
        /// <returns>A <see cref="TaskSequence"/> that lists the containers.</returns>
        private RESTCommand<ResultSegment<CloudBlobContainer>> ListContainersImpl(string prefix, ContainerListingDetails detailsIncluded, BlobContinuationToken currentToken, int? maxResults, BlobRequestOptions options)
        {
            ListingContext listingContext = new ListingContext(prefix, maxResults)
            {
                Marker = currentToken != null ? currentToken.NextMarker : null
            };

            RESTCommand<ResultSegment<CloudBlobContainer>> getCmd = new RESTCommand<ResultSegment<CloudBlobContainer>>(this.Credentials, this.StorageUri);

            options.ApplyToStorageCommand(getCmd);
            getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken);
            getCmd.RetrieveResponseStream = true;
            getCmd.Handler = this.AuthenticationHandler;
            getCmd.BuildClient = HttpClientFactory.BuildHttpClient;
            getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => ContainerHttpRequestMessageFactory.List(uri, serverTimeout, listingContext, detailsIncluded, cnt, ctx);
            getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex);
            getCmd.PostProcessResponse = (cmd, resp, ctx) =>
            {
                return Task.Factory.StartNew(() =>
                {
                    ListContainersResponse listContainersResponse = new ListContainersResponse(cmd.ResponseStream);
                    List<CloudBlobContainer> containersList = listContainersResponse.Containers.Select(item => new CloudBlobContainer(item.Properties, item.Metadata, item.Name, this)).ToList();
                    BlobContinuationToken continuationToken = null;
                    if (listContainersResponse.NextMarker != null)
                    {
                        continuationToken = new BlobContinuationToken()
                        {
                            NextMarker = listContainersResponse.NextMarker,
                            TargetLocation = cmd.CurrentResult.TargetLocation,
                        };
                    }

                    return new ResultSegment<CloudBlobContainer>(containersList)
                    {
                        ContinuationToken = continuationToken,
                    };
                });
            };

            return getCmd;
        }
        public void BlobProtocolGetContainerWithEmptyHeader()
        {
            ListingContext listingContext = new ListingContext("default", null);
            cloudOwnerAsync.CreateContainer("emptyheadercontainer", true);

            HttpWebRequest request = BlobTests.ListContainersRequest(cloudOwnerAsync.BlobContext, listingContext);
            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (cloudOwnerAsync.BlobContext.Credentials != null)
            {
                BlobTests.SignRequest(request, cloudOwnerAsync.BlobContext);
                request.Headers.Add("x-ms-blob-application-metadata", "");
            }
            using (HttpWebResponse response = BlobTestUtils.GetResponse(request, cloudOwnerAsync.BlobContext))
            {
                BlobTests.ListContainersResponse(response, cloudOwnerAsync.BlobContext, null);
            }

            request = BlobTests.ListContainersRequest(cloudOwnerAsync.BlobContext, listingContext);
            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (cloudOwnerAsync.BlobContext.Credentials != null)
            {
                request.Headers.Add("x-ms-blob-application-metadata", "");
                BlobTests.SignRequest(request, cloudOwnerAsync.BlobContext);
            }
            using (HttpWebResponse response = BlobTestUtils.GetResponse(request, cloudOwnerAsync.BlobContext))
            {
                BlobTests.ListContainersResponse(response, cloudOwnerAsync.BlobContext, HttpStatusCode.OK);
            }
        }
 public void ListContainersScenarioTest(ListingContext listingContext, HttpStatusCode? expectedError, params string[] expectedContainers)
 {
     HttpWebRequest request = BlobTests.ListContainersRequest(BlobContext, listingContext);
     Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
     if (BlobContext.Credentials != null)
     {
         BlobTests.SignRequest(request, BlobContext);
     }
     HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext);
     try
     {
         BlobTests.ListContainersResponse(response, BlobContext, expectedError);
         ListContainersResponse listContainersResponse = new ListContainersResponse(response.GetResponseStream());
         int i = 0;
         foreach (BlobContainerEntry item in listContainersResponse.Containers)
         {
             if (expectedContainers == null)
             {
                 Assert.Fail("Should not have containers.");
             }
             Assert.IsTrue(i < expectedContainers.Length, "Unexpected container: " + item.Name);
             Assert.AreEqual<string>(expectedContainers[i++], item.Name, "Incorrect container.");
         }
         if (expectedContainers != null && i < expectedContainers.Length)
         {
             Assert.Fail("Missing container: " + expectedContainers[i] + "(and " + (expectedContainers.Length - i - 1) + " more).");
         }
     }
     finally
     {
         response.Close();
     }
 }
예제 #9
0
 public static HttpWebRequest ListSharesRequest(FileContext context, ListingContext listingContext)
 {
     Uri uri = FileClientTests.ConstructUri(context.Address);
     OperationContext opContext = new OperationContext();
     HttpWebRequest request = ShareHttpWebRequestFactory.List(uri, context.Timeout, listingContext, ShareListingDetails.Metadata, true, opContext);
     Assert.IsNotNull(request);
     Assert.IsNotNull(request.Method);
     Assert.AreEqual("GET", request.Method);
     FileTestUtils.RangeHeader(request, null);
     return request;
 }
        public void BlobProtocolListContainersCloud()
        {
            ListingContext listingContext = new ListingContext("default", null);
            cloudOwnerAsync.ListContainersScenarioTest(listingContext, null, cloudSetup.ContainerName);

            cloudSetup.CreateContainer("newcontainer1", true);
            cloudSetup.CreateContainer("newcontainer2", true);

            try
            {
                cloudOwnerAsync.ListContainersScenarioTest(listingContext, null, cloudSetup.ContainerName);
                listingContext = new ListingContext("newcontainer", 10);
                cloudOwnerAsync.ListContainersScenarioTest(listingContext, null, "newcontainer1", "newcontainer2");
            }
            finally
            {
                cloudSetup.DeleteContainer("newcontainer1");
                cloudSetup.DeleteContainer("newcontainer2");
            }
        }
        /// <summary>
        /// Core implementation for the ListShares method.
        /// </summary>
        /// <param name="prefix">The share prefix.</param>
        /// <param name="detailsIncluded">The details included.</param>
        /// <param name="currentToken">The continuation token.</param>
        /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned 
        /// in the result segment, up to the per-operation limit of 5000. If this value is null, the maximum possible number of results will be returned, up to 5000.</param>
        /// <param name="options">A <see cref="FileRequestOptions"/> object that specifies additional options for the request.</param>
        /// <returns>A <see cref="RESTCommand{T}"/> that lists the shares.</returns>
        private RESTCommand<ResultSegment<CloudFileShare>> ListSharesImpl(string prefix, ShareListingDetails detailsIncluded, FileContinuationToken currentToken, int? maxResults, FileRequestOptions options)
        {
            ListingContext listingContext = new ListingContext(prefix, maxResults)
            {
                Marker = currentToken != null ? currentToken.NextMarker : null
            };

            RESTCommand<ResultSegment<CloudFileShare>> getCmd = new RESTCommand<ResultSegment<CloudFileShare>>(this.Credentials, this.StorageUri);

            options.ApplyToStorageCommand(getCmd);
            getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken);
            getCmd.RetrieveResponseStream = true;
            getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, useVersionHeader, ctx) => ShareHttpWebRequestFactory.List(uri, serverTimeout, listingContext, detailsIncluded, useVersionHeader, ctx);
            getCmd.SignRequest = this.AuthenticationHandler.SignRequest;
            getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null, cmd, ex);
            getCmd.PostProcessResponse = (cmd, resp, ctx) =>
            {
                ListSharesResponse listSharesResponse = new ListSharesResponse(cmd.ResponseStream);
                List<CloudFileShare> sharesList = new List<CloudFileShare>(
                    listSharesResponse.Shares.Select(item => new CloudFileShare(item.Properties, item.Metadata, item.Name, this)));
                FileContinuationToken continuationToken = null;
                if (listSharesResponse.NextMarker != null)
                {
                    continuationToken = new FileContinuationToken()
                    {
                        NextMarker = listSharesResponse.NextMarker,
                        TargetLocation = cmd.CurrentResult.TargetLocation,
                    };
                }

                return new ResultSegment<CloudFileShare>(sharesList)
                {
                    ContinuationToken = continuationToken,
                };
            };

            return getCmd;
        }
 public static HttpWebRequest ListContainersRequest(BlobContext context, ListingContext listingContext)
 {
     Uri uri = BlobClientTests.ConstructUri(context.Address);
     OperationContext opContext = new OperationContext();
     HttpWebRequest request = ContainerHttpWebRequestFactory.List(uri, context.Timeout, listingContext, ContainerListingDetails.Metadata, opContext);
     Assert.IsNotNull(request);
     Assert.IsNotNull(request.Method);
     Assert.AreEqual("GET", request.Method);
     BlobTestUtils.RangeHeader(request, null);
     BlobTestUtils.LeaseIdHeader(request, null);
     return request;
 }
        public void FileProtocolGetShareWithEmptyHeader()
        {
            ListingContext listingContext = new ListingContext("default", null);
            cloudOwnerAsync.CreateShare("emptyheadershare1");

            HttpWebRequest request = FileTests.ListSharesRequest(cloudOwnerAsync.FileContext, listingContext);
            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (cloudOwnerAsync.FileContext.Credentials != null)
            {
                FileTests.SignRequest(request, cloudOwnerAsync.FileContext);
                request.Headers.Add("x-ms-file-application-metadata", "");
            }
            using (HttpWebResponse response = FileTestUtils.GetResponse(request, cloudOwnerAsync.FileContext))
            {
                FileTests.ListSharesResponse(response, cloudOwnerAsync.FileContext, null);
            }

            request = FileTests.ListSharesRequest(cloudOwnerAsync.FileContext, listingContext);
            Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
            if (cloudOwnerAsync.FileContext.Credentials != null)
            {
                request.Headers.Add("x-ms-file-application-metadata", "");
                FileTests.SignRequest(request, cloudOwnerAsync.FileContext);
            }
            using (HttpWebResponse response = FileTestUtils.GetResponse(request, cloudOwnerAsync.FileContext))
            {
                FileTests.ListSharesResponse(response, cloudOwnerAsync.FileContext, HttpStatusCode.OK);
            }
        }
        public void FileProtocolListSharesCloud()
        {
            ListingContext listingContext = new ListingContext("default", null);
            cloudOwnerAsync.ListSharesScenarioTest(listingContext, null, cloudSetup.ShareName);

            cloudSetup.CreateShare("newshare1");
            cloudSetup.CreateShare("newshare2");

            try
            {
                cloudOwnerAsync.ListSharesScenarioTest(listingContext, null, cloudSetup.ShareName);
                listingContext = new ListingContext("n", 10);
                cloudOwnerAsync.ListSharesScenarioTest(listingContext, null, "newshare1", "newshare2");
            }
            finally
            {
                cloudSetup.DeleteShare("newshare1");
                cloudSetup.DeleteShare("newshare2");
            }
        }
예제 #15
0
 public void ListSharesScenarioTest(ListingContext listingContext, HttpStatusCode? expectedError, params string[] expectedShares)
 {
     HttpWebRequest request = FileTests.ListSharesRequest(FileContext, listingContext);
     Assert.IsTrue(request != null, "Failed to create HttpWebRequest");
     if (FileContext.Credentials != null)
     {
         FileTests.SignRequest(request, FileContext);
     }
     HttpWebResponse response = FileTestUtils.GetResponse(request, FileContext);
     try
     {
         FileTests.ListSharesResponse(response, FileContext, expectedError);
         ListSharesResponse listSharesResponse = new ListSharesResponse(response.GetResponseStream());
         int i = 0;
         foreach (FileShareEntry item in listSharesResponse.Shares)
         {
             if (expectedShares == null)
             {
                 Assert.Fail("Should not have shares.");
             }
             Assert.IsTrue(i < expectedShares.Length, "Unexpected share: " + item.Name);
             Assert.AreEqual<string>(expectedShares[i++], item.Name, "Incorrect share.");
         }
         if (expectedShares != null && i < expectedShares.Length)
         {
             Assert.Fail("Missing share: " + expectedShares[i] + "(and " + (expectedShares.Length - i - 1) + " more).");
         }
     }
     finally
     {
         response.Close();
     }
 }