private string GetStorageUrl(string resourceGroupName, string accountName, string applicationId, string version, out bool didCreateAppPackage)
{
try
{
// Checks to see if the package exists
ApplicationPackage response = BatchManagementClient.ApplicationPackage.Get(
resourceGroupName,
accountName,
applicationId,
version);
didCreateAppPackage = false;
return response.StorageUrl;
}
catch (CloudException exception)
{
// If the application package is not found we want to create a new application package.
if (exception.Response.StatusCode != HttpStatusCode.NotFound)
{
var message = string.Format(Resources.FailedToGetApplicationPackage, applicationId, version, exception.Message);
throw new CloudException(message, exception);
}
}
try
{
ApplicationPackage addResponse = BatchManagementClient.ApplicationPackage.Create(
resourceGroupName,
accountName,
applicationId,
version);
// If Application was created we need to return a flag.
didCreateAppPackage = true;
return addResponse.StorageUrl;
}
catch (Exception exception)
{
var message = string.Format(Resources.FailedToAddApplicationPackage, applicationId, version, exception.Message);
throw new NewApplicationPackageException(message, exception);
}
}