public void Config(IPersistenceUnitCfg puCfg, Configuration nhCfg)
 {
     //var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();
     //enversConf.SetRevisionEntity<CustomRevEntity>(e => e.Id, e => e.Timestamp, typeof(CustomRevInfoListener));
     //enversConf.Audit(GetDomainEntities().Where(e => !typeof(REVINFO).IsAssignableFrom(e)));
     nhCfg.IntegrateWithEnvers(new AttributeConfiguration());
 }
Exemplo n.º 2
0
        protected override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            // The ValidatorInitializer and the ValidateEventListener share the same engine

            // Initialize the SharedEngine
            fortest = new NHibernateSharedEngineProvider();
            Cfg.Environment.SharedEngineProvider = fortest;
            ValidatorEngine ve = Cfg.Environment.SharedEngineProvider.GetEngine();

            ve.Clear();

            XmlConfiguration nhvc = new XmlConfiguration();

            nhvc.Properties[Cfg.Environment.ApplyToDDL]               = "true";
            nhvc.Properties[Cfg.Environment.AutoregisterListeners]    = "true";
            nhvc.Properties[Cfg.Environment.ValidatorMode]            = "UseAttribute";
            nhvc.Properties[Cfg.Environment.MessageInterpolatorClass] = typeof(PrefixMessageInterpolator).AssemblyQualifiedName;

            var enversConf = new FluentConfiguration();

            enversConf.Audit <Address>();
            configuration.IntegrateWithEnvers(enversConf);

            ve.Configure(nhvc);

            ValidatorInitializer.Initialize(configuration);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="config"></param>
        protected override void PostProcessConfiguration(Configuration config)
        {
            if (FluentNhibernateMappingAssemblies != null)
            {
                foreach (var assemblyName in FluentNhibernateMappingAssemblies)
                {
                    config.AddMappingsFromAssembly(Assembly.Load(assemblyName));
                }
            }

            config.Properties.Add("nhibernate.envers.Diversia_with_modified_flag", "true");
                //log property data for revisions
            config.IntegrateWithEnvers(new AttributeConfiguration());
            config.SetListener(ListenerType.PreInsert, new DiversiaAuditEventListener());
            config.SetListener(ListenerType.PreUpdate, new DiversiaAuditEventListener());
            config.SetListener(ListenerType.PreDelete, new DiversiaAuditEventListener());
            config.SetListener(ListenerType.PreCollectionRecreate, new DiversiaAuditEventListener());
            config.SetListener(ListenerType.PreCollectionUpdate, new DiversiaAuditEventListener());
            config.SetListener(ListenerType.PreCollectionRemove, new DiversiaAuditEventListener());
            config.Cache(c =>
            {
                c.UseMinimalPuts = true;
                c.UseQueryCache = true;
                c.Provider<SysCacheProvider>();
            });
        }
Exemplo n.º 4
0
 private static void InitializeEnvers(NHibernate.Cfg.Configuration configuration)
 {
     configuration.SetProperty("nhibernate.envers.audit_table_suffix", "_Audit");
     configuration.SetProperty("nhibernate.envers.revision_field_name", "Revision");
     configuration.SetProperty("nhibernate.envers.revision_type_field_name", "RevisionType");
     configuration.SetProperty("nhibernate.envers.store_data_at_delete", "true");
     configuration.IntegrateWithEnvers(new AttributeConfiguration());
 }
        public static CoreNHibernate.ISessionFactory CreateSessionFactory(DBTypes dbType)
        {
            FluentConfiguration config = Fluently.Configure();

            switch (dbType)
            {
            case DBTypes.Oracle:
                config = OracleHelper.ConfigurationFactory();
                break;

            case DBTypes.MSSQL:
                config = MsSqlHelper.ConfigurationFactory();
                break;

            case DBTypes.SQLite:
                config = SQLiteHelper.ConfigurationFactory();
                break;

            case DBTypes.MySQL:
            default:
                throw new NotImplementedException("Not implemented yet...");
            }

            var enversConf = new EnversNHibernate.Configuration.Fluent.FluentConfiguration();

            List <Type> domainEntities = Assembly.GetAssembly(typeof(Clients)).GetTypes() // Assembly.Load("bilisimHR.DataLayer.Core").GetTypes()
                                         .Where(t => (typeof(Entity <int>).IsAssignableFrom(t) && !t.IsGenericType))
                                         .ToList();

            foreach (Type type in domainEntities)
            {
                enversConf.Audit(type);
            }

            CoreNHibernate.Cfg.Configuration cfg = new CoreNHibernate.Cfg.Configuration();
            cfg = config.BuildConfiguration();

            cfg.BuildMappings();
            cfg.SetInterceptor(new TrackingInterceptor());

            //Envers RevType Values
            //0(ADD), 1(MODIFY) and 2(DELETE)
            ConfigurationKey.AuditTableSuffix.SetUserValue(cfg, "_LOG");
            IRevisionInfoService revInfoService = new RevisionInfoService();

            // Service Locator Registry
            ServiceLocator.RegisterService(revInfoService);
            ServiceLocator.RegisterService(new HttpRequestMessageService());

            enversConf.SetRevisionEntity <CustomRevInfo>(e => e.Id, e => e.RevisionDate, new CustomRevInfoListener());
            cfg.IntegrateWithEnvers(enversConf);

            config.ExposeConfiguration(exp => new SchemaUpdate(cfg).Execute(false, true))
            .ExposeConfiguration(c => { c.CurrentSessionContext <CoreNHibernate.Context.CallSessionContext>(); });
            //config.ExposeConfiguration(exp => new SchemaExport(cfg).Execute(true, true, false));
            return(config.BuildSessionFactory());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Cria o Schema do Banco a partir das classes mapeadas *.hbm.xml
        /// </summary>
        public static void ExportSchema()
        {
            //cria uma nova cgf no NHibernate
            var cfg = new Configuration();
            cfg.Configure();

                cfg.IntegrateWithEnvers(new AttributeConfiguration());

            //Executando o schema export
            var schemaExport = new SchemaExport(cfg);
            schemaExport.Execute(true, true, false);
        }
        private static void SetupConfiguration(NHibernate.Cfg.Configuration config)
        {
            //var resetDb = bool.Parse( ConfigurationManager.AppSettings["ResetDb"]);
            config.IntegrateWithEnvers(new AttributeConfiguration());

            var update = new SchemaUpdate(config);

            update.Execute(true, true);

            //bool clearDatabase = resetDb;
            //var filename = DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")+".sql";
            //new SchemaExport(config)
            //	//.SetOutputFile( Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(),filename))
            //	.Create(false, clearDatabase);
        }
Exemplo n.º 8
0
        static void CreateDatabase()
        {
            var configuration = new NHibernate.Cfg.Configuration();
            var _mapper       = new CustomModelMapper();

            configuration.DataBaseIntegration((x) =>
            {
                x.ConnectionString = @"Data Source=localhost;Initial Catalog=EnversBug;Persist Security Info=True;User ID=sa;Password=sa2008~";
                x.Dialect <MsSql2012Dialect>();
            });

            var types = typeof(Entity <>)
                        .Assembly
                        .GetTypes()
                        .Where(t => !t.IsInterface && !t.IsGenericType)
            ;

            _mapper.AddMappings(types);

            configuration.AddMapping(_mapper.CompileMappingFor(types));

            configuration.SetEnversProperty(ConfigurationKey.AuditTableSuffix, "_A");
            configuration.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true);
            configuration.SetEnversProperty(ConfigurationKey.RevisionOnCollectionChange, false);

            var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();

            enversConf.Audit(types);

            configuration.IntegrateWithEnvers(enversConf);


            var exporter = new SchemaExport(configuration);

            exporter.Execute(true, true, false);

            _sessionFactory = configuration.BuildSessionFactory();
        }
Exemplo n.º 9
0
        private static void BuildEnversConfiguration(Configuration configuration)
        {
            var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();

            IEnumerable<Type> entities = typeof(BaseEntity).Assembly.GetTypes()
                .Where(x => x.IsSubclassOf(typeof(BaseEntity)) && x.IsAbstract == false)
                .ToList();

            enversConf.Audit(entities);

            configuration.IntegrateWithEnvers(enversConf);
        }