public static CloudStorageAccount GetCloudStorageAccount(this WindowsAzureSubscription subscription)
        {
            if (subscription == null || subscription.SubscriptionId == null)
            {
                return(null);
            }

            if (subscription.currentCloudStorageAccount != null)
            {
                return(subscription.currentCloudStorageAccount as CloudStorageAccount);
            }
            else
            {
                using (var storageClient = subscription.CreateClient <StorageManagementClient>())
                {
                    var storageServiceResponse = storageClient.StorageAccounts.Get(subscription.currentStorageAccountName);
                    var storageKeysResponse    = storageClient.StorageAccounts.GetKeys(subscription.currentStorageAccountName);

                    subscription.currentCloudStorageAccount = new CloudStorageAccount(
                        new StorageCredentials(storageServiceResponse.StorageAccount.Name, storageKeysResponse.PrimaryKey),
                        GeneralUtilities.CreateHttpsEndpoint(storageServiceResponse.StorageAccount.Properties.Endpoints[0].ToString()),
                        GeneralUtilities.CreateHttpsEndpoint(storageServiceResponse.StorageAccount.Properties.Endpoints[1].ToString()),
                        GeneralUtilities.CreateHttpsEndpoint(storageServiceResponse.StorageAccount.Properties.Endpoints[2].ToString()));

                    return(subscription.currentCloudStorageAccount as CloudStorageAccount);
                }
            }
        }
示例#2
0
        public virtual Uri UploadPackageToBlob(
            StorageManagementClient storageClient,
            string storageName,
            string packagePath,
            BlobRequestOptions blobRequestOptions)
        {
            StorageAccountGetKeysResponse keys = storageClient.StorageAccounts.GetKeys(storageName);
            string storageKey      = keys.PrimaryKey;
            var    storageService  = storageClient.StorageAccounts.Get(storageName);
            Uri    blobEndpointUri = storageService.StorageAccount.Properties.Endpoints[0];

            return(UploadFile(storageName,
                              GeneralUtilities.CreateHttpsEndpoint(blobEndpointUri.ToString()),
                              storageKey, packagePath, blobRequestOptions));
        }
示例#3
0
        public virtual Uri UploadPackageToBlob(
            IServiceManagement channel,
            string storageName,
            string subscriptionId,
            string packagePath,
            BlobRequestOptions blobRequestOptions)
        {
            StorageService storageService = channel.GetStorageKeys(subscriptionId, storageName);
            string         storageKey     = storageService.StorageServiceKeys.Primary;

            storageService = channel.GetStorageService(subscriptionId, storageName);
            string blobEndpointUri = storageService.StorageServiceProperties.Endpoints[0];

            return(UploadFile(
                       storageName,
                       GeneralUtilities.CreateHttpsEndpoint(blobEndpointUri), storageKey, packagePath, blobRequestOptions));
        }
示例#4
0
        public virtual void DeletePackageFromBlob(
            IServiceManagement channel,
            string storageName,
            string subscriptionId,
            Uri packageUri)
        {
            var storageService = channel.GetStorageKeys(subscriptionId, storageName);
            var storageKey     = storageService.StorageServiceKeys.Primary;

            storageService = channel.GetStorageService(subscriptionId, storageName);
            var blobStorageEndpoint = GeneralUtilities.CreateHttpsEndpoint(
                storageService.StorageServiceProperties.Endpoints.Find(p => p.Contains(BlobEndpointIdentifier)));
            var        credentials = new StorageCredentials(storageName, storageKey);
            var        client      = new CloudBlobClient(blobStorageEndpoint, credentials);
            ICloudBlob blob        = client.GetBlobReferenceFromServer(packageUri);

            blob.DeleteIfExists();
        }