/// <summary> /// Uploads an application package to Storage /// </summary> public static AddApplicationPackageResult CreateApplicationPackage(BatchController controller, BatchAccountContext context, string applicationId, string version, string filePath) { AddApplicationPackageResult applicationPackage = null; if (HttpMockServer.Mode == HttpRecorderMode.Record) { applicationPackage = controller.BatchManagementClient.Application.AddApplicationPackage( context.ResourceGroupName, context.AccountName, applicationId, version); CloudBlockBlob blob = new CloudBlockBlob(new Uri(applicationPackage.StorageUrl)); blob.UploadFromFile(filePath, FileMode.Open); } return(applicationPackage); }
private string GetStorageUrl(string resourceGroupName, string accountName, string applicationId, string version, out bool didCreateAppPackage) { try { // Checks to see if the package exists GetApplicationPackageResult response = BatchManagementClient.Application.GetApplicationPackage( 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 { AddApplicationPackageResult addResponse = BatchManagementClient.Application.AddApplicationPackage( 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); } }