/// <summary> /// Parses the response. /// </summary> /// <param name="blockListResponse">The block list response.</param> /// <returns>An enumerable list of <see cref="ListBlockItem"/> objects.</returns> private static IEnumerable <ListBlockItem> ParseResponse(GetBlockListResponse blockListResponse) { List <ListBlockItem> result = new List <ListBlockItem>(); result.AddRange(blockListResponse.Blocks); return(result); }
public async Task <ActionResult <GetBlockListResponse> > GetBlockList() { var username = User.Identity.Name; var user = await userService.GetUserFromUsernameAsync(username).ConfigureAwait(false); if (user == null) { logger.LogWarning($"Attempt to get blocklist for unknown user '{username}'"); return(NotFound()); } logger.LogDebug($"Returned block list for user '{username}'"); var response = new GetBlockListResponse { Success = true }; response.BlockList.AddRange(user.BlockList.Select(bl => bl.BlockedUser).ToList()); return(response); }
/// <summary> /// Gets the download block list. /// </summary> /// <param name="typesOfBlocks">The types of blocks.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <param name="setResult">The result report delegate.</param> /// <returns>A <see cref="TaskSequence"/> that gets the download block list.</returns> internal TaskSequence GetDownloadBlockList(BlockListingFilter typesOfBlocks, BlobRequestOptions options, Action <IEnumerable <ListBlockItem> > setResult) { var request = ProtocolHelper.GetWebRequest(this.ServiceClient, options, (timeout) => BlobRequest.GetBlockList(this.TransformedAddress, timeout, this.SnapshotTime, typesOfBlocks, null)); this.ServiceClient.Credentials.SignRequest(request); // Retrieve the stream var requestStreamTask = request.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout); yield return(requestStreamTask); // Copy the data using (var response = requestStreamTask.Result as HttpWebResponse) { using (var responseStream = response.GetResponseStream()) { var blockListResponse = new GetBlockListResponse(responseStream); setResult(ParseResponse(blockListResponse)); } this.ParseSizeAndLastModified(response); } }
/// <summary> /// Gets the download block list. /// </summary> /// <param name="typesOfBlocks">The types of blocks.</param> /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the blob. If <c>null</c>, no condition is used.</param> /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="RESTCommand{T}"/> that gets the download block list.</returns> internal RESTCommand<IEnumerable<ListBlockItem>> GetBlockListImpl(BlockListingFilter typesOfBlocks, AccessCondition accessCondition, BlobRequestOptions options) { RESTCommand<IEnumerable<ListBlockItem>> getCmd = new RESTCommand<IEnumerable<ListBlockItem>>(this.ServiceClient.Credentials, this.Uri); getCmd.ApplyRequestOptions(options); getCmd.RetrieveResponseStream = true; getCmd.BuildRequestDelegate = (uri, builder, serverTimeout, ctx) => BlobHttpWebRequestFactory.GetBlockList(uri, serverTimeout, this.SnapshotTime, typesOfBlocks, accessCondition, 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) => { CloudBlobSharedImpl.UpdateETagLMTAndSequenceNumber(this.attributes, resp); GetBlockListResponse responseParser = new GetBlockListResponse(cmd.ResponseStream); IEnumerable<ListBlockItem> blocks = new List<ListBlockItem>(responseParser.Blocks); return blocks; }; return getCmd; }
public void GetBlockListScenarioTest(string containerName, string blobName, BlockListingFilter typesOfBlocks, string leaseId, HttpStatusCode? expectedError, params string[] expectedBlocks) { HttpWebRequest request = BlobTests.GetBlockListRequest(BlobContext, containerName, blobName, typesOfBlocks, AccessCondition.GenerateLeaseCondition(leaseId)); Assert.IsTrue(request != null, "Failed to create HttpWebRequest"); if (BlobContext.Credentials != null) { BlobTests.SignRequest(request, BlobContext); } HttpWebResponse response = BlobTestUtils.GetResponse(request, BlobContext); try { BlobTests.GetBlockListResponse(response, BlobContext, expectedError); GetBlockListResponse getBlockListResponse = new GetBlockListResponse(response.GetResponseStream()); int i = 0; foreach (ListBlockItem item in getBlockListResponse.Blocks) { if (expectedBlocks == null) { Assert.Fail("Should not have blocks."); } Assert.IsTrue(i < expectedBlocks.Length, "Unexpected block: " + item.Name); Assert.AreEqual<string>(expectedBlocks[i++], item.Name, "Incorrect block."); } if (expectedBlocks != null && i < expectedBlocks.Length) { Assert.Fail("Missing block: " + expectedBlocks[i] + "(and " + (expectedBlocks.Length - i - 1) + " more)."); } } finally { response.Close(); } }
/// <summary> /// Gets the download block list. /// </summary> /// <param name="typesOfBlocks">The types of blocks.</param> /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the blob. If <c>null</c>, no condition is used.</param> /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies any additional options for the request.</param> /// <returns>A <see cref="TaskSequence"/> that gets the download block list.</returns> internal RESTCommand<IEnumerable<ListBlockItem>> GetBlockListImpl(BlockListingFilter typesOfBlocks, AccessCondition accessCondition, BlobRequestOptions options) { RESTCommand<IEnumerable<ListBlockItem>> getCmd = new RESTCommand<IEnumerable<ListBlockItem>>(this.ServiceClient.Credentials, this.Uri); getCmd.ApplyRequestOptions(options); getCmd.RetrieveResponseStream = true; getCmd.Handler = this.ServiceClient.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.BuildRequest = (cmd, cnt, ctx) => BlobHttpRequestMessageFactory.GetBlockList(cmd.Uri, cmd.ServerTimeoutInSeconds, this.SnapshotTime, typesOfBlocks, accessCondition, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx); getCmd.PostProcessResponse = (cmd, resp, ex, ctx) => { CloudBlobSharedImpl.ParseSizeAndLastModified(this.attributes, resp); return Task.Factory.StartNew(() => { GetBlockListResponse responseParser = new GetBlockListResponse(cmd.ResponseStream); IEnumerable<ListBlockItem> blocks = new List<ListBlockItem>(responseParser.Blocks); return blocks; }); }; return getCmd; }
/// <summary> /// Parses the response. /// </summary> /// <param name="blockListResponse">The block list response.</param> /// <returns>An enumerable list of <see cref="ListBlockItem"/> objects.</returns> private static IEnumerable<ListBlockItem> ParseResponse(GetBlockListResponse blockListResponse) { List<ListBlockItem> result = new List<ListBlockItem>(); result.AddRange(blockListResponse.Blocks); return result; }
/// <summary> /// Gets the download block list. /// </summary> /// <param name="typesOfBlocks">The types of blocks.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <param name="setResult">The result report delegate.</param> /// <returns>A <see cref="TaskSequence"/> that gets the download block list.</returns> internal TaskSequence GetDownloadBlockList(BlockListingFilter typesOfBlocks, BlobRequestOptions options, Action<IEnumerable<ListBlockItem>> setResult) { var request = ProtocolHelper.GetWebRequest(this.ServiceClient, options, (timeout) => BlobRequest.GetBlockList(this.TransformedAddress, timeout, this.SnapshotTime, typesOfBlocks, null)); this.ServiceClient.Credentials.SignRequest(request); // Retrieve the stream var requestStreamTask = request.GetResponseAsyncWithTimeout(this.ServiceClient, options.Timeout); yield return requestStreamTask; // Copy the data using (var response = requestStreamTask.Result as HttpWebResponse) { using (var responseStream = response.GetResponseStream()) { var blockListResponse = new GetBlockListResponse(responseStream); setResult(ParseResponse(blockListResponse)); } this.ParseSizeAndLastModified(response); } }
/// <summary> /// Gets the download block list. /// </summary> /// <param name="typesOfBlocks">The types of blocks.</param> /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the blob. If <c>null</c>, no condition is used.</param> /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="TaskSequence"/> that gets the download block list.</returns> internal RESTCommand<IEnumerable<ListBlockItem>> GetBlockListImpl(BlockListingFilter typesOfBlocks, AccessCondition accessCondition, BlobRequestOptions options) { RESTCommand<IEnumerable<ListBlockItem>> getCmd = new RESTCommand<IEnumerable<ListBlockItem>>(this.ServiceClient.Credentials, this.attributes.StorageUri); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => BlobHttpRequestMessageFactory.GetBlockList(uri, serverTimeout, this.SnapshotTime, typesOfBlocks, accessCondition, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponse = (cmd, resp, ctx) => { CloudBlob.UpdateETagLMTLengthAndSequenceNumber(this.attributes, resp, true); return Task.Factory.StartNew(() => { GetBlockListResponse responseParser = new GetBlockListResponse(cmd.ResponseStream); IEnumerable<ListBlockItem> blocks = new List<ListBlockItem>(responseParser.Blocks); return blocks; }); }; return getCmd; }
protected List <ListBlockItem> AssertBlockListsAreEqual(string containerName, string blobName, GetBlockListResponse response) { var client = StorageAccount.CreateCloudBlobClient(); var container = client.GetContainerReference(containerName); if (!container.Exists()) { Assert.Fail("AssertBlockExists: The container '{0}' does not exist", containerName); } var blob = container.GetBlockBlobReference(blobName); var committedBlockList = blob.DownloadBlockList(BlockListingFilter.Committed); var uncommittedBlockList = blob.DownloadBlockList(BlockListingFilter.Uncommitted); var blockList = committedBlockList.Concat(uncommittedBlockList).ToList(); var gottenBlocks = response.CommittedBlocks.Concat(response.UncommittedBlocks).ToList(); var gottenBlocksCount = gottenBlocks.Count; Assert.AreEqual(blockList.Count, gottenBlocksCount); for (var i = 0; i < gottenBlocksCount; i++) { var expectedBlock = blockList[i]; var gottenBlock = gottenBlocks[i]; Assert.AreEqual(expectedBlock.Name, gottenBlock.Name); Assert.AreEqual(expectedBlock.Length, gottenBlock.Size); } return(blockList); }