public UploadContext Create()
{
AssertIfValidhVhd(localVhd);
AssertIfValidVhdSize(localVhd);
this.blobObjectFactory.CreateContainer(blobDestination);
UploadContext context = null;
bool completed = false;
try
{
context = new UploadContext
{
DestinationBlob = destinationBlob,
SingleInstanceMutex = AcquireSingleInstanceMutex(destinationBlob.Uri)
};
if (overWrite)
{
destinationBlob.DeleteIfExistsAsync(DeleteSnapshotsOption.IncludeSnapshots, null, requestOptions, operationContext: null)
.ConfigureAwait(false).GetAwaiter().GetResult();
}
if (destinationBlob.Exists(requestOptions))
{
Program.SyncOutput.MessageResumingUpload();
if (destinationBlob.GetBlobMd5Hash(requestOptions) != null)
{
throw new InvalidOperationException(
"An image already exists in blob storage with this name. If you want to upload again, use the Overwrite option.");
}
var metaData = destinationBlob.GetUploadMetaData();
AssertMetaDataExists(metaData);
AssertMetaDataMatch(metaData, OperationMetaData);
PopulateContextWithUploadableRanges(localVhd, context, true);
PopulateContextWithDataToUpload(localVhd, context);
}
else
{
CreateRemoteBlobAndPopulateContext(context);
}
context.Md5HashOfLocalVhd = MD5HashOfLocalVhd;
completed = true;
}
finally
{
if (!completed && context != null)
{
context.Dispose();
}
}
return(context);
}