0

Looking to programmatically do in .NET as question states. Which libraries should I be looking into? Links to code examples much appreciated.

Thanks.

Fung
  • 7,530
  • 7
  • 53
  • 68

1 Answers1

2

You can refer to the simple example as below, it truncates the table based upon a timestamp and then scan the table to get the data.

    public void TruncateDiagnostics(CloudStorageAccount storageAccount, DateTime keepThreshold)
    {
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            CloudTable cloudTable = tableClient.GetTableReference("WADLogsTable");

            TableQuery query = new TableQuery();
            query.FilterString = string.Format("Timestamp lt datetime'{0:yyyy-MM-ddTHH:mm:ss}'", keepThreshold);
            var items = cloudTable.ExecuteQuery(query).ToList();

            Dictionary<string, TableBatchOperation> batches = new Dictionary<string, TableBatchOperation>();
            foreach (var entity in items)
            {
                TableOperation tableOperation = TableOperation.Delete(entity);

                if (!batches.ContainsKey(entity.PartitionKey))
                {
                    batches.Add(entity.PartitionKey, new TableBatchOperation());
                }

                batches[entity.PartitionKey].Add(tableOperation);
            }

            foreach (var batch in batches.Values)
            {
                cloudTable.ExecuteBatch(batch);
            }
    }

You can get more examples from this thread Windows Azure - Cleaning Up The WADLogsTable.

Community
  • 1
  • 1
forester123
  • 1,549
  • 10
  • 10
  • Thanks. My question seems to be a duplicate of the link you posted. My initial search before posting question didn't hit it. Especially searching for WADSLogTable. Will add it as a tag for the other question and close mine. Thanks again. – Fung Jan 14 '16 at 05:22