/// <summary> /// Enumerates the items in a table looking for items with a timestamp over the time to keep. /// </summary> /// <param name="table">CloudTable instance.</param> /// <returns>Number of items removed.</returns> internal async Task <int> EnumerateTableItemsAsync(TableItem table, TableClient tableClient) { if (null == table) { throw new ArgumentNullException("Argument is null", nameof(this.EnumerateTableItemsAsync)); } Stopwatch sw = Stopwatch.StartNew(); ServiceEventSource.Current.Trace("EnumerateTableItemsAsync", tableClient.Name); int deleteCount = 0; var timeStamp = DateTimeOffset.Now.Subtract(this._timeToKeep); // Execute the query. AsyncPageable <TableEntity> queryResult = tableClient.QueryAsync <TableEntity>(e => e.Timestamp < timeStamp); await foreach (TableEntity item in queryResult) { await tableClient.DeleteEntityAsync(item.PartitionKey, item.RowKey); deleteCount++; } ServiceEventSource.Current.Trace($"EnumerateTableItemsAsync removed {deleteCount} items from {table.Name} in {sw.ElapsedMilliseconds}ms."); return(deleteCount); }
public async Task DeleteAsync(DishEntity dish) { ArgumentNullException.ThrowIfNull(dish.RowKey); var partitionKey = "lye"; var response = await _dishTable.DeleteEntityAsync(partitionKey, dish.RowKey); _logger.LogInformation("Deleted dish with RowKey {RowKey} - Status: {HttpStatus}", dish.RowKey, response.Status); }
public async Task <bool> DeleteAsync(TodoItem deleteTodo) { var tableClient = new TableClient(_conn, TableName); var result = await tableClient.DeleteEntityAsync(deleteTodo.PartitionKey, deleteTodo.RowKey); return(result.Status == StatusCodes.Status204NoContent); }
public async Task <T> DeleteEntityAsync <T>(TableClient tableClient, string partitionKey, string rowKey) where T : AzureTableEntity, new() { Guard.IsNotNull(tableClient, nameof(tableClient)); var oldEntity = await GetEntityAsync <T>(tableClient, partitionKey, rowKey); await tableClient.DeleteEntityAsync(partitionKey, rowKey); return(oldEntity); }
protected async Task ClearTableAsync() { var entities = TableClient.QueryAsync <TableEntity>(); await foreach (var entity in entities) { await TableClient.DeleteEntityAsync(entity.PartitionKey, entity.RowKey); } }
public async Task <Image> DeleteImageAsync(string id) { var image = new ImageTableEntity { Id = id }; await TableClient.DeleteEntityAsync(image.PartitionKey, image.RowKey); return(image); //TODO : Bubble up errors through the stack }
public static async Task <IActionResult> DeleteTodo( [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = Route + "/{id}")] HttpRequest req, [Table(TableName, Connection = "AzureWebJobsStorage")] TableClient todoTable, ILogger log, string id) { try { await todoTable.DeleteEntityAsync(PartitionKey, id, ETag.All); } catch (RequestFailedException e) when(e.Status == 404) { return(new NotFoundResult()); } return(new OkResult()); }
public async Task CreateDeleteEntitiesAsync() { string storageUri = StorageUri; string accountName = StorageAccountName; string storageAccountKey = PrimaryStorageAccountKey; string tableName = "OfficeSupplies2p2"; string partitionKey = "somePartition"; string rowKey = "A1"; string rowKeyStrong = "B1"; #region Snippet:TablesSample2CreateTableClientAsync // Construct a new <see cref="TableClient" /> using a <see cref="TableSharedKeyCredential" />. var client = new TableClient( tableName, new Uri(storageUri), new TableSharedKeyCredential(accountName, storageAccountKey)); // Create the table in the service. await client.CreateAsync(); #endregion #region Snippet:TablesSample2CreateEntityAsync // Make an entity by defining a <see cref="Dictionary"> that includes the partition and row key. var entity = new TableEntity(partitionKey, rowKey) { { "Product", "Markers" }, { "Price", 5.00 }, }; // Insert the newly created entity. await client.CreateEntityAsync(entity); #endregion #region Snippet:TablesSample2CreateStronglyTypedEntityAsync // Make a strongly typed entity by defining a custom class that extends <see cref="TableEntity">. var strongEntity = new OfficeSupplyEntity { PartitionKey = partitionKey, RowKey = rowKeyStrong, Product = "Notebook", Price = 3.00 }; // Insert the newly created entity. await client.CreateEntityAsync(strongEntity); #endregion #region Snippet:TablesSample2DeleteEntityAsync // Delete the entity given the partition and row key. await client.DeleteEntityAsync(partitionKey, rowKey); #endregion #region Snippet:TablesSample2DeleteTableWithTableClientAsync await client.DeleteAsync(); #endregion }
public Task <Response> DeleteAsync(string rowKey) => _tableClient.DeleteEntityAsync(_partitionKey, rowKey);
public async Task CreateDeleteEntitiesAsync() { string storageUri = StorageUri; string accountName = StorageAccountName; string storageAccountKey = PrimaryStorageAccountKey; string tableName = "OfficeSupplies2p2"; string partitionKey = "Stationery"; string rowKey = "A1"; string rowKeyStrong = "B1"; #region Snippet:TablesSample2CreateTableClientAsync // Construct a new <see cref="TableClient" /> using a <see cref="TableSharedKeyCredential" />. var client = new TableClient( new Uri(storageUri), tableName, new TableSharedKeyCredential(accountName, storageAccountKey)); // Create the table in the service. await client.CreateAsync(); #endregion #region Snippet:TablesSample2CreateEntityAsync // Make a dictionary entity by defining a <see cref="TableEntity">. var entity = new TableEntity(partitionKey, rowKey) { { "Product", "Marker Set" }, { "Price", 5.00 }, { "Quantity", 21 } }; Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}."); #endregion #region Snippet:TablesSample2AddEntityAsync // Insert the newly created entity. await client.AddEntityAsync(entity); #endregion #region Snippet:TablesSample2CreateStronglyTypedEntityAsync // Create an instance of the strongly-typed entity and set their properties. var strongEntity = new OfficeSupplyEntity { PartitionKey = partitionKey, RowKey = rowKeyStrong, Product = "Notebook", Price = 3.00, Quantity = 50 }; Console.WriteLine($"{entity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}."); #endregion // Add the newly created entity. await client.AddEntityAsync(strongEntity); #region Snippet:TablesSample2DeleteEntityAsync // Delete the entity given the partition and row key. await client.DeleteEntityAsync(partitionKey, rowKey); #endregion #region Snippet:TablesSample2DeleteTableWithTableClientAsync await client.DeleteAsync(); #endregion }
public static async Task DeleteEntityAsync(string account, string key, string tableName, string partitionKey, string rowKey) { TableClient table = new TableClient(Client.GetConnectionString(account, key), tableName); await table.DeleteEntityAsync(partitionKey, rowKey); }
public async Task DeleteTokenAsync(string tenantId, string userId) { await _tableClient.CreateIfNotExistsAsync(); await _tableClient.DeleteEntityAsync(partitionKey : tenantId, rowKey : userId); }