Exemplo n.º 1
0
        public void InitializeAudit()
        {
            var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();

            enversConf.Audit(GetDomainEntities());
            configure.IntegrateWithEnvers(enversConf);
        }
        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.º 3
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);
        }
Exemplo n.º 4
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.º 5
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);
        }