public async Task <List <AuditActivity> > GetAuditActivity(string partitionkey, int pageCount = 1, int pageSize = 1000) { var t = ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditActivities()); var query = new TableQuery <AuditActivity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionkey)); if (pageCount > 1) { query = query.Take(pageSize).Skip((pageCount - 1) * pageSize).AsTableQuery(); } else { query = query.Take(pageSize); } return((await t.ExecuteQuerySegmentedAsync(query, null)).Results); }
async Task ProcessActivity(AuditActivity auditActivity) { var activityUser = new AuditUserActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName) { AuditType = auditActivity.AuditType, EntityPartitionKey = auditActivity.PartitionKey, EntityRowKey = auditActivity.RowKey, EntityType = auditActivity.EntityType, EntityId = auditActivity.EntityId }; var auditUserHistoryActivity = new AuditUserHistoryActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName); var activityHistory = new AuditActivityHistory(TimeZoneHelper.GetDate(auditActivity.On), auditActivity.ById, auditActivity.ByName, auditActivity.PartitionKey, auditActivity.RowKey) { EntityType = auditActivity.EntityType, EntityId = auditActivity.EntityId, On = auditActivity.On, AuditType = auditActivity.AuditType }; await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditActivities()), TableOperation.Insert(auditActivity)); await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.Insert(activityUser)); await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.InsertOrReplace(auditUserHistoryActivity)); await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditActivityHistories()), TableOperation.InsertOrReplace(activityHistory)); if (auditActivity.GetActivityType() == AuditActivityType.Delete) { var deletion = new AuditDeletion(auditActivity.EntityType, auditActivity.EntityId) { Entity = auditActivity.Entity, ById = auditActivity.ById, ByName = auditActivity.ByName, On = auditActivity.On }; await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditDeletions()), TableOperation.Insert(deletion)); } ; }
public async static Task CreateTablesIfNotExistsAsync() { var tableCreationTasks = TableAssist.GetTables() .ToList() .Select(table => GetTableClient().GetTableReference(TableAssist.AuditActivities()) .CreateIfNotExistsAsync()); await Task.WhenAll(tableCreationTasks); }