public void Enable(List <Type> auditableTypes, Func <AuditContext> getAuditContext) { _getAuditContext = getAuditContext; AuditEntityConfiguration.SetAuditableTypes(auditableTypes); InitializeConfiguration(); _isEnabled = true; }
private Type GetTypeFromClassName(string name) => AuditEntityConfiguration.GetTypeFromClassName(name);
private void InitializeConfiguration() { MiniSessionManager.ExecuteInUoW(manager => { var repo = ServiceLocator.Current.GetInstance <IRepositoryBuilder>().CreateAuditingRepository(manager); var oldEntityConfigurations = repo.GetAll <AuditEntityConfiguration>(); List <AuditEntityConfiguration> newEntityConfigurations = AuditEntityConfiguration.GetAllEntityConfigurations(); newEntityConfigurations.ForEach(newEntityConfiguration => { var item = oldEntityConfigurations.FirstOrDefault(c => c.FullName == newEntityConfiguration.FullName); if (item == null) { repo.Save(newEntityConfiguration); } else { item.UpdateAuditEntityConfiguration(newEntityConfiguration, repo); } }); oldEntityConfigurations.ForEach(oldEntityConfiguration => { var item = newEntityConfigurations.FirstOrDefault(c => c.FullName == oldEntityConfiguration.FullName); if (item == null) { repo.DeleteAuditEntityConfiguration(oldEntityConfiguration); } }); var auditLogEntryTypes = repo.GetAll <AuditLogEntryType>(); if (!auditLogEntryTypes.Any()) { repo.Save(new AuditLogEntryType { Code = "CREATE", Name = "Create" }); repo.Save(new AuditLogEntryType { Code = "UPDATE", Name = "Update" }); repo.Save(new AuditLogEntryType { Code = "DELETE", Name = "Delete" }); auditLogEntryTypes = repo.GetAll <AuditLogEntryType>(); } var auditLogPropertyActionTypes = repo.GetAll <AuditLogPropertyActionType>(); var addAction = auditLogPropertyActionTypes.FirstOrDefault(a => a.Code == "ADD"); if (addAction == null) { repo.Save(new AuditLogPropertyActionType { Code = "ADD", Name = "Added Element To Collection" }); } var removeAction = auditLogPropertyActionTypes.FirstOrDefault(a => a.Code == "REMOVE"); if (removeAction == null) { repo.Save(new AuditLogPropertyActionType { Code = "REMOVE", Name = "Removed Element From Collection" }); } var assignAction = auditLogPropertyActionTypes.FirstOrDefault(a => a.Code == "ASSIGN"); if (assignAction == null) { repo.Save(new AuditLogPropertyActionType { Code = "ASSIGN", Name = "Assign Entity" }); } }); ClearAuditTrailCache(); }