public void AddToQuery(AuditConfiguration auditCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters) { var propertyName = CriteriaTools.DeterminePropertyName(auditCfg, versionsReader, entityName, _propertyNameGetter); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName); parameters.AddWhereWithFunction(propertyName, " lower ", " like ", _value.ToLower()); }
public void MapToEntityFromMap(AuditConfiguration verCfg, Object obj, IDictionary <String, Object> data, Object primaryKey, IAuditReaderImplementor versionsReader, long revision) { if (obj == null) { return; } Object entityId = delegat.MapToIdFromMap(DictionaryWrapper <String, Object> .Wrap((IDictionary)data[propertyData.Name])); Object value; if (entityId == null) { value = null; } else { if (versionsReader.FirstLevelCache.Contains(referencedEntityName, revision, entityId)) { value = versionsReader.FirstLevelCache[referencedEntityName, revision, entityId]; } else { //java: Class<?> entityClass = ReflectionTools.loadClass(referencedEntityName); value = versionsReader.SessionImplementor.Factory.GetEntityPersister(referencedEntityName).CreateProxy( entityId, new ToOneDelegateSessionImplementor(versionsReader, Toolz.ResolveDotnetType(referencedEntityName), entityId, revision, verCfg)); } } PropertyInfo propInfo = obj.GetType().GetProperty(propertyData.Name); propInfo.SetValue(obj, value, null); }
public void AddToQuery(AuditConfiguration verCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters) { var opParameters = parameters.AddSubParameters(op); lhs.AddToQuery(verCfg, versionsReader, entityName, qb, opParameters.AddSubParameters("and")); rhs.AddToQuery(verCfg, versionsReader, entityName, qb, opParameters.AddSubParameters("and")); }
public void MapToEntityFromMap(AuditConfiguration verCfg, object obj, IDictionary data, object primaryKey, IAuditReaderImplementor versionsReader, long revision) { if (obj != null) { NullSafeMapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); } }
public void AddToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) { String propertyName = propertyNameGetter.Get(auditCfg); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName); // This will be the aggregated query, containing all the specified conditions QueryBuilder subQb = qb.NewSubQueryBuilder(); // Adding all specified conditions both to the main query, as well as to the // aggregated one. foreach (IAuditCriterion versionsCriteria in criterions) { versionsCriteria.AddToQuery(auditCfg, entityName, qb, parameters); versionsCriteria.AddToQuery(auditCfg, entityName, subQb, subQb.RootParameters); } // Setting the desired projection of the aggregated query switch (mode) { case AggregatedMode.MIN: subQb.AddProjection("min", propertyName, false); break; case AggregatedMode.MAX: subQb.AddProjection("max", propertyName, false); break; } // Adding the constrain on the result of the aggregated criteria parameters.AddWhere(propertyName, "=", subQb); }
/// <summary> /// Integrate Envers with NHibernate. /// </summary> /// <param name="configuration">The NHibernate configuration.</param> /// <param name="auditEventListener">The custom implementation for all listeners (better if inherited from <see cref="AuditEventListener"/>>)</param> /// <param name="metaDataProvider">The provider of metadata (attributes, embedded fluent-configuration or custom <see cref="IMetaDataProvider"/> for custom DSL.</param> /// <returns>The NHibernate configuration.</returns> /// <remarks> /// WARNING: Be sure to call this method after set all configuration properties, after have added all your mappings /// and after integrate NHibernate with all others packages as NHibernate.Validator, NHibernate.Search, NHibernate.Spatial. /// </remarks> public static Configuration IntegrateWithEnvers(this Configuration configuration, AuditEventListener auditEventListener, IMetaDataProvider metaDataProvider) { AuditConfiguration.SetConfigMetas(configuration, metaDataProvider); addListeners(configuration, auditEventListener); AuditConfiguration.GetFor(configuration); return(configuration); }
public void WhenGetAuditConfMultipleTimesThenDoesNotThrowsForDupicatedMappings() { var cfg = new Cfg.Configuration(); cfg.Configure(); cfg.AddXml(SimpleMapping); AuditConfiguration.GetFor(cfg); //<< external call AuditConfiguration.SetConfigMetas(cfg, new AttributeConfiguration()); var listeners = new[] { new AuditEventListener() }; cfg.AppendListeners(ListenerType.PostInsert, listeners); cfg.AppendListeners(ListenerType.PostUpdate, listeners); cfg.AppendListeners(ListenerType.PostDelete, listeners); cfg.AppendListeners(ListenerType.PostCollectionRecreate, listeners); cfg.AppendListeners(ListenerType.PreCollectionRemove, listeners); cfg.AppendListeners(ListenerType.PreCollectionUpdate, listeners); Executing.This(() => { using (cfg.BuildSessionFactory()) { // build the session factory to run initialization of listeners and be completelly sure // there isn't problems } }).Should().NotThrow(); }
public static string DeterminePropertyName(AuditConfiguration auditCfg, IAuditReaderImplementor versionsReader, string entityName, string propertyName) { if (propertyName != null) { var sessionFactory = versionsReader.SessionImplementor.Factory; if (AuditId.IdentifierPlaceholder.Equals(propertyName)) { var identifierPropertyName = sessionFactory.GetEntityPersister(entityName).IdentifierPropertyName; return(auditCfg.AuditEntCfg.OriginalIdPropName + "." + identifierPropertyName); } var idPropertyName = sessionFactory.GetEntityPersister(entityName).IdentifierPropertyName; if (propertyName.Equals(idPropertyName)) { return(auditCfg.AuditEntCfg.OriginalIdPropName + "." + propertyName); } if (propertyName.StartsWith(idPropertyName + MappingTools.RelationCharacter)) { propertyName = propertyName.Replace(MappingTools.RelationCharacter, "."); return(auditCfg.AuditEntCfg.OriginalIdPropName + propertyName.Substring(idPropertyName.Length)); } } return(propertyName); }
public EntitiesAtRevisionQuery(AuditConfiguration verCfg, IAuditReaderImplementor versionsReader, System.Type cls, long revision) : base(verCfg, versionsReader, cls) { this.revision = revision; }
public void AddToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) { Parameters opParameters = parameters.AddSubParameters(op); lhs.AddToQuery(verCfg, entityName, qb, opParameters.AddSubParameters("and")); rhs.AddToQuery(verCfg, entityName, qb, opParameters.AddSubParameters("and")); }
public void MapToEntityFromMap(AuditConfiguration verCfg, Object obj, IDictionary <String, Object> data, Object primaryKey, IAuditReaderImplementor versionsReader, long revision) { //TODO in implementing second phase///////////// throw new NotImplementedException("Not Implemented!"); //if (obj == null) { // return; //}Not implememented //System.Type entityClass = ReflectionTools.loadClass(owningEntityName); //Object value; //try { // value = versionsReader.CreateQuery().ForEntitiesAtRevision(entityClass, revision) // //.Add( (AuditEntity.relatedId(owningReferencePropertyName).eq(primaryKey)).GetSingleResult(); //} catch (NoResultException e) { // value = null; //} catch (NonUniqueResultException e) { // throw new AuditException("Many versions results for one-to-one relationship: (" + owningEntityName + // ", " + owningReferencePropertyName + ")"); //} //ISetter setter = ReflectionTools.getSetter(obj.getClass(), propertyData); //Catalina: la portare se foloseste PropertyInfo. Exemple in MultiPropertyMapper si SinglePropertyMapper //setter.set(obj, value, null); }
public AuditRevisionsAssociationQuery(AuditConfiguration auditConfiguration, IAuditReaderImplementor auditReader, IEntityAuditQuery <TEntity> parent, QueryBuilder queryBuilder, string ownerEntityName, string propertyName, JoinType joinType, string ownerAlias) { _auditConfiguration = auditConfiguration; _auditReader = auditReader; _parent = parent; _queryBuilder = queryBuilder; _joinType = joinType; _ownerAlias = ownerAlias; var relationDescription = CriteriaTools.GetRelatedEntity(auditConfiguration, ownerEntityName, propertyName); if (relationDescription == null) { throw new ArgumentException("Property " + propertyName + " of entity " + ownerEntityName + " is not a valid association for queries"); } _entityName = relationDescription.ToEntityName; _ownerAssociationIdMapper = relationDescription.IdMapper; _alias = queryBuilder.GenerateAlias(); _parameters = queryBuilder.AddParameters(_alias); _criterions = new List <IAuditCriterion>(); _associationQueries = new List <AuditRevisionsAssociationQuery <TEntity> >(); _associationQueryMap = new Dictionary <string, AuditRevisionsAssociationQuery <TEntity> >(); }
protected AbstractRevisionsQuery(AuditConfiguration auditConfiguration, IAuditReaderImplementor versionsReader, bool includesDeletations, string entityName) { AuditConfiguration = auditConfiguration; _versionsReader = versionsReader; _criterions = new List <IAuditCriterion>(); EntityInstantiator = new EntityInstantiator(auditConfiguration, versionsReader); EntityName = entityName; VersionsEntityName = auditConfiguration.AuditEntCfg.GetAuditEntityName(EntityName); QueryBuilder = new QueryBuilder(VersionsEntityName, QueryConstants.ReferencedEntityAlias); _includesDeletations = includesDeletations; if (!auditConfiguration.EntCfg.IsVersioned(EntityName)) { throw new NotAuditedException(EntityName, EntityName + " is not versioned!"); } _associationQueries = new List <AuditRevisionsAssociationQuery <TEntity> >(); _associationQueryMap = new Dictionary <string, AuditRevisionsAssociationQuery <TEntity> >(); }
public object ConvertQueryResult(AuditConfiguration auditCfg, EntityInstantiator entityInstantiator, string entityName, long revision, object value) { return(auditCfg.EntCfg.IsVersioned(entityName) ? entityInstantiator.CreateInstanceFromVersionsEntity(entityName, (IDictionary)value, revision) : value); }
protected override void NullSafeMapToEntityFromMap(AuditConfiguration verCfg, object obj, IDictionary data, object primaryKey, IAuditReaderImplementor versionsReader, long revision) { var entityId = _delegat.MapToIdFromMap(data); object value = null; if (entityId != null) { if (!versionsReader.FirstLevelCache.TryGetValue(_referencedEntityName, revision, entityId, out value)) { var referencedEntity = GetEntityInfo(verCfg, _referencedEntityName); var ignoreNotFound = false; if (!referencedEntity.IsAudited) { var referencingEntityName = verCfg.EntCfg.GetEntityNameForVersionsEntityName((string)data["$type$"]); var relation = verCfg.EntCfg.GetRelationDescription(referencingEntityName, PropertyData.Name); ignoreNotFound = relation != null && relation.IsIgnoreNotFound; } var removed = RevisionType.Deleted.Equals(data[verCfg.AuditEntCfg.RevisionTypePropName]); value = ignoreNotFound ? ToOneEntityLoader.LoadImmediate(versionsReader, _referencedEntityName, entityId, revision, removed, verCfg) : ToOneEntityLoader.CreateProxyOrLoadImmediate(versionsReader, _referencedEntityName, entityId, revision, removed, verCfg); } } SetPropertyValue(obj, value); }
public void AddToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) { String propertyName = propertyNameGetter.Get(auditCfg); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName); parameters.AddWhereWithParams(propertyName, "in (", values, ")"); }
public AuditingManager() { sp = Stopwatch.StartNew(); Session = NullSession.GetInstance(); auditSetting = IocManager.Instance.Resolve <AuditConfiguration>(); provider = new WebAuditInfoProvider(); }
protected override void RegisterTypes(IUnityContainer container) { base.RegisterTypes(container); var config = new AuditConfiguration <MyDefaultAuditor>(); config.AddNamespaceAuditor <FooAuditor>(typeof(Foo).FullName); config.AddNamespaceAuditor <QuxAuditor>(typeof(Qux).FullName); container.RegisterInstance <IAuditConfiguration>(config, (new ContainerControlledLifetimeManager())); container.RegisterType <IFacetDecorator, AuditManager>("AuditManager", new ContainerControlledLifetimeManager()); var reflectorConfig = new ReflectorConfiguration(new[] { typeof(MyDefaultAuditor), typeof(FooAuditor), typeof(QuxAuditor), typeof(QueryableList <Foo>) }, new[] { typeof(SimpleRepository <Foo>), typeof(SimpleRepository <Bar>), typeof(SimpleRepository <Qux>), typeof(FooService), typeof(BarService), typeof(QuxService) }, new[] { typeof(Foo).Namespace }); container.RegisterInstance <IReflectorConfiguration>(reflectorConfig, new ContainerControlledLifetimeManager()); }
public MessageAuditService( ILogger <MessageAuditService> logger, IOptions <AuditConfiguration> configuration) { _logger = logger; _configuration = configuration.Value; }
public void ShouldUseDefaultValue() { var nhConfiguration = new Cfg.Configuration(); nhConfiguration.IntegrateWithEnvers(); AuditConfiguration.GetFor(nhConfiguration).GlobalCfg.StoreDataAtDelete .Should().Be.False(); }
public void MapToEntityFromMap(AuditConfiguration verCfg, object obj, IDictionary data, object primaryKey, IAuditReaderImplementor versionsReader, long revision) { foreach (var mapper in Properties.Values) { mapper.MapToEntityFromMap(verCfg, obj, data, primaryKey, versionsReader, revision); } }
public ECommerceDb() { Audit(Categories); Audit(Products).WithConfiguration <ProductAuditConfig>(); AuditConfiguration.EmptyPropertyMode = EmptyPropertyMode.AlwaysAudit; AuditConfiguration.OnlyAuditPropertiesIf((property, entity) => !property.Name.EndsWith("Id")); }
public void AddToQuery(AuditConfiguration auditCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters) { var propertyName = CriteriaTools.DeterminePropertyName(auditCfg, versionsReader, entityName, propertyNameGetter); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, otherPropertyName); parameters.AddWhere(propertyName, op, otherPropertyName); }
public void AuditCreatedUserGuidSetsCreatedUserGuidPropertyName() { var componentUnderTest = new AuditConfiguration(); componentUnderTest.AuditCreatedUserGuid <TestEntity>(c => c.SomeGuid); Assert.That(componentUnderTest.CreatedUserGuidPropertyName(typeof(TestEntity)), Is.EqualTo("SomeGuid")); }
public void AuditModifiedUserGuidSetsModifiedUserGuidPropertyName() { var componentUnderTest = new AuditConfiguration(); componentUnderTest.AuditModifiedUserGuid <TestEntity>(c => c.AnotherGuid); Assert.That(componentUnderTest.ModifiedUserGuidPropertyName(typeof(TestEntity)), Is.EqualTo("AnotherGuid")); }
protected AbstractAuditWorkUnit(ISessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, Object id) { this.sessionImplementor = sessionImplementor; this.verCfg = verCfg; this.EntityId = id; this.EntityName = entityName; }
public void AuditModifiedDateTimeSetsCreatedDateTimePropertyName() { var componentUnderTest = new AuditConfiguration(); componentUnderTest.AuditModifiedDateTime <TestEntity>(c => c.AnotherDateTime); Assert.That(componentUnderTest.ModifiedDateTimePropertyName(typeof(TestEntity)), Is.EqualTo("AnotherDateTime")); }
public void DefaultBehavioursArePreconfigured() { var configuration = new AuditConfiguration(); configuration.Behaviours.Should().Contain(AuditBehaviours.SetMachineNameToEnvironmentMachineName); configuration.Behaviours.Should().Contain(AuditBehaviours.SetApplicationNameToLoggingApplicationName); configuration.Behaviours.Should().Contain(AuditBehaviours.SetCorrelationKeyToFlowedCorrelationKeyOrDefault); }
public void TestCreateOk() { var config = new AuditConfiguration<IAuditor>(); config.AddNamespaceAuditor<IAuditor>("namespace"); // ReSharper disable once UnusedVariable var sink = new AuditManager(config); }
public void CanBeSetByConfigurationKey() { var nhConfiguration = new Cfg.Configuration(); nhConfiguration.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true); nhConfiguration.IntegrateWithEnvers(); AuditConfiguration.GetFor(nhConfiguration).GlobalCfg.StoreDataAtDelete .Should().Be.True(); }
public void CanBeSetByConfigurationKeyMethod() { var nhConfiguration = new Cfg.Configuration(); ConfigurationKey.StoreDataAtDelete.SetUserValue(nhConfiguration, true); nhConfiguration.IntegrateWithEnvers(); AuditConfiguration.GetFor(nhConfiguration).GlobalCfg.StoreDataAtDelete .Should().Be.True(); }
/// <summary> /// Initializes a new instance of the <see cref="AuditLogger"/> class. /// </summary> /// <param name="objectContext">The <see cref="ObjectContext"/> to create the <see cref="AuditLog"/> from.</param> /// <param name="configuration">The <see cref="AuditConfiguration"/> to use when creating the <see cref="AuditLog"/>.</param> public AuditLogger(ObjectContext objectContext, AuditConfiguration configuration) { if (objectContext == null) throw new ArgumentNullException("objectContext"); _objectContext = objectContext; _configuration = configuration ?? AuditConfiguration.Default; AttachEvents(); }
/// <summary> /// Initializes a new instance of the <see cref="AuditLogger"/> class. /// </summary> /// <param name="dbContext">The <see cref="DbContext"/> to create the <see cref="AuditLog"/> from.</param> /// <param name="configuration">The <see cref="AuditConfiguration"/> to use when creating the <see cref="AuditLog"/>.</param> public AuditLogger(DbContext dbContext, AuditConfiguration configuration) { if (dbContext == null) throw new ArgumentNullException("dbContext"); var adapter = (IObjectContextAdapter)dbContext; _objectContext = adapter.ObjectContext; _configuration = configuration ?? AuditConfiguration.Default; AttachEvents(); }
/// <summary>Static constructor.</summary> static AuditManager() { DefaultConfiguration = new AuditConfiguration(); }
/// <summary> /// Begin audit logging by attaching an AuditLogger to the ObjectContext. /// </summary> /// <param name="objectContext">The ObjectContext to create the AuditLog from.</param> /// <param name="configuration">The AuditConfiguration to use when creating the AuditLog.</param> /// <returns>An Auditlogger instance to create an AuditLog from.</returns> public static AuditLogger BeginAudit(this ObjectContext objectContext, AuditConfiguration configuration = null) { return new AuditLogger(objectContext, configuration); }
/// <summary> /// Begin audit logging by attaching an AuditLogger to the ObjectContext. /// </summary> /// <param name="dbContext">The DbContext to create the AuditLog from.</param> /// <param name="configuration">The AuditConfiguration to use when creating the AuditLog.</param> /// <returns>An Auditlogger instance to create an AuditLog from.</returns> public static AuditLogger BeginAudit(this DbContext dbContext, AuditConfiguration configuration = null) { return new AuditLogger(dbContext, configuration); }