Ejemplo n.º 1
0
 public static void CreateTablesIfNotExists()
 {
     foreach (var tableName in TableAssist.GetTables())
     {
         GetTableClient().GetTableReference(tableName).CreateIfNotExists();
     }
 }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
 public async static Task CreateTablesIfNotExistsAsync()
 {
     var tableCreationTasks = TableAssist.GetTables()
                              .ToList()
                              .Select(table => GetTableClient().GetTableReference(TableAssist.AuditActivities())
                                      .CreateIfNotExistsAsync());
     await Task.WhenAll(tableCreationTasks);
 }
Ejemplo n.º 4
0
        public async Task <AuditDeletion> GetDeleteActivity(string partitionkey, string rowKey)
        {
            var o = TableOperation.Retrieve <AuditDeletion>(partitionkey, rowKey);
            var t = ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditDeletions());
            var d = await t.ExecuteAsync(o);

            return(d.Result as AuditDeletion);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public async Task <List <AuditActivityHistory> > GetAuditActivity(int pageCount = 1, int pageSize = 500)
        {
            var t     = ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditActivityHistories());
            var query = new TableQuery <AuditActivityHistory>();

            if (pageCount > 1)
            {
                query = query.Take(pageSize).Skip((pageCount - 1) * pageSize).AsTableQuery();
            }
            else
            {
                query = query.Take(pageSize);
            }

            return((await t.ExecuteQuerySegmentedAsync(query, null)).Results);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns all permission exceptions for the specified date
        /// </summary>
        public async Task <List <AuditPermissionActivity> > GetPermissionExceptionActivity(DateTime date, int pageCount = 1, int pageSize = 500)
        {
            var t     = ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditPermissions());
            var query = new TableQuery <AuditPermissionActivity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, date.ToString("yyyyMM")));

            if (pageCount > 1)
            {
                query = query.Take(pageSize).Skip((pageCount - 1) * pageSize).AsTableQuery();
            }
            else
            {
                query = query.Take(pageSize);
            }

            return((await t.ExecuteQuerySegmentedAsync(query, null)).Results);
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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));
            }
            ;
        }
Ejemplo n.º 11
0
        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));
        }
Ejemplo n.º 12
0
 public Task <TableQuerySegment <AuditDeletion> > GetDeleteActivity(int pageSize = 500, TableContinuationToken tableContinuationToken = null)
 {
     return(GetSegmentedData <AuditDeletion>(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditDeletions()), pageSize, tableContinuationToken));
 }