/// <summary> /// Returns a all of a users activities, including login and permission activities /// </summary> public Task <TableQuerySegment <AuditUserActivity> > GetUserActivity(string userId, int pageSize = 500, TableContinuationToken tableContinuationToken = null) { var t = ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()); var query = new TableQuery <AuditUserActivity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, userId)); return(t.ExecuteQuerySegmentedAsync(query.Take(pageSize), tableContinuationToken)); }
public async Task <List <AuditUserActivity> > GetAllUsersActivity(int pageCount = 1, int pageSize = 500) { var t = ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()); var query = new TableQuery <AuditUserActivity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "USER")); 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 ProcessPermissionIssue(AuditActivity auditActivity) { var activityUser = new AuditUserActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName) { AuditType = auditActivity.AuditType, ExtraInfo = auditActivity.Description }; await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.InsertOrReplace(activityUser)); await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUserLogins()), TableOperation.InsertOrReplace(activityUser)); var activityPermission = new AuditPermissionActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName, auditActivity.EntityType, auditActivity.EntityId) { ExtraInfo = auditActivity.Description }; await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditPermissions()), TableOperation.InsertOrReplace(activityPermission)); }
public async Task <List <AuditUserActivity> > GetUserActivity(string userId) { var t = ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()); var query = new TableQuery <AuditUserActivity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, userId)); var segment = await t.ExecuteQuerySegmentedAsync(query, null); var model = new List <AuditUserActivity>(); if (segment.Results != null) { model.AddRange(segment.Results.ToList()); } while (segment.ContinuationToken != null) { segment = await t.ExecuteQuerySegmentedAsync(query, segment.ContinuationToken); model.AddRange(segment.Results.ToList()); } return(model); }
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)); } ; }
async Task ProcessLogin(AuditActivity auditActivity) { var activityUser = new AuditUserActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName) { AuditType = auditActivity.AuditType, ExtraInfo = auditActivity.Description }; if (auditActivity.Entity != null && bool.TryParse(auditActivity.Entity, out bool isSuccess)) { activityUser.IsSuccessful = isSuccess; } await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.InsertOrReplace(activityUser)); await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.InsertOrReplace(activityUser)); await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUserLogins()), TableOperation.InsertOrReplace(activityUser)); var activityLogin = new AuditLoginActivity(auditActivity.On.DateTime, auditActivity.ById, auditActivity.ByName) { ExtraInfo = auditActivity.Description }; await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditLogins()), TableOperation.InsertOrReplace(activityLogin)); }