private void UploadFileToApplicationPackage(
string resourceGroupName,
string accountName,
string applicationId,
string version,
string filePath,
string storageUrl,
bool appPackageAlreadyExists)
{
try
{
CloudBlockBlob blob = new CloudBlockBlob(new Uri(storageUrl));
blob.UploadFromFile(filePath, FileMode.Open);
}
catch (Exception exception)
{
// If the application package has already been created we don't want to delete the application package mysteriously.
if (appPackageAlreadyExists)
{
// If we are creating a new application package and the upload fails we should delete the application package.
try
{
DeleteApplicationPackage(resourceGroupName, accountName, applicationId, version);
}
catch
{
// Need to throw if we fail to delete the application while attempting to clean it up.
var deleteMessage = string.Format(Resources.FailedToUploadAndDelete, filePath, exception.Message);
throw new NewApplicationPackageException(deleteMessage, exception);
}
}
// Need to throw if we fail to upload the file's content.
var uploadMessage = string.Format(Resources.FailedToUpload, filePath, exception.Message);
throw new NewApplicationPackageException(uploadMessage, exception);
}
}