Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Created April 30, 2018 23:20
Show Gist options
  • Save loic-sharma/1db163b0e30c17da2700429a78f64682 to your computer and use it in GitHub Desktop.
Save loic-sharma/1db163b0e30c17da2700429a78f64682 to your computer and use it in GitHub Desktop.
Blob Storage Profiling Test
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