public async Task <NewSessionResultChats> GetChatsSessionAsync(int count) { string guid = Guid.NewGuid().ToString(); _bufferBlocksChat[guid] = new BufferBlock <string>(); List <string> chats = new List <string>(); List <string> output = new List <string>(); TableContinuationToken token = null; var tables = await tableClient.ListTablesSegmentedAsync(token); foreach (var table in tables) { if (table.Name != "users" && table.Name != "activeUsers") { output.Add(table.Name); } } return(new NewSessionResultChats { sessionId = guid, chats = output }); }
/// <summary> /// Returns an enumerable collection of tables in the storage account asynchronously. /// </summary> /// <param name="tableClient">Cloud table client.</param> /// <param name="cloudTables">List of cloud tables.</param> /// <param name="prefix">The table name prefix.</param> /// <param name="maxResults"> /// A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the /// per-operation limit of 5000. If this value is zero the maximum possible number of results will be returned, up to 5000. /// </param> /// <param name="continuationToken">Continuation token.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns> /// An enumerable collection of tables that are retrieved. /// </returns> private static Task <List <CloudTable> > ListTablesImplAsync( this CloudTableClient tableClient, List <CloudTable> cloudTables, string prefix, int?maxResults, TableContinuationToken continuationToken, CancellationToken cancellationToken = default(CancellationToken)) { return(tableClient .ListTablesSegmentedAsync(prefix, maxResults, continuationToken, null, null, cancellationToken) .Then(result => { cancellationToken.ThrowIfCancellationRequested(); cloudTables.AddRange(result.Results); // Checks whether maxresults entities has been received if (maxResults.HasValue && cloudTables.Count >= maxResults.Value) { return TaskHelpers.FromResult(cloudTables.Take(maxResults.Value).ToList()); } // Checks whether enumeration has been completed if (result.ContinuationToken != null) { return ListTablesImplAsync(tableClient, cloudTables, prefix, maxResults, result.ContinuationToken, cancellationToken); } return TaskHelpers.FromResult(cloudTables); })); }
public bool Connect() { TableContinuationToken tableToken = null; CancellationToken cancellationToken = new CancellationToken(); if (!Config.SasEndpointInfo.IsPopulated()) { Log.Warning("no table or token info. exiting:", Config.SasEndpointInfo); return(false); } try { CloudTable table = new CloudTable(new Uri(Config.SasEndpointInfo.TableEndpoint + Config.SasEndpointInfo.SasToken)); _tableClient = table.ServiceClient; TableResultSegment tables = _tableClient.ListTablesSegmentedAsync( null, MaxResults, tableToken, new TableRequestOptions(), null, cancellationToken).Result; TableList.AddRange(tables); return(true); } catch (Exception e) { Log.Exception($"{e}"); return(false); } }
private async Task <IEnumerable <CloudTable> > GetTables(string eyeColor = null) { var result = new List <CloudTable>(); if (string.IsNullOrEmpty(eyeColor)) { TableContinuationToken continuationToken = null; do { var tempResult = await _tableClient.ListTablesSegmentedAsync(_tableNamePrefix, continuationToken); result.AddRange(tempResult); } while (continuationToken != null); } else { var tableName = $"{_tableNamePrefix}{eyeColor}"; var table = _tableClient.GetTableReference(tableName); var exists = await table.ExistsAsync(); if (exists) { result.Add(table); } } return(result); }
public static IEnumerableAsync <CloudTable> GetTables(this CloudTableClient tableClient) { var ranOnce = false; var continuationToken = default(TableContinuationToken); return(EnumerableAsync.YieldBatch <CloudTable>( async(yieldReturn, yieldBreak) => { if (continuationToken.IsDefaultOrNull()) { if (ranOnce) { return yieldBreak; } } ranOnce = true; var segment = await tableClient.ListTablesSegmentedAsync(continuationToken); continuationToken = segment.ContinuationToken; if (!segment.Results.Any()) { return yieldBreak; } return yieldReturn(segment.Results.ToArray()); })); }
/// <summary> /// Lists tables in the storage account whose names begin with the specified prefix. /// </summary> /// <param name="tableClient">The Table service client object.</param> /// <param name="prefix">The table name prefix.</param> /// <returns>A Task object</returns> private static async Task ListTablesWithPrefix(CloudTableClient tableClient, string prefix) { Console.WriteLine("List all tables beginning with prefix {0}:", prefix); TableContinuationToken continuationToken = null; TableResultSegment resultSegment = null; try { do { // List tables beginning with the specified prefix. // Passing in null for the maxResults parameter returns the maximum number of results (up to 5000). resultSegment = await tableClient.ListTablesSegmentedAsync( prefix, null, continuationToken, null, null); // Enumerate the tables returned. foreach (var table in resultSegment.Results) { Console.WriteLine("\tTable:" + table.Name); } }while (continuationToken != null); Console.WriteLine(); } catch (StorageException e) { Console.WriteLine(e.Message); Console.ReadLine(); throw; } }
public async Task <List <string> > GetTableNames(string connectionString) { var tableList = new List <string>(); if (CloudStorageAccount.TryParse(connectionString, out account)) { var tableClient = new CloudTableClient(account.TableEndpoint, account.Credentials); TableContinuationToken token = null; try { do { var segmentedTablesList = await tableClient.ListTablesSegmentedAsync(token); tableList.AddRange(segmentedTablesList.Results.Select(x => x.Name)); token = segmentedTablesList.ContinuationToken; } while (token != null); } catch (Exception e) { await _log.WriteErrorAsync(nameof(AzureTableCheckService), $"Getting table names - account:\"{account.Credentials.AccountName}\"", e); } } return(tableList); }
private static async Task <TResult> FindAllTablesAsync <TResult>(this CloudTableClient sourceClient, Func <bool> stopCalled, Func <CloudTable[], TResult> onSuccess, Func <string, TResult> onFailure) { var context = new OperationContext(); TableContinuationToken token = null; var tables = new List <CloudTable>(); while (true) { if (stopCalled()) { return(onFailure($"listing tables stopped on {sourceClient.Credentials.AccountName}")); } try { var segment = await sourceClient.ListTablesSegmentedAsync(null, null, token, TableCopyOptions.requestOptions, context); var results = segment.Results.ToArray(); tables.AddRange(results); token = segment.ContinuationToken; if (null == token) { return(onSuccess(tables.ToArray())); } } catch (Exception e) { return(onFailure($"Exception listing all tables, Detail: {e.Message}")); } } }
public void DownloadTables(string tablePrefix = "") { Log.Info($"enumerating tables: with prefix {tablePrefix}"); int resultsCount = 0; TableContinuationToken token = new TableContinuationToken(); tablePrefix = string.IsNullOrEmpty(Config.UriFilter) ? tablePrefix : Config.UriFilter; while (token != null) { try { Task <TableResultSegment> tableSegment = _tableClient.ListTablesSegmentedAsync(tablePrefix, MaxResults, token, null, null); Task <TableResultSegment> task = DownloadTablesSegmentAsync(tableSegment, Config.NodeFilter); token = task.Result.ContinuationToken; resultsCount += task.Result.Results.Count; } catch (Exception e) { Log.Exception($"exception in table enumeration { e }"); break; } } Log.Info("finished table enumeration"); _tableTasks.Wait(); Log.Highlight($"processed table count:{ resultsCount.ToString("#,#") } minutes:{ (DateTime.Now - _instance.StartTime).TotalMinutes.ToString("F3") } "); }
//ok public static async Task <TResult> FindAllTablesAsync <TResult>(this CloudTableClient sourceClient, Func <CloudTable[], TResult> onSuccess, Func <string, TResult> onFailure) { var context = CreateContext(); TableContinuationToken token = null; var tables = new List <CloudTable>(); while (true) { try { var segment = await sourceClient.ListTablesSegmentedAsync(null, null, token, RetryOptions, context); var results = segment.Results.ToArray(); tables.AddRange(results); token = segment.ContinuationToken; if (null == token) { return(onSuccess(tables.ToArray())); } } catch (Exception e) { return(onFailure($"Exception listing all tables, Detail: {e.Message}")); } } }
protected override async Task <LoadMoreResult> LoadMoreAsync(CollectionQuery query, object continuationToken) { var next = await client.ListTablesSegmentedAsync(query.Filter, continuationToken as TableContinuationToken); var result = new LoadMoreResult(next.Results.Select(r => r as object).ToList(), next.ContinuationToken); return(result); }
private async Task Copy(CloudTableClient source, IHydra target, CancellationToken token) { var response = await source.ListTablesSegmentedAsync(null); do { foreach (var sourceItem in response.Results.Where(x => string.IsNullOrWhiteSpace(Options.Object) || x.Name.EqualsCi(Options.Object))) { _logger.LogInformation($"Processing {sourceItem.GetType().Name} '{sourceItem.Name}'."); var processed = 0L; var query = new TableQuery <DynamicTableEntity>(); var entities = await sourceItem.ExecuteQuerySegmentedAsync(query, null); do { ApplyOverrides(entities); foreach (var group in entities.GroupBy(x => x.PartitionKey)) { var targetClient = target.CreateTableClient(group.Key); var targetItem = targetClient.GetTableReference(sourceItem.Name); await _policyCreate.ExecuteAsync(async() => await targetItem.CreateIfNotExistsAsync()); foreach (var batch in group.Batch(100)) { var operation = new TableBatchOperation(); batch.ForEach(x => operation.Insert(x)); await targetItem.ExecuteBatchAsync(operation); } } processed += entities.LongCount(); _logger.LogInformation($"Processed {sourceItem.GetType().Name} '{sourceItem.Name}' {processed} entities."); entities = await sourceItem.ExecuteQuerySegmentedAsync(query, entities.ContinuationToken); }while (entities.ContinuationToken != null && !token.IsCancellationRequested); } response = await source.ListTablesSegmentedAsync(response.ContinuationToken); }while (response.ContinuationToken != null && !token.IsCancellationRequested); }
/// <summary> /// Lists tables in the storage account, optionally whose names begin with the specified prefix. /// </summary> /// <param name="tableClient">The Table service client object.</param> /// <param name="count">The number of tablenames maximally transmitted. </param> /// <param name="prefix">The table name prefix. In case of null or "" no prefix is used. </param> /// <returns>A Task object</returns> public static async Task <TableQueryResponse> ListTablesWithPrefix(CloudTableClient tableClient, int count, string prefix = "") { TableContinuationToken continuationToken = null; TableResultSegment resultSegment = null; TableQueryResponse response = new TableQueryResponse { ListResult = null, ErrorMessage = "" }; List <string> localTables = new List <string>(); try { do { // List tables beginning with the specified prefix. // Passing in null for the maxResults parameter returns the maximum number of results (up to 5000). if ((prefix == "") | (prefix == null)) { resultSegment = await tableClient.ListTablesSegmentedAsync( null, count, continuationToken, null, null); } else { resultSegment = await tableClient.ListTablesSegmentedAsync( prefix, count, continuationToken, null, null); } // Enumerate the tables returned. foreach (var table in resultSegment.Results) { localTables.Add(table.Name); } }while (continuationToken != null); response.ListResult = localTables; response.ErrorMessage = ""; return(response); } catch (StorageException e) { response.ListResult = null; response.ErrorMessage = e.Message; return(response); } }
private async Task Clear(CloudTableClient target, CancellationToken token) { var response = await target.ListTablesSegmentedAsync(null); do { foreach (var item in response.Results.Where(x => string.IsNullOrWhiteSpace(Options.Object) || x.Name.EqualsCi(Options.Object))) { var targetItem = target.GetTableReference(item.Name); _logger.LogInformation($"Deleting {item.GetType().Name} '{item.Name}'..."); await targetItem.DeleteAsync(); } response = await target.ListTablesSegmentedAsync(response.ContinuationToken); }while (response.ContinuationToken != null && !token.IsCancellationRequested); }
protected void GetNames(GoogleVisualizationDataTable dataTable, Dictionary <string, int> tableIndex) { int index = 1; bool addDate = true; TableOperation tableOperation = TableOperation.Retrieve <DynamicTableEntity>("Setting", "Name"); CloudTableClient tableClient = AzureStorageExtension.GetCloudTableClient(AzureStorageConfig); string table0 = string.Format("{0}0", AzureStorageConfig.Container); TableContinuationToken token = new TableContinuationToken(); do { var orphanedTables = tableClient.ListTablesSegmentedAsync(AzureStorageConfig.Container, token).Result; token = orphanedTables.ContinuationToken; foreach (CloudTable cloudTable in orphanedTables.Results) { if (cloudTable.Name == table0) { continue; } DynamicTableEntity tdsTableEntity = (DynamicTableEntity)cloudTable.ExecuteAsync(tableOperation).Result.Result; IDictionary <string, EntityProperty> nameInfos = tdsTableEntity.Properties; string name = ""; foreach (KeyValuePair <string, EntityProperty> pInfo in nameInfos) { if (pInfo.Key != "PartitionKey" && pInfo.Key != "RowKey" && pInfo.Key != "Timestamp") { name = pInfo.Value.StringValue; //.GetValue(tdsTableEntity); if (name == null) { break; } if (pInfo.Key == "ADATE") { if (addDate) { dataTable.AddColumn(name, "datetime"); tableIndex.Add(pInfo.Key, 0); addDate = false; } } else { dataTable.AddColumn(name, "number"); tableIndex.Add(pInfo.Key, index++); } } } } }while (token != null); }
/// <summary> /// List azure storage tables /// </summary> /// <param name="prefix">Table name prefix</param> /// <param name="requestOptions">Table request options</param> /// <param name="operationContext">Operation context</param> /// <returns>An enumerable collection of tables that begin with the specified prefix</returns> public IEnumerable <CloudTable> ListTables(string prefix, TableRequestOptions requestOptions, OperationContext operationContext) { //https://ahmet.im/blog/azure-listblobssegmentedasync-listcontainerssegmentedasync-how-to/ TableContinuationToken continuationToken = null; var results = new List <CloudTable>(); do { var response = tableClient.ListTablesSegmentedAsync(prefix, null, continuationToken, requestOptions, operationContext).Result; continuationToken = response.ContinuationToken; results.AddRange(response.Results); } while (continuationToken != null); return(results); }
public static async Task <List <CloudTable> > ListTablesAsync(this CloudTableClient client) { TableContinuationToken continuationToken = null; List <CloudTable> results = new List <CloudTable>(); do { var response = await client.ListTablesSegmentedAsync(continuationToken); continuationToken = response.ContinuationToken; results.AddRange(response.Results); }while (continuationToken != null); return(results); }
internal static async Task <IEnumerable <CloudTable> > ListTablesAsync(CloudTableClient tableClient, string tableNamePrefix) { List <CloudTable> tables = new List <CloudTable>(); TableContinuationToken continuationToken = null; do { var results = await tableClient.ListTablesSegmentedAsync(tableNamePrefix, continuationToken); continuationToken = results.ContinuationToken; tables.AddRange(results.Results); }while (continuationToken != null); return(tables); }
/// <summary> /// Get Tables from Azure Storage. /// </summary> /// <returns>List of Cloud Tables.</returns> public IList <CloudTable> GetTables() { var tables = new List <CloudTable>(); TableContinuationToken token = null; // do { var result = tableClient.ListTablesSegmentedAsync(token).Result; token = result.ContinuationToken; tables.AddRange(result.Results); }while (token != null); // return(tables); }
public static async Task <List <CloudTable> > GetTableListAsync(CloudTableClient tableClient) { TableContinuationToken token = null; var cloudTableList = new List <CloudTable>(); do { TableResultSegment segment = await tableClient.ListTablesSegmentedAsync(token); token = segment.ContinuationToken; cloudTableList.AddRange(segment.Results); }while (token != null); return(cloudTableList); }
// List all tables that we may have handed out. public async Task <CloudTable[]> ListTablesAsync() { List <CloudTable> list = new List <CloudTable>(); TableContinuationToken continuationToken = null; do { var segment = await _tableClient.ListTablesSegmentedAsync(_tableNamePrefix, null, continuationToken, null, null, CancellationToken.None); list.AddRange(segment.Results); continuationToken = segment.ContinuationToken; }while (continuationToken != null); return(list.ToArray()); }
public static async Task <List <string> > ListTablesAsync(string account, string key) { CloudTableClient tableClient = Client.GetTableClient(account, key); TableContinuationToken continuationToken = null; List <CloudTable> results = new List <CloudTable>(); do { var response = await tableClient.ListTablesSegmentedAsync(continuationToken); continuationToken = response.ContinuationToken; results.AddRange(response.Results); }while (continuationToken != null); return(results.Select(t => t.Name).ToList()); }
/// <summary> /// Lists all tables within the storage account. /// </summary> /// <returns>IEnumerable string of table names.</returns> public async Task <IEnumerable <string> > ListTableNames() { var tableNames = new List <string>(); TableContinuationToken continuationToken = null; do { var listResults = await CloudTableClient.ListTablesSegmentedAsync(continuationToken); foreach (var table in listResults.Results) { tableNames.Add(table.Name); } continuationToken = listResults.ContinuationToken; } while (continuationToken != null); return(tableNames); }
public static void ClassCleanup() { var storageAccountProvider = Configuration.GetTestCosmosStorageAccount(); var client = new CloudTableClient(new Uri(storageAccountProvider.TableEndpoint), storageAccountProvider.Credentials); TableContinuationToken token = new TableContinuationToken(); do { var orphanedTables = client.ListTablesSegmentedAsync(_baseTableName, token).Result; token = orphanedTables.ContinuationToken; foreach (CloudTable orphanedTableName in orphanedTables.Results) { client.GetTableReference(orphanedTableName.Name).DeleteIfExistsAsync().Wait(); } }while (token != null); }
public static async Task <List <string> > GetProjects([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "projects")] HttpRequest req, TraceWriter log) { var projects = new List <string>(); TableContinuationToken continuationToken = null; do { var page = await tableClient.ListTablesSegmentedAsync(continuationToken); continuationToken = page.ContinuationToken; projects.AddRange(page.Results .Select(r => r.Name) .Where(r => r != IndexTableName && !r.StartsWith(AzureWebJobsContainerPrefixes)) ); }while (continuationToken != null); return(projects); }
/// <summary> /// Returns the list of table names in this storage /// </summary> /// <returns></returns> public async Task <IReadOnlyCollection <string> > ListTableNamesAsync() { var result = new List <string>(); TableContinuationToken token = null; do { TableResultSegment segment = await _client.ListTablesSegmentedAsync(token); foreach (CloudTable table in segment.Results) { result.Add(table.Name); } token = segment.ContinuationToken; }while(token != null); return(result); }
public void DataClear() { CloudTableClient tableClient = AzureStorageExtension.GetCloudTableClient(AzureStorageConfig); TableContinuationToken token = new TableContinuationToken(); do { var orphanedTables = tableClient.ListTablesSegmentedAsync(AzureStorageConfig.Container, token).Result; token = orphanedTables.ContinuationToken; foreach (CloudTable orphanedTableName in orphanedTables.Results) { orphanedTableName.DeleteAsync(); while (orphanedTableName.ExistsAsync().Result == true) { } } }while (token != null); Thread.Sleep(50000); }
/// <summary> /// List azure storage tables /// </summary> /// <param name="prefix">Table name prefix</param> /// <param name="requestOptions">Table request options</param> /// <param name="operationContext">Operation context</param> /// <returns>An enumerable collection of tables that begin with the specified prefix</returns> public IEnumerable <CloudTable> ListTables(string prefix, TableRequestOptions requestOptions, XTable.OperationContext operationContext) { //https://ahmet.im/blog/azure-listblobssegmentedasync-listcontainerssegmentedasync-how-to/ TableContinuationToken continuationToken = null; var results = new List <CloudTable>(); do { try { var response = tableClient.ListTablesSegmentedAsync(prefix, null, continuationToken, requestOptions, operationContext).Result; continuationToken = response.ContinuationToken; results.AddRange(response.Results); } catch (AggregateException e) when(e.InnerException is XTable.StorageException) { throw e.InnerException; } } while (continuationToken != null); return(results); }
// List all tables that we may have handed out. public async Task <CloudTable[]> ListTablesAsync() { List <CloudTable> list = new List <CloudTable>(); TableContinuationToken continuationToken = null; do { var segment = await _tableClient.ListTablesSegmentedAsync(_tableNamePrefix, continuationToken, CancellationToken.None); list.AddRange(segment.Results); continuationToken = segment.ContinuationToken; }while (continuationToken != null); var legacyTable = LegacyTableReader.GetLegacyTable(_tableClient); if (legacyTable != null) { list.Add(legacyTable); } return(list.ToArray()); }
private async static Task Clean(StorageAccount account) { CloudBlobClient blobClient = account.CreateCloudBlobClient(); foreach (var testContainer in (await blobClient.ListContainersSegmentedAsync(TestArtifactPrefix, null)).Results) { await testContainer.DeleteAsync(); } CloudTableClient tableClient = account.CreateCloudTableClient(); foreach (var table in await tableClient.ListTablesSegmentedAsync(TestArtifactPrefix, null)) { await table.DeleteAsync(); } CloudQueueClient queueClient = account.CreateCloudQueueClient(); foreach (var queue in (await queueClient.ListQueuesSegmentedAsync(TestArtifactPrefix, null)).Results) { await queue.DeleteAsync(); } }