示例#1
0
        public async Task QueryTablesAsync()
        {
            string storageUri        = StorageUri;
            string accountName       = StorageAccountName;
            string storageAccountKey = PrimaryStorageAccountKey;
            string tableName         = "OfficeSupplies3p2" + _random.Next();

            var serviceClient = new TableServiceClient(
                new Uri(storageUri),
                new TableSharedKeyCredential(accountName, storageAccountKey));

            await serviceClient.CreateTableAsync(tableName);

            #region Snippet:TablesSample3QueryTablesAsync
            // Use the <see cref="TableServiceClient"> to query the service. Passing in OData filter strings is optional.
            AsyncPageable <TableItem> queryTableResults = serviceClient.QueryAsync(filter: $"TableName eq '{tableName}'");

            Console.WriteLine("The following are the names of the tables in the query result:");
            // Iterate the <see cref="Pageable"> in order to access individual queried tables.
            await foreach (TableItem table in queryTableResults)
            {
                Console.WriteLine(table.Name);
            }
            #endregion

            await serviceClient.DeleteTableAsync(tableName);
        }
示例#2
0
        public async Task <List <string> > ListTablesAsync()
        {
            var result     = new List <string>();
            var tableItems = tableServiceClient.QueryAsync();

            await foreach (var tableItem in tableItems)
            {
                result.Add(tableItem.Name);
            }
            return(result);
        }
示例#3
0
        public static async Task <List <string> > ListTablesAsync(string account, string key)
        {
            TableServiceClient client  = new TableServiceClient(Client.GetConnectionString(account, key));
            List <string>      results = new List <string>();

            await foreach (var table in client.QueryAsync())
            {
                results.Add(table.Name);
            }

            return(results);
        }
        /// <summary>
        /// Inspects the Service Fabric diagnostic tables and removes old items when found.
        /// </summary>
        /// <returns></returns>
        internal async Task CleanupDiagnosticTablesAsync()
        {
            if ((string.IsNullOrWhiteSpace(this._endpoint)) || (string.IsNullOrWhiteSpace(this._sasToken)))
            {
                ServiceEventSource.Current.Error("Storage account information not set.");
                return;
            }

            try
            {
                // Create the storage credentials and connect to the storage account.
                // The SAS token must be a Table service SAS URL with permissions to read, delete and list table entries. HTTPS must be used.
                AzureSasCredential sc     = new AzureSasCredential(this._sasToken);
                TableServiceClient client = new TableServiceClient(new Uri(this._endpoint), sc);

                // Inspect each table for items to be removed.
                foreach (string tableName in this._tablesToInspect)
                {
                    await foreach (var table in client.QueryAsync(t => t.Name == tableName))
                    {
                        var tableClient = client.GetTableClient(table.Name);
                        await this.EnumerateTableItemsAsync(table, tableClient);
                    }
                }

                this._healthState = HealthState.Ok;
            }
            catch (RequestFailedException ex)
            {
                this._healthState = HealthState.Error;
                ServiceEventSource.Current.Exception(ex.Message, ex.GetType().Name, ex.StackTrace);
            }
            catch (Exception ex)
            {
                ServiceEventSource.Current.Exception(ex.Message, ex.GetType().Name, ex.StackTrace);
            }
        }
示例#5
0
    private async Task DeleteExpiredTables(DateTimeOffset endTime)
    {
        // Note: in practice you would likely debounce / limit the number of times this method gets called
        // For brevity we just do it on every read operation.
        var minBucket = GetBucketNameForTimeSpan(endTime);

        _logger.LogInformation("Deleting tables before: [{bucket}]", minBucket);

        await foreach (var table in _tableServiceClient.QueryAsync())
        {
            // Skip tables that aren't a part of this, they've done nothing wrong.
            if (!table.Name.StartsWith(_tablePrefix))
            {
                continue;
            }

            var bucketId = GetBucketId(table.Name);
            if (bucketId < minBucket)
            {
                _logger.LogInformation("Deleting expired table: [{tableName}]", table.Name);
                await _tableServiceClient.DeleteTableAsync(table.Name);
            }
        }
    }
 public IAsyncEnumerable <TableItem> GetTables() => serviceClient.QueryAsync();
示例#7
0
 /// <summary>
 /// Does the table exist
 /// </summary>
 /// <returns></returns>
 public async Task <bool> TableExistsAsync()
 {
     return((await _cloudTableService.QueryAsync(e => e.Name == _tableName).ToListAsync()).Any());
 }