/// <summary> /// Exports the list of containers in a given storage account /// </summary> /// <param name="account">Storage account to get the name and key of the storage account whose blobs are to be exported</param> /// <returns>List of storage account containers</returns> private List <Container> ExportStorageAccountContainers(Microsoft.WindowsAzure.Management.Storage.Models.StorageAccount account) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; List <Container> containers = new List <Container>(); try { string srcStorageAccountKey = GetStorageAccountKeysFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials, account.Name).PrimaryKey; Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount( new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(account.Name, srcStorageAccountKey), true); CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient(); foreach (var item in cloudBlobClient.ListContainers()) { List <Blob> blobs = new List <Blob>(); containers.Add(new Container { ContainerName = item.Name, BlobDetails = ExportBlobs(item.ListBlobs(null, false), blobs) }); } return(containers); } catch (Exception ex) { Logger.Error(methodName, ex); throw; } }
private static bool VerifyStorageAccount( StorageAccount storageCreated, string storageAccountName, string label, string description, string location, string accountType) { bool verified = true; verified &= storageCreated.Name == storageAccountName; verified &= storageCreated.Uri.ToString().Contains(storageAccountName); verified &= storageCreated.Name == storageAccountName; verified &= storageCreated.Properties.Label == label; verified &= storageCreated.Properties.Description == description; verified &= storageCreated.Properties.Location == location; verified &= storageCreated.Properties.AccountType == accountType; return verified; }
public static string StorageAccountAsString(StorageAccount sa) { var sb = new StringBuilder(); sb.AppendLine("Name: ".PadRight(30) + sa.Name); sb.AppendLine("Location: ".PadRight(30) + sa.Properties.Location); return sb.ToString(); }
private static bool TryGetStorageAccount(IStorageManagementClient storageClient, string storageAccountName, out StorageAccount storageAccount) { try { storageAccount = storageClient.StorageAccounts.Get(storageAccountName).StorageAccount; } catch { storageAccount = null; } return storageAccount != null; }
/// <summary> /// Create storage blob. /// Note: storage container name should be in lower case /// </summary> /// <param name="service"></param> /// <param name="blobName"></param> /// <param name="containerName"></param> /// <returns></returns> public CloudBlockBlob CreateBlob(StorageAccount service, string blobName, string containerName = "") { return service.CreateBlob(blobName, containerName); }
/// <summary> /// Create storage container. /// Note: storage container name should be in lower case /// </summary> /// <param name="service"></param> /// <param name="containerName"></param> /// <returns></returns> public CloudBlobContainer CreateContainer(StorageAccount service, string containerName = "") { return service.CreateContainer(containerName); }
internal static void LogObject(this TestEasyLog log, StorageAccount storageService) { if (storageService == null) return; if (!string.IsNullOrEmpty(storageService.Name)) { log.Info(string.Format("StorageService Name:{0}", storageService.Name)); } log.Info(string.Format("StorageService Url:{0}", storageService.Uri)); }