Skip to content

Instantly share code, notes, and snippets.

@rushfrisby
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save rushfrisby/43344de7882b53ae0d77 to your computer and use it in GitHub Desktop.

Select an option

Save rushfrisby/43344de7882b53ae0d77 to your computer and use it in GitHub Desktop.
Starts the Azure Storage Emulator if it is not running. Useful for running unit tests on a build server.
private async Task StartAzureStorageEmulator()
{
if (!Settings.Default.StartAzureStorageEmulator)
return;
try
{
var storageAccount = CloudStorageAccount.Parse(Settings.Default.AzureStorageConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("test");
var context = new OperationContext();
var options = new BlobRequestOptions
{
RetryPolicy = new NoRetry(),
ServerTimeout = TimeSpan.FromSeconds(1)
};
await container.ExistsAsync(options, context);
}
catch (StorageException)
{
var processStartInfo = new ProcessStartInfo
{
FileName = @"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\WAStorageEmulator.exe",
Arguments = @"start",
};
using (var process = Process.Start(processStartInfo))
{
process.WaitForExit();
}
}
}
@satisne

satisne commented Jul 29, 2015

Copy link
Copy Markdown

Thanks for the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment