Last active
August 29, 2015 14:10
-
-
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.
This file contains hidden or 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
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code.