Created
April 30, 2018 23:20
-
-
Save loic-sharma/1db163b0e30c17da2700429a78f64682 to your computer and use it in GitHub Desktop.
Blob Storage Profiling Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Microsoft.WindowsAzure.Storage; | |
using Microsoft.WindowsAzure.Storage.Blob; | |
namespace ConsoleApp6 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var connectionstring = "Connection string here"; | |
if (!CloudStorageAccount.TryParse(connectionstring, out var storageAccount)) | |
{ | |
Console.WriteLine("Bad connection string"); | |
} | |
var client = storageAccount.CreateCloudBlobClient(); | |
var container = client.GetContainerReference("octopuspackages"); | |
var directory = container.GetDirectoryReference("/"); | |
while (true) | |
{ | |
ListBlobs(directory).GetAwaiter().GetResult(); | |
} | |
} | |
private static async Task ListBlobs(CloudBlobDirectory directory) | |
{ | |
Console.WriteLine("Getting blobs"); | |
foreach (var blob in await directory.ListBlobsAsync(CancellationToken.None)) | |
{ | |
Console.WriteLine(blob.Uri); | |
} | |
Console.WriteLine("Done"); | |
} | |
} | |
internal static class CloudBlobStorageExtensions | |
{ | |
public static async Task<IEnumerable<IListBlobItem>> ListBlobsAsync( | |
this CloudBlobDirectory directory, CancellationToken cancellationToken) | |
{ | |
var items = new List<IListBlobItem>(); | |
BlobContinuationToken continuationToken = null; | |
do | |
{ | |
var segment = await directory.ListBlobsSegmentedAsync( | |
useFlatBlobListing: true, | |
blobListingDetails: BlobListingDetails.None, | |
maxResults: null, | |
currentToken: continuationToken, | |
options: null, | |
operationContext: null, | |
cancellationToken: cancellationToken); | |
continuationToken = segment.ContinuationToken; | |
items.AddRange(segment.Results); | |
} | |
while (continuationToken != null && !cancellationToken.IsCancellationRequested); | |
return items; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment