public async Task DataCleanup_DeleteTables_NoTablesExist_ShouldWork() { // Setup CloudTableClient tableClient = TableHelper.CreateCloudTableClient(StorageConnectionString); var parameters = new DataCleanupParameters() { StorageConnectionString = StorageConnectionString }; var content = new StringContent(JsonSerializer.Serialize(parameters), Encoding.UTF8, "application/json"); // - Removes pre-existing tables IEnumerable <CloudTable> tableResult1 = tableClient.ListTables(); if (tableResult1.Count() != 0) { HttpResponseMessage response1 = await _clientFixture.GetClient().PostAsync(_UrlDeleteTables, content); response1.StatusCode.Should().Be(HttpStatusCode.OK); tableResult1 = tableClient.ListTables(); tableResult1.Should().HaveCount(0); } // Act HttpResponseMessage response2 = await _clientFixture.GetClient().PostAsync(_UrlDeleteTables, content); // Verify response2.StatusCode.Should().Be(HttpStatusCode.OK); IEnumerable <CloudTable> tableResult2 = tableClient.ListTables(); tableResult2.Should().HaveCount(0); }
public bool ValidateCredentials() { // Expect exception when credentials are incorrect var tables = _client.ListTables(); return(tables.Count() >= 0); // Make sure the (possibly internal) IQueryable evaluates }
public bool ValidateCredentials() { // Throws exception if host does not exist Dns.GetHostEntry(_client.Credentials.AccountName + ".table.core.windows.net"); // Expect exception when credentials are incorrect var tables = _client.ListTables(); return(tables.Count() >= 0); // Make sure the (possibly internal) IQueryable evaluates }
/// <summary> /// Lists all tables of the specified storageAccount /// </summary> private void GetAllTableName() { try { CloudTableClient client = storageAccount.CreateCloudTableClient(); ckb_TableName.Items.Clear(); List <string> lstSelectedTableName = new List <string>(); if (ViewState["SelectedTableName"] != null) { lstSelectedTableName = (List <string>)ViewState["SelectedTableName"]; } foreach (CloudTable table in client.ListTables()) { ListItem item = new ListItem(); item.Text = table.Name; item.Value = table.Name; ckb_TableName.Items.Add(item); if (lstSelectedTableName.Contains(item.Text)) { item.Selected = true; } } ckb_TableName_SelectedIndexChanged(null, null); } catch (Exception ex) { } }
private Task CleanAsync(CloudTableClient client) { var deletes = client.ListTables() .Where(table => table.Name.StartsWith(Configuration.Indexer.StorageNamespace, StringComparison.InvariantCultureIgnoreCase)) .SelectMany(table => table.ExecuteQuery(new TableQuery()).Select(e => new { Entity = e, Table = table })) .Select(async table => { try { await table.Table.ExecuteAsync(TableOperation.Delete(table.Entity)); } catch (StorageException ex) { if (ex.RequestInformation != null && ex.RequestInformation.HttpStatusCode == 404) { return; } throw; } }) .ToArray(); return(Task.WhenAll(deletes)); }
private void Delete_All_Button_Click(object sender, RoutedEventArgs e) { foreach (var table in tableClient.ListTables()) { table.DeleteIfExists(); } }
/// <summary> /// Clean tables /// /// Delete all the existing tables in the given storage account /// </summary> /// <param name="azureConnectionString">azure table connection string</param> /// <returns>task</returns> public static async Task Clean(string azureConnectionString) { Console.WriteLine("Deleting all tables in Azure Table Store..."); CloudStorageAccount account = CloudStorageAccount.Parse(azureConnectionString); CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); foreach (var result in tableClient.ListTables()) { // filter out Azure diagnostics tables if (IsWADTable(result.Name)) { continue; } // if the table name does not have a prefix match on OBA table names, // then we should not delete it if (!IsOBATable(result.Name)) { continue; } await result.DeleteIfExistsAsync(); Console.WriteLine(" " + result.Name + " - Table Deleted"); } }
public void DropTables() { foreach (var table in _tableClient.ListTables()) { table.DeleteIfExists(); } }
private static void listarTablas() { var connectionString = "DefaultEndpointsProtocol=https;AccountName=hefesoft;AccountKey=dodn17DT7hBi3lXrWlvXihLS9J7xuItHLIpWLBZn2QEMdBHm02Lqxr055rNCpP5z3FhfcjjX3MhPy1Npk3VF3Q=="; CloudStorageAccount account = CloudStorageAccount.Parse(connectionString); CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); IEnumerable <CloudTable> tables = tableClient.ListTables(); //validarTableExist(tableClient); CloudTable table = tableClient.GetTableReference("TmKeys"); table.CreateIfNotExists(); foreach (CloudTable item in tables) { var policy = sharedKey(); string sharedAccessSignature = item.GetSharedAccessSignature(policy); // Create a new customer entity. SharedKeyEntity shared = new SharedKeyEntity(item.Name, "1"); shared.Key = sharedAccessSignature; shared.Expire = policy.SharedAccessExpiryTime.Value.ToString(); if (policy.SharedAccessStartTime.HasValue) { shared.Start = policy.SharedAccessStartTime.Value.ToString(); } // Create the TableOperation that inserts the customer entity. TableOperation insertOperation = TableOperation.Insert(shared); // Execute the insert operation. table.Execute(insertOperation); } }
public static void EncryptTables(CloudStorageAccount storageAccount, AESEncryption encrypt) { // Create the table client. // Table has no snapshot so nothing to disable. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); foreach (CloudTable table in tableClient.ListTables()) { // Retrieve reference to a previously created tables. CloudTable tbl = tableClient.GetTableReference(table.Name); TableQuery query = new TableQuery(); foreach (ITableEntity entity in table.ExecuteQuery(query)) { // Create a retrieve operation that takes a customer entity. TableOperation retrieveOperation = TableOperation.Retrieve(entity.PartitionKey, entity.RowKey); // Execute the operation. TableResult retrievedResult = table.Execute(retrieveOperation); // Assign the result to a CustomerEntity object. ITableEntity updateEntity = (ITableEntity)retrievedResult.Result; if (updateEntity != null) { //encrypt the entity's properties (patition & row) EncryptFitTableConstrains(entity, tbl, encrypt); } } Console.Read(); //keep console open for dubug } }
static void Main(string[] args) { // Parse the connection string and return a reference to the storage account. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString")); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); IEnumerable <CloudTable> list = tableClient.ListTables("WAD"); foreach (var tab in list) { Console.WriteLine(tab.Name); } // Create the CloudTable object that represents the "people" table. CloudTable table = tableClient.GetTableReference("WADMetricsPT1HP10DV2S20160823"); // Construct the query operation for all customer entities where PartitionKey="***". TableQuery <WADMerticsEntity> query = new TableQuery <WADMerticsEntity>(); //.Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith")); // Print the fields for each customer. foreach (WADMerticsEntity entity in table.ExecuteQuery(query)) { Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey, entity.RoleInstance, entity.CounterName); } Console.ReadKey(); }
/// <summary> /// Try connect to Azure Table Service. Use for check connection /// </summary> /// <param name="accountName">Storage account name</param> /// <param name="key">Storage account key</param> /// <returns></returns> public static Boolean TryConnect(String accountName, String key) { if (String.IsNullOrEmpty(accountName)) { throw new ArgumentNullException("accountName"); } if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } CloudTableClient cloudTableClient = GetClient(accountName, key); Boolean isCanConnect = false; try { //try list tables for test connection cloudTableClient.Timeout = new TimeSpan(0, 0, 0, 30); string listTables = cloudTableClient.ListTables().FirstOrDefault(); isCanConnect = true; } catch (Exception exception) { //TODO: log } return(isCanConnect); }
private IEnumerable <Task> DeleteAllTables() { CloudTableClient tableClient = _storageAccount.CreateCloudTableClient(); IEnumerable <CloudTable> allTables = tableClient.ListTables(); return(allTables.Select(t => Task.Run(() => t.DeleteAndWaitForCompletion()))); }
private void Connect_Click(object sender, EventArgs e) { storageConnectionString = String.Format(storageConnectionString, AccountName.Text, AccountKey.Text); CloudStorageAccount storageAccount; try { storageAccount = CloudStorageAccount.Parse(storageConnectionString); } catch (FormatException fex) { MessageBox.Show("유효한 계정 정보가 아닙니다\n\n" + fex.Message, "경고", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ConnectState.ForeColor = System.Drawing.Color.Blue; ConnectState.Text = "* 연결되었습니다"; // Create the table client. tableClient = storageAccount.CreateCloudTableClient(); IEnumerable <CloudTable> list = tableClient.ListTables(tablePrefix); List <string> tableList = new List <string>(); foreach (var tab in list) { tableList.Add(tab.Name); } TablesList.DataSource = tableList; }
/// <summary> /// Lists all tables of the specified storageAccount /// </summary> private void GetAllTableName() { CloudTableClient client = storageAccount.CreateCloudTableClient(); ckb_TableName.Items.Clear(); List <string> lstSelectedTableName = new List <string>(); if (ViewState["SelectedTableName"] != null) { lstSelectedTableName = (List <string>)ViewState["SelectedTableName"]; } foreach (CloudTable table in client.ListTables()) { if (!table.Name.StartsWith("PII")) { ListItem item = new ListItem(); item.Text = table.Name; item.Value = table.Name; ckb_TableName.Items.Add(item); if (lstSelectedTableName.Contains(item.Text)) { item.Selected = true; } } } }
private static void ClearPlatformStorageAccounts() { //var response = new DataAccessResponseType { isSuccess = false }; //Loop through all tables named by schema for this account and delete CloudTableClient cloudTableClient = Sahara.Core.Settings.Azure.Storage.StorageConnections.PlatformStorage.CreateCloudTableClient(); //Create and set retry policy IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 16); //IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 3); cloudTableClient.DefaultRequestOptions.RetryPolicy = exponentialRetryPolicy; IEnumerable <CloudTable> tables = cloudTableClient.ListTables(); foreach (CloudTable table in tables) { try { table.Delete(); } catch { //response.isSuccess = false; } } }
/// <summary> /// Validate the list permission in sastoken for the specified table service /// </summary> internal void ValidateTableListWithSasToken(string sasToken, bool useHttps = true) { Test.Info("Verify table list permission"); CloudStorageAccount sasAccount = TestBase.GetStorageAccountWithSasToken(account.Credentials.AccountName, sasToken, useHttps); CloudTableClient sasClient = sasAccount.CreateCloudTableClient(); sasClient.ListTables().Count(); }
public Task <IEnumerable <Record> > GetAsync() { CloudTable table = _tableClient.ListTables() .FirstOrDefault(t => t.Name == TableName); if (table == null) { return(default);
public static IEnumerable <string> GetAll(string account, string key) { CloudTableClient tableClient = Client.GetTableClient(account, key); foreach (CloudTable table in tableClient.ListTables()) { yield return(table.Name); } }
private static List<string> GetTablesNameForAzureSubscription(string connectionString) { CloudStorageAccount account =CloudStorageAccount .Parse(connectionString); CloudTableClient tableClient = new CloudTableClient (account.TableEndpoint.ToString(), account.Credentials); var result = tableClient.ListTables(); return result.ToList(); }
/// <summary> /// List all table. /// </summary> /// <returns>IEnumerable<CloudTable></returns> public IEnumerable <CloudTable> ListAllContainer() { IEnumerable <CloudTable> listContainer = tableClient.ListTables(); foreach (CloudTable cloudTable in listContainer) { Console.WriteLine("Cloud Table:{0},URL:{1}", cloudTable.Name, cloudTable.Uri); } return(listContainer); }
public async Task TearDown() { foreach (var table in tableClient.ListTables()) { if (table.Name.StartsWith(tableNamePrefix)) { await table.DeleteAsync(); } } await blobServiceClient.DeleteBlobContainerAsync(containerName); }
public static void iterate_table(CloudStorageAccount storageAccount) { // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); foreach (CloudTable table in tableClient.ListTables()) { // Retrieve reference to a previously created tables. CloudTable tbl = tableClient.GetTableReference(table.Name); Console.WriteLine(tbl); } }
internal List <CloudTable> GetAllTableNamesForAzureAccount(bool removeWhiteList) { CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString); CloudTableClient tableClient = new CloudTableClient(storageAccount.TableStorageUri, storageAccount.Credentials); IEnumerable <CloudTable> tables = tableClient.ListTables().Where(a => !a.Name.StartsWith("WAD")); if (removeWhiteList) { return(RemoveWhiteListTables(tables, TablesToExclude).ToList()); } return(tables.ToList()); }
private void Clean(CloudTableClient client) { foreach (var table in client.ListTables()) { if (table.Name.StartsWith(Configuration.Indexer.StorageNamespace, StringComparison.InvariantCultureIgnoreCase)) { foreach (var entity in table.ExecuteQuery(new TableQuery())) { table.Execute(TableOperation.Delete(entity)); } } } }
public static async Task <HttpResponseMessage> QueueUpBackupPartitions( [Property(Name = IdPropertyName)] IRef <RepositoryBackup> repositoryBackupRef, [Property(Name = StorageSettingCopyFromPropertyName)] string storageSettingCopyFrom, [Property(Name = StorageSettingCopyToPropertyName)] string storageSettingCopyTo, [Resource] RepositoryBackup repositoryBackup, AzureApplication application, RequestMessage <TableBackup> requestQuery, HttpRequestMessage request, EastFive.Analytics.ILogger logger, MultipartResponseAsync <InvocationMessage> onQueued, AlreadyExistsResponse onAlreadyExists) { logger.Trace($"Cleaning backup results"); var repo = AzureTableDriverDynamic.FromStorageString(storageSettingCopyTo); await DeleteAllAsync(GetRepository(storageSettingCopyTo)); CloudStorageAccount account = CloudStorageAccount .Parse(storageSettingCopyFrom); CloudTableClient tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); return(await await repositoryBackup.StorageCreateAsync( (discard) => { var resourceInfoToProcess = tableClient .ListTables() .Distinct() .Select( async cloudTable => { var tableBackup = new TableBackup() { tableBackupRef = Ref <TableBackup> .NewRef(), backup = repositoryBackupRef, tableName = cloudTable.Name, when = DateTime.UtcNow, }; var invocationMessage = await requestQuery .HttpPost(tableBackup) .CompileRequest(request) .FunctionAsync(); logger.Trace($"Invocation[{invocationMessage.id}] will backup table `{tableBackup.tableName}`."); return invocationMessage; }) .AsyncEnumerable(); return onQueued(resourceInfoToProcess); }, () => onAlreadyExists().AsTask())); }
public static void track() { try { if (LabStarter.Properties.Settings.Default["CopyId"] == string.Empty) { LabStarter.Properties.Settings.Default["CopyId"] = Guid.NewGuid().ToString(); LabStarter.Properties.Settings.Default.Save(); } if (LabStarter.Properties.Settings.Default["IpAddress"] == string.Empty) { LabStarter.Properties.Settings.Default["IpAddress"] = GetLocalIPAddress().ToString(); LabStarter.Properties.Settings.Default.Save(); } // Parse the connection string and return a reference to the storage account. CloudStorageAccount storageAccount = CloudStorageAccount.Parse( //CloudConfigurationManager.GetSetting("StorageConnectionString") ConfigurationSettings.AppSettings["StorageConnectionString"] ); // Create the table client. CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = null; string tableReference = ConfigurationSettings.AppSettings["ExamName"]; table = tableClient.GetTableReference(tableReference); // Retrieve a reference to the table. if (tableClient.ListTables(tableReference).Count() < 1) { // Create the table if it doesn't exist. table.CreateIfNotExists(); } string studentID = ConfigurationSettings.AppSettings["StudentId"]; string studentName = ConfigurationSettings.AppSettings["StudentName"]; StudentEntity student = new StudentEntity(studentID, studentName); // Create the TableOperation object that inserts the student entity. TableOperation insertOperation = TableOperation.Insert(student); // Execute the insert operation. var result = table.Execute(insertOperation); recordLocalActivity(student); Debug.WriteLine(result.Result); } catch (Exception ex) { Debug.WriteLine(" Exception " + ex.Message); } }
private static void listTables(string strtsWith) { Console.WriteLine("List tables which start with '{0}'", strtsWith); CloudTableClient tableClient = new CloudTableClient(m_StorageAccount.TableEndpoint, m_StorageAccount.Credentials); var tables = tableClient.ListTables(strtsWith); foreach (var tbl in tables) { Console.WriteLine(tbl.Name); } }
public List <string> PlsTableNames() { string sConnectionString = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", m_sAccountName, m_sAccountKey); try { m_csa = CloudStorageAccount.Parse(sConnectionString); if (m_csa == null) { return(null); } m_ctc = m_csa.CreateCloudTableClient(); if (m_ctc == null) { return(null); } // trye to enumerate the tables } catch { return(null); } List <string> pls; try { IEnumerable <CloudTable> plct = m_ctc.ListTables(); m_plct = new List <CloudTable>(); pls = new List <string>(); foreach (CloudTable ct in plct) { m_plct.Add(ct); pls.Add(ct.Name); } } catch { return(null); } return(pls); }
internal static DataAccessResponseType DestroyTableStorageData(Account account) { var response = new DataAccessResponseType { isSuccess = false }; //Loop through all tables named by schema for this account and delete //CloudTableClient cloudTableClient = Sahara.Core.Settings.Azure.Storage.StorageConnections.AccountsStorage.CreateCloudTableClient(); CloudTableClient cloudTableClient = Settings.Azure.Storage.GetStoragePartitionAccount(account.StoragePartition).CreateCloudTableClient(); //Create and set retry policy IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 16); //IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 3); cloudTableClient.DefaultRequestOptions.RetryPolicy = exponentialRetryPolicy; IEnumerable <CloudTable> tables = cloudTableClient.ListTables(Sahara.Core.Common.Methods.SchemaNames.AccountIdToTableStorageName(account.AccountID.ToString())); foreach (CloudTable table in tables) { try { table.Delete(); } catch { response.isSuccess = false; PlatformLogManager.LogActivity( CategoryType.ManualTask, ActivityType.ManualTask_TableStorage, "Table(s) Deletion Failed for schema" + Sahara.Core.Common.Methods.SchemaNames.AccountIdToTableStorageName(account.AccountID.ToString()), "Please delete all tables for schema '" + Sahara.Core.Common.Methods.SchemaNames.AccountIdToTableStorageName(account.AccountID.ToString()) + "' manually.", null, null, null, null, null, null, System.Reflection.MethodBase.GetCurrentMethod().ToString() ); } } return(response); }