/// <summary> /// Checks if $MetricsCapacityBlob table exists in a storage account. /// </summary> /// <param name="cloudStorageAccount">The cloud storage account.</param> /// <returns></returns> public static bool MetricsTableExists(this CloudStorageAccount cloudStorageAccount) { CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient(); var cloudTableClient = cloudStorageAccount.CreateCloudTableClient(); var table = cloudTableClient.GetTableReference("$MetricsCapacityBlob"); return table.Exists(); }
/// <summary> /// Enables the storage analytics for blob service. /// </summary> /// <param name="cloudStorageAccount">The cloud storage account.</param> public static void EnableBlobStorageAnalytics(this CloudStorageAccount cloudStorageAccount) { CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); ServiceProperties serviceProperties = cloudBlobClient.GetServiceProperties(); serviceProperties.Metrics.MetricsLevel = MetricsLevel.Service; serviceProperties.Metrics.RetentionDays = RetentionDays.Value; cloudBlobClient.SetServiceProperties(serviceProperties); }
public static void DeleteAllBlobContainers(this CloudStorageAccount storageAccount, string prefix = null) { var blobClient = storageAccount.CreateCloudBlobClient(); var containers = blobClient.ListContainers(prefix ?? ""); foreach (var container in containers) { container.DeleteIfExists(); } }
public static void Ensure(this CloudStorageAccount account, IEnumerable<string> tables = null, IEnumerable<string> containers = null, IEnumerable<string> queues = null) { var tableClient = account.CreateCloudTableClient(); var blobClient = account.CreateCloudBlobClient(); var queueClient = account.CreateCloudQueueClient(); if (tables != null) foreach (var table in tables) tableClient.CreateTableIfNotExist(table); if (containers != null) foreach (var container in containers) blobClient.GetContainerReference(container).CreateIfNotExist(); if (queues != null) foreach (var queue in queues) queueClient.GetQueueReference(queue).CreateIfNotExist(); }
/// <summary> /// Tries the get user data capacity metric for blob service. /// </summary> /// <param name="cloudStorageAccount">The cloud storage account.</param> /// <param name="fromDate">Date from which retrieve capacity information.</param> /// <param name="analyticsEnabled">if set to <c>true</c> if analytics enabled.</param> /// <returns></returns> public static IEnumerable<Tuple<DateTime, long>> TryGetBlobUserDataCapacityMetric(this CloudStorageAccount cloudStorageAccount, DateTime fromDate, out bool analyticsEnabled) { CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient(); var serviceProperties = blobClient.GetServiceProperties(); analyticsEnabled = serviceProperties.Metrics.MetricsLevel == MetricsLevel.Service; if (!analyticsEnabled) { return null; } var cloudTableClient = cloudStorageAccount.CreateCloudTableClient(); var table = cloudTableClient.GetTableReference("$MetricsCapacityBlob"); //Selecting TableQuery<MetricsCapacityBlob> query = new TableQuery<MetricsCapacityBlob>().Where(TableQuery.CombineFilters(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThan, (fromDate.ToUniversalTime()).ToString("yyyyMMddTHH00")), TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, "data"))); return table.ExecuteQuery(query).Select(c => new Tuple<DateTime, long>(c.Timestamp.Date, c.Capacity)); }