/// <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 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); } }
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); }
/// <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); } }
public static async Task <IList <CloudTable> > ListTablesAsync( this CloudTableClient client, CancellationToken ct = default(CancellationToken)) { var tables = new List <CloudTable>(); TableContinuationToken token = null; do { TableResultSegment seg = await client.ListTablesAsync(token, ct); token = seg.ContinuationToken; tables.AddRange(seg); } while (token != null && !ct.IsCancellationRequested); return(tables); }
/// <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 IAsyncOperation<TableResultSegment> ListTablesSegmentedAsync(string prefix, int? maxResults, TableContinuationToken currentToken, TableRequestOptions requestOptions, OperationContext operationContext) #endif { requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this); operationContext = operationContext ?? new OperationContext(); TableQuery query = this.GenerateListTablesQuery(prefix, maxResults); #if ASPNET_K return Task.Run(async () => { TableQuerySegment seg = await this.ExecuteQuerySegmentedAsync(TableConstants.TableServiceTablesName, query, currentToken, requestOptions, operationContext, cancellationToken); #else return AsyncInfo.Run(async (cancellationToken) => { TableQuerySegment seg = await this.ExecuteQuerySegmentedAsync(TableConstants.TableServiceTablesName, query, currentToken, requestOptions, operationContext).AsTask(cancellationToken); #endif TableResultSegment retSegment = new TableResultSegment(seg.Results.Select(tbl => new CloudTable(tbl.Properties[TableConstants.TableName].StringValue, this)).ToList()); retSegment.ContinuationToken = seg.ContinuationToken; return retSegment; #if ASPNET_K }, cancellationToken); #else }); #endif }
public TableResultSegment ListTablesSegmented( string prefix, int? maxResults, TableContinuationToken currentToken, TableRequestOptions requestOptions = null, OperationContext operationContext = null) { requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this); operationContext = operationContext ?? new OperationContext(); TableQuerySegment<DynamicTableEntity> res = this.GenerateListTablesQuery(prefix, maxResults).ExecuteQuerySegmented(currentToken, this, TableConstants.TableServiceTablesName, requestOptions, operationContext); List<CloudTable> tables = res.Results.Select(tbl => new CloudTable( NavigationHelper.AppendPathToUri(this.BaseUri, tbl.Properties[TableConstants.TableName].StringValue), this)).ToList(); TableResultSegment retSeg = new TableResultSegment(tables) { ContinuationToken = res.ContinuationToken as TableContinuationToken }; return retSeg; }
public TableResultSegment EndListTablesSegmented(IAsyncResult asyncResult) { TableQuerySegment<DynamicTableEntity> res = Executor.EndExecuteAsync<TableQuerySegment<DynamicTableEntity>>(asyncResult); List<CloudTable> tables = res.Results.Select(tbl => new CloudTable( NavigationHelper.AppendPathToUri(this.BaseUri, tbl.Properties[TableConstants.TableName].StringValue), this)).ToList(); TableResultSegment retSeg = new TableResultSegment(tables) { ContinuationToken = res.ContinuationToken as TableContinuationToken }; return retSeg; }
/// <summary> /// Returns a result segment containing a collection of tables beginning with the specified prefix. /// </summary> /// <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 <c>null</c> the maximum possible number of results will be returned, up to 5000.</param> /// <param name="currentToken">A <see cref="TableContinuationToken"/> token returned by a previous listing operation.</param> /// <param name="requestOptions">A <see cref="TableRequestOptions"/> object that specifies any additional options for the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that provides information on how the operation executed.</param> /// <returns>The result segment containing the collection of tables.</returns> public IAsyncOperation<TableResultSegment> ListTablesSegmentedAsync( string prefix, int? maxResults, TableContinuationToken currentToken, TableRequestOptions requestOptions, OperationContext operationContext) { requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this); operationContext = operationContext ?? new OperationContext(); TableQuery query = this.GenerateListTablesQuery(prefix, maxResults); return AsyncInfo.Run(async (cancellationToken) => { TableQuerySegment seg = await this.ExecuteQuerySegmentedAsync(TableConstants.TableServiceTablesName, query, currentToken, requestOptions, operationContext).AsTask(cancellationToken); TableResultSegment retSegment = new TableResultSegment(seg.Results.Select(tbl => new CloudTable(NavigationHelper.AppendPathToUri(this.BaseUri, tbl.Properties[TableConstants.TableName].StringValue), this)).ToList()); retSegment.ContinuationToken = seg.ContinuationToken as TableContinuationToken; return retSegment; }); }
public TableResultSegmentAdapter(TableResultSegment segment) { ContinuationToken = segment.ContinuationToken; Results = segment.Results.Select <CloudTable, ICloudTable>(ct => new CloudTableAdapter(ct)).ToList(); }
public virtual TableResultSegment ListTablesSegmented(string prefix, int? maxResults, TableContinuationToken currentToken, TableRequestOptions requestOptions = null, OperationContext operationContext = null) { requestOptions = TableRequestOptions.ApplyDefaultsAndClearEncryption(requestOptions, this); operationContext = operationContext ?? new OperationContext(); CloudTable serviceTable = this.GetTableReference(TableConstants.TableServiceTablesName); TableQuerySegment<DynamicTableEntity> res = CloudTableClient.GenerateListTablesQuery(prefix, maxResults).ExecuteQuerySegmentedInternal(currentToken, this, serviceTable, requestOptions, operationContext); List<CloudTable> tables = res.Results.Select(tbl => new CloudTable( tbl.Properties[TableConstants.TableName].StringValue, this)).ToList(); TableResultSegment retSeg = new TableResultSegment(tables) { ContinuationToken = res.ContinuationToken as TableContinuationToken }; return retSeg; }