public async Task ListBlobsScenarioTest(string containerName, BlobListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedBlobs) { HttpRequestMessage request = BlobTests.ListBlobsRequest(BlobContext, containerName, listingContext); Assert.IsTrue(request != null, "Failed to create HttpRequestMessage"); using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext)) { BlobTests.ListBlobsResponse(response, BlobContext, expectedError); ListBlobsResponse listBlobsResponse = await ListBlobsResponse.ParseAsync(HttpResponseParsers.GetResponseStream(response), CancellationToken.None); int i = 0; foreach (IListBlobEntry item in listBlobsResponse.Blobs) { ListBlobEntry blob = item as ListBlobEntry; if (expectedBlobs == null) { Assert.Fail("Should not have blobs."); } Assert.IsTrue(i < expectedBlobs.Length, "Unexpected blob: " + blob.Name); Assert.AreEqual <string>(expectedBlobs[i++], blob.Name, "Incorrect blob."); } if (expectedBlobs != null && i < expectedBlobs.Length) { Assert.Fail("Missing blob: " + expectedBlobs[i] + "(and " + (expectedBlobs.Length - i - 1) + " more)."); } } }
public void BlobProtocolListingContextValidation() { BlobListingContext listingContext1 = new BlobListingContext("correct", 1, null, BlobListingDetails.All); try { BlobListingContext listingContext2 = new BlobListingContext("below min", 0, null, BlobListingDetails.All); Assert.Fail(); } catch (ArgumentOutOfRangeException e) { Assert.IsTrue(e.ToString().Contains("System.ArgumentOutOfRangeException: The argument 'maxResults' is smaller than minimum of '1'")); } BlobListingContext listingContext3 = new BlobListingContext("not limited", 6000, null, BlobListingDetails.All); }
public void BlobProtocolListBlobsCloudOwnerSync() { BlobListingContext listingContext = new BlobListingContext("def", null, null, BlobListingDetails.All); cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, cloudSetup.BlobName); cloudSetup.CreateBlob(cloudSetup.ContainerName, "newblob1", false); cloudSetup.CreateBlob(cloudSetup.ContainerName, "newblob2", false); try { cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, cloudSetup.BlobName); listingContext = new BlobListingContext("n", 10, "/", BlobListingDetails.Metadata); cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, "newblob1", "newblob2"); } finally { cloudSetup.DeleteBlob(cloudSetup.ContainerName, "newblob1"); cloudSetup.DeleteBlob(cloudSetup.ContainerName, "newblob2"); } }
public void BlobProtocolListBlobsCloudAnonSync() { BlobListingContext listingContext = new BlobListingContext("p", null, null, BlobListingDetails.All); cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, cloudSetup.PublicBlobName); cloudSetup.CreateBlob(cloudSetup.PublicContainerName, "newblob1", true); cloudSetup.CreateBlob(cloudSetup.PublicContainerName, "newblob2", true); try { cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, cloudSetup.PublicBlobName); // snapshots cannot be listed along with delimiter listingContext = new BlobListingContext("n", 10, "/", BlobListingDetails.Metadata); cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, "newblob1", "newblob2"); } finally { cloudSetup.DeleteBlob(cloudSetup.PublicContainerName, "newblob1"); cloudSetup.DeleteBlob(cloudSetup.PublicContainerName, "newblob2"); } }
public void ListBlobsScenarioTest(string containerName, BlobListingContext listingContext, HttpStatusCode?expectedError, params string[] expectedBlobs) { HttpWebRequest request = BlobTests.ListBlobsRequest(BlobContext, containerName, 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.ListBlobsResponse(response, BlobContext, expectedError); ListBlobsResponse listBlobsResponse = new ListBlobsResponse(response.GetResponseStream()); int i = 0; foreach (IListBlobEntry item in listBlobsResponse.Blobs) { ListBlobEntry blob = item as ListBlobEntry; if (expectedBlobs == null) { Assert.Fail("Should not have blobs."); } Assert.IsTrue(i < expectedBlobs.Length, "Unexpected blob: " + blob.Name); Assert.AreEqual <string>(expectedBlobs[i++], blob.Name, "Incorrect blob."); } if (expectedBlobs != null && i < expectedBlobs.Length) { Assert.Fail("Missing blob: " + expectedBlobs[i] + "(and " + (expectedBlobs.Length - i - 1) + " more)."); } } finally { response.Close(); } }
public void BlobProtocolListBlobsCloudOwnerSync() { BlobListingContext listingContext = new BlobListingContext("def", null, null, BlobListingDetails.All); cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, cloudSetup.BlobName); cloudSetup.CreateBlob(cloudSetup.ContainerName, "newblob1", false); cloudSetup.CreateBlob(cloudSetup.ContainerName, "newblob2", false); try { cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, cloudSetup.BlobName); listingContext = new BlobListingContext("n", 10, "/", BlobListingDetails.Metadata); cloudOwnerSync.ListBlobsScenarioTest(cloudSetup.ContainerName, listingContext, null, "newblob1", "newblob2"); } finally { cloudSetup.DeleteBlob(cloudSetup.ContainerName, "newblob1"); cloudSetup.DeleteBlob(cloudSetup.ContainerName, "newblob2"); } }
public void BlobProtocolListBlobsCloudAnonSync() { BlobListingContext listingContext = new BlobListingContext("p", null, null, BlobListingDetails.All); cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, cloudSetup.PublicBlobName); cloudSetup.CreateBlob(cloudSetup.PublicContainerName, "newblob1", true); cloudSetup.CreateBlob(cloudSetup.PublicContainerName, "newblob2", true); try { cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, cloudSetup.PublicBlobName); // snapshots cannot be listed along with delimiter listingContext = new BlobListingContext("n", 10, "/", BlobListingDetails.Metadata); cloudAnonSync.ListBlobsScenarioTest(cloudSetup.PublicContainerName, listingContext, null, "newblob1", "newblob2"); } finally { cloudSetup.DeleteBlob(cloudSetup.PublicContainerName, "newblob1"); cloudSetup.DeleteBlob(cloudSetup.PublicContainerName, "newblob2"); } }
/// <summary> /// Generates a web request to return a listing of all blobs in the container. /// </summary> /// <param name="uri">The absolute URI to the container.</param> /// <param name="timeout">The server timeout interval.</param> /// <param name="listingContext">A set of parameters for the listing operation.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param> /// <returns>A web request to use to perform the operation.</returns> public static HttpWebRequest ListBlobs(Uri uri, int?timeout, BlobListingContext listingContext, OperationContext operationContext) { UriQueryBuilder builder = ContainerHttpWebRequestFactory.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.Details != BlobListingDetails.None) { StringBuilder sb = new StringBuilder(); bool started = false; if ((listingContext.Details & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("snapshots"); } if ((listingContext.Details & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("uncommittedblobs"); } if ((listingContext.Details & BlobListingDetails.Metadata) == BlobListingDetails.Metadata) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("metadata"); } if ((listingContext.Details & BlobListingDetails.Copy) == BlobListingDetails.Copy) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("copy"); } builder.Add("include", sb.ToString()); } } HttpWebRequest request = HttpWebRequestFactory.CreateWebRequest(WebRequestMethods.Http.Get, uri, timeout, builder, operationContext); return(request); }
public static HttpWebRequest ListBlobsRequest(BlobContext context, string containerName, BlobListingContext listingContext) { Uri uri = BlobClientTests.ConstructUri(context.Address, containerName); OperationContext opContext = new OperationContext(); HttpWebRequest request = ContainerHttpWebRequestFactory.ListBlobs(uri, context.Timeout, listingContext, opContext); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("GET", request.Method); BlobTestUtils.RangeHeader(request, null); BlobTestUtils.LeaseIdHeader(request, null); return request; }
public static HttpRequestMessage ListBlobsRequest(BlobContext context, string containerName, BlobListingContext listingContext) { Uri uri = BlobClientTests.ConstructUri(context.Address, containerName); OperationContext opContext = new OperationContext(); HttpRequestMessage request = ContainerHttpRequestMessageFactory.ListBlobs(uri, context.Timeout, listingContext, null, opContext, SharedKeyCanonicalizer.Instance, context.Credentials); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual(HttpMethod.Get, request.Method); BlobTestUtils.RangeHeader(request, null); BlobTestUtils.LeaseIdHeader(request, null); return(request); }
/// <summary> /// Generates a web request to return a listing of all blobs in the container. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the container.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="listingContext">A <see cref="ListingContext"/> object.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest ListBlobs(Uri uri, int? timeout, BlobListingContext listingContext, OperationContext operationContext) { return ContainerHttpWebRequestFactory.ListBlobs(uri, timeout, listingContext, true /* useVersionHeader */, operationContext); }
public void BlobProtocolListingContextValidation() { BlobListingContext listingContext1 = new BlobListingContext("correct", 1, null, BlobListingDetails.All); try { BlobListingContext listingContext2 = new BlobListingContext("below min", 0, null, BlobListingDetails.All); Assert.Fail(); } catch (ArgumentOutOfRangeException e) { Assert.IsTrue(e.ToString().Contains("System.ArgumentOutOfRangeException: The argument 'maxResults' is smaller than minimum of '1'")); } BlobListingContext listingContext3 = new BlobListingContext("not limited", 6000, null, BlobListingDetails.All); }
/// <summary> /// Generates a web request to return a listing of all blobs in the container. /// </summary> /// <param name="uri">The absolute URI to the container.</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 StorageRequestMessage ListBlobs(Uri uri, int?timeout, BlobListingContext listingContext, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials) { UriQueryBuilder builder = ContainerHttpRequestMessageFactory.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.HasValue) { builder.Add("maxresults", listingContext.MaxResults.ToString()); } if (listingContext.Details != BlobListingDetails.None) { StringBuilder sb = new StringBuilder(); bool started = false; if ((listingContext.Details & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("snapshots"); } if ((listingContext.Details & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("uncommittedblobs"); } if ((listingContext.Details & BlobListingDetails.Metadata) == BlobListingDetails.Metadata) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("metadata"); } if ((listingContext.Details & BlobListingDetails.Copy) == BlobListingDetails.Copy) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("copy"); } builder.Add("include", sb.ToString()); } } StorageRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Get, uri, timeout, builder, content, operationContext, canonicalizer, credentials); return(request); }
/// <summary> /// Core implementation of the ListBlobs method. /// </summary> /// <param name="prefix">The blob prefix.</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="useFlatBlobListing">Specifies whether to list blobs in a flat listing, or whether to list blobs hierarchically, by virtual directory.</param> /// <param name="blobListingDetails">A <see cref="BlobListingDetails"/> enumeration describing which items to include in the listing.</param> /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param> /// <param name="currentToken">A continuation token returned by a previous listing operation.</param> /// <returns>A <see cref="RESTCommand{T}"/> that lists the blobs.</returns> private RESTCommand<ResultSegment<IListBlobItem>> ListBlobsImpl(string prefix, int? maxResults, bool useFlatBlobListing, BlobListingDetails blobListingDetails, BlobRequestOptions options, BlobContinuationToken currentToken) { if (!useFlatBlobListing && (blobListingDetails & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots) { throw new ArgumentException(SR.ListSnapshotsWithDelimiterError, "blobListingDetails"); } string delimiter = useFlatBlobListing ? null : this.ServiceClient.DefaultDelimiter; BlobListingContext listingContext = new BlobListingContext(prefix, maxResults, delimiter, blobListingDetails) { Marker = currentToken != null ? currentToken.NextMarker : null }; RESTCommand<ResultSegment<IListBlobItem>> getCmd = new RESTCommand<ResultSegment<IListBlobItem>>(this.ServiceClient.Credentials, this.Uri); getCmd.ApplyRequestOptions(options); getCmd.RetrieveResponseStream = true; getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => ContainerHttpWebRequestFactory.ListBlobs(uri, serverTimeout, listingContext, ctx); getCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest; getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponse = (cmd, resp, ctx) => { ListBlobsResponse listBlobsResponse = new ListBlobsResponse(cmd.ResponseStream); List<IListBlobItem> blobList = new List<IListBlobItem>( listBlobsResponse.Blobs.Select(item => this.SelectListBlobItem(item))); BlobContinuationToken continuationToken = null; if (listBlobsResponse.NextMarker != null) { continuationToken = new BlobContinuationToken() { NextMarker = listBlobsResponse.NextMarker, }; } return new ResultSegment<IListBlobItem>(blobList) { ContinuationToken = continuationToken, }; }; return getCmd; }
/// <summary> /// Generates a web request to return a listing of all blobs in the container. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the container.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="listingContext">A <see cref="ListingContext"/> object.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest ListBlobs(Uri uri, int?timeout, BlobListingContext listingContext, OperationContext operationContext) { return(ContainerHttpWebRequestFactory.ListBlobs(uri, timeout, listingContext, true /* useVersionHeader */, operationContext)); }
public void ListBlobsScenarioTest(string containerName, BlobListingContext listingContext, HttpStatusCode? expectedError, params string[] expectedBlobs) { HttpWebRequest request = BlobTests.ListBlobsRequest(BlobContext, containerName, 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.ListBlobsResponse(response, BlobContext, expectedError); ListBlobsResponse listBlobsResponse = new ListBlobsResponse(response.GetResponseStream()); int i = 0; foreach (IListBlobEntry item in listBlobsResponse.Blobs) { ListBlobEntry blob = item as ListBlobEntry; if (expectedBlobs == null) { Assert.Fail("Should not have blobs."); } Assert.IsTrue(i < expectedBlobs.Length, "Unexpected blob: " + blob.Name); Assert.AreEqual<string>(expectedBlobs[i++], blob.Name, "Incorrect blob."); } if (expectedBlobs != null && i < expectedBlobs.Length) { Assert.Fail("Missing blob: " + expectedBlobs[i] + "(and " + (expectedBlobs.Length - i - 1) + " more)."); } } finally { response.Close(); } }
/// <summary> /// Core implementation of the ListBlobs method. /// </summary> /// <param name="prefix">The blob prefix.</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="useFlatBlobListing">Whether to list blobs in a flat listing, or whether to list blobs hierarchically, by virtual directory.</param> /// <param name="blobListingDetails">A <see cref="BlobListingDetails"/> enumeration describing which items to include in the listing.</param> /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param> /// <param name="currentToken">The continuation token.</param> /// <returns>A <see cref="RESTCommand"/> that lists the blobs.</returns> private RESTCommand<ResultSegment<IListBlobItem>> ListBlobsImpl(string prefix, int? maxResults, bool useFlatBlobListing, BlobListingDetails blobListingDetails, BlobRequestOptions options, BlobContinuationToken currentToken) { if (!useFlatBlobListing && (blobListingDetails & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots) { throw new ArgumentException(SR.ListSnapshotsWithDelimiterError, "blobListingDetails"); } string delimiter = useFlatBlobListing ? null : this.ServiceClient.DefaultDelimiter; BlobListingContext listingContext = new BlobListingContext(prefix, maxResults, delimiter, blobListingDetails) { Marker = currentToken != null ? currentToken.NextMarker : null }; RESTCommand<ResultSegment<IListBlobItem>> getCmd = new RESTCommand<ResultSegment<IListBlobItem>>(this.ServiceClient.Credentials, this.StorageUri); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(currentToken); getCmd.RetrieveResponseStream = true; getCmd.Handler = this.ServiceClient.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => ContainerHttpRequestMessageFactory.ListBlobs(uri, serverTimeout, listingContext, 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(() => { ListBlobsResponse listBlobsResponse = new ListBlobsResponse(cmd.ResponseStream); List<IListBlobItem> blobList = listBlobsResponse.Blobs.Select(item => this.SelectListBlobItem(item)).ToList(); BlobContinuationToken continuationToken = null; if (listBlobsResponse.NextMarker != null) { continuationToken = new BlobContinuationToken() { NextMarker = listBlobsResponse.NextMarker, TargetLocation = cmd.CurrentResult.TargetLocation, }; } return new ResultSegment<IListBlobItem>(blobList) { ContinuationToken = continuationToken, }; }); }; return getCmd; }
/// <summary> /// Generates a web request to return a listing of all blobs in the container. /// </summary> /// <param name="uri">The absolute URI to the container.</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 StorageRequestMessage ListBlobs(Uri uri, int? timeout, BlobListingContext listingContext, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials) { UriQueryBuilder builder = ContainerHttpRequestMessageFactory.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.HasValue) { builder.Add("maxresults", listingContext.MaxResults.ToString()); } if (listingContext.Details != BlobListingDetails.None) { StringBuilder sb = new StringBuilder(); bool started = false; if ((listingContext.Details & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("snapshots"); } if ((listingContext.Details & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("uncommittedblobs"); } if ((listingContext.Details & BlobListingDetails.Metadata) == BlobListingDetails.Metadata) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("metadata"); } if ((listingContext.Details & BlobListingDetails.Copy) == BlobListingDetails.Copy) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("copy"); } builder.Add("include", sb.ToString()); } } StorageRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Get, uri, timeout, builder, content, operationContext, canonicalizer, credentials); return request; }
/// <summary> /// Generates a web request to return a listing of all blobs in the container. /// </summary> /// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the container.</param> /// <param name="timeout">An integer specifying the server timeout interval.</param> /// <param name="listingContext">A <see cref="ListingContext"/> object.</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 <see cref="System.Net.HttpWebRequest"/> object.</returns> public static HttpWebRequest ListBlobs(Uri uri, int? timeout, BlobListingContext listingContext, bool useVersionHeader, OperationContext operationContext) { UriQueryBuilder builder = ContainerHttpWebRequestFactory.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.HasValue) { builder.Add("maxresults", listingContext.MaxResults.ToString()); } if (listingContext.Details != BlobListingDetails.None) { StringBuilder sb = new StringBuilder(); bool started = false; if ((listingContext.Details & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("snapshots"); } if ((listingContext.Details & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("uncommittedblobs"); } if ((listingContext.Details & BlobListingDetails.Metadata) == BlobListingDetails.Metadata) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("metadata"); } if ((listingContext.Details & BlobListingDetails.Copy) == BlobListingDetails.Copy) { if (!started) { started = true; } else { sb.Append(","); } sb.Append("copy"); } builder.Add("include", sb.ToString()); } } HttpWebRequest request = HttpWebRequestFactory.CreateWebRequest(WebRequestMethods.Http.Get, uri, timeout, builder, useVersionHeader, operationContext); return request; }
public static HttpWebRequest ListBlobsRequest(BlobContext context, string containerName, BlobListingContext listingContext) { Uri uri = BlobClientTests.ConstructUri(context.Address, containerName); OperationContext opContext = new OperationContext(); HttpWebRequest request = ContainerHttpWebRequestFactory.ListBlobs(uri, context.Timeout, listingContext, opContext); Assert.IsNotNull(request); Assert.IsNotNull(request.Method); Assert.AreEqual("GET", request.Method); BlobTestUtils.RangeHeader(request, null); BlobTestUtils.LeaseIdHeader(request, null); return(request); }