コード例 #1
0
        /// <summary>
        /// Integrate ActsAsVersioned with NHibernate.
        /// </summary>
        /// <param name="configuration">The NHibernate configuration.</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 IntegrateWithActsAsVersioned(this Configuration configuration)
        {
            const string integratedKey = "ActsAsVersioned_Integrated";

            if (configuration.GetProperty(integratedKey) != null)
            {
                Logger.Warn($"{nameof(IntegrateWithActsAsVersioned)} has already been called for this configuration");
                return(configuration);
            }

            var versionedClasses = new List <VersionedClass>();

            foreach (var pc in configuration.ClassMappings)
            {
                if (!VersionedClass.IsActsAsVersioned(pc))
                {
                    continue;
                }

                versionedClasses.Add(new VersionedClass(pc));
            }

            if (versionedClasses.Count == 0)
            {
                // nothing to do
                return(configuration);
            }

            var mapping = configuration.BuildMapping();

            foreach (var vc in versionedClasses)
            {
                vc.UpdateConfiguration(configuration, mapping);
            }

            var listeners = new[] { new VersionedEventListener(versionedClasses) };

            // ReSharper disable CoVariantArrayConversion
            configuration.AppendListeners(ListenerType.PostInsert, listeners);
            configuration.AppendListeners(ListenerType.PostUpdate, listeners);
            configuration.AppendListeners(ListenerType.PostDelete, listeners);
            // ReSharper restore CoVariantArrayConversion

            configuration.SetProperty(integratedKey, "1");
            return(configuration);
        }
コード例 #2
0
        private void AppendListeners(NHibernate.Cfg.Configuration configuration)
        {
            configuration.AppendListeners(ListenerType.PreInsert,
                                          new[]
            {
                new SetCoreProperties()
            });
            SoftDeleteListener softDeleteListener = new SoftDeleteListener();

            configuration.SetListener(ListenerType.Delete, softDeleteListener);
        }
コード例 #3
0
        private static void addListeners(Configuration cfg, AuditEventListener auditEventListener)
        {
            var listeners = 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);
        }
コード例 #4
0
 protected virtual void ConfigurePersistence(Configuration config)
 {
     config.AppendListeners(ListenerType.PreUpdate, new[] { new AuditEventListener() });
     config.AppendListeners(ListenerType.PreInsert, new[] { new AuditEventListener() });
     SchemaMetadataUpdater.QuoteTableAndColumns(config);
 }
コード例 #5
0
        public static Configuration AddEventListener(this Configuration config, ListenerType listenerType, object o)
        {
            //config.AppendListeners(listenerType, new [] { o });
            switch (listenerType)
            {
            case ListenerType.Autoflush: config.AppendListeners(ListenerType.Autoflush, new [] { (IAutoFlushEventListener)o });  break;

            case ListenerType.Merge: config.AppendListeners(ListenerType.Merge, new [] { (IMergeEventListener)o }); break;

            case ListenerType.Create: config.AppendListeners(ListenerType.Create, new [] { (IPersistEventListener)o }); break;

            case ListenerType.CreateOnFlush: config.AppendListeners(ListenerType.CreateOnFlush, new [] { (IPersistEventListener)o }); break;

            case ListenerType.Delete: config.AppendListeners(ListenerType.Delete, new [] { (IDeleteEventListener)o }); break;

            case ListenerType.DirtyCheck: config.AppendListeners(ListenerType.DirtyCheck, new [] { (IDirtyCheckEventListener)o }); break;

            case ListenerType.Evict: config.AppendListeners(ListenerType.Evict, new [] { (IEvictEventListener)o }); break;

            case ListenerType.Flush: config.AppendListeners(ListenerType.Flush, new [] { (IFlushEventListener)o }); break;

            case ListenerType.FlushEntity: config.AppendListeners(ListenerType.FlushEntity, new [] { (IFlushEntityEventListener)o }); break;

            case ListenerType.Load: config.AppendListeners(ListenerType.Load, new [] { (ILoadEventListener)o }); break;

            case ListenerType.LoadCollection: config.AppendListeners(ListenerType.LoadCollection, new [] { (IInitializeCollectionEventListener)o }); break;

            case ListenerType.Lock: config.AppendListeners(ListenerType.Lock, new [] { (ILockEventListener)o }); break;

            case ListenerType.Refresh: config.AppendListeners(ListenerType.Refresh, new [] { (IRefreshEventListener)o }); break;

            case ListenerType.Replicate: config.AppendListeners(ListenerType.Replicate, new [] { (IReplicateEventListener)o }); break;

            case ListenerType.SaveUpdate: config.AppendListeners(ListenerType.SaveUpdate, new [] { (ISaveOrUpdateEventListener)o }); break;

            case ListenerType.Save: config.AppendListeners(ListenerType.Save, new [] { (ISaveOrUpdateEventListener)o }); break;

            case ListenerType.PreUpdate: config.AppendListeners(ListenerType.PreUpdate, new [] { (IPreUpdateEventListener)o }); break;

            case ListenerType.Update: config.AppendListeners(ListenerType.Update, new [] { (ISaveOrUpdateEventListener)o }); break;

            case ListenerType.PreLoad: config.AppendListeners(ListenerType.PreLoad, new [] { (IPreLoadEventListener)o }); break;

            case ListenerType.PreDelete: config.AppendListeners(ListenerType.PreDelete, new [] { (IPreDeleteEventListener)o }); break;

            case ListenerType.PreInsert: config.AppendListeners(ListenerType.PreInsert, new [] { (IPreInsertEventListener)o }); break;

            case ListenerType.PostLoad: config.AppendListeners(ListenerType.PostLoad, new [] { (IPostLoadEventListener)o }); break;

            case ListenerType.PostInsert: config.AppendListeners(ListenerType.PostInsert, new [] { (IPostInsertEventListener)o }); break;

            case ListenerType.PostUpdate: config.AppendListeners(ListenerType.PostUpdate, new [] { (IPostUpdateEventListener)o }); break;

            case ListenerType.PostDelete: config.AppendListeners(ListenerType.PostDelete, new [] { (IPostDeleteEventListener)o }); break;

            case ListenerType.PostCommitUpdate: config.AppendListeners(ListenerType.PostCommitUpdate, new [] { (IPostUpdateEventListener)o }); break;

            case ListenerType.PostCommitInsert: config.AppendListeners(ListenerType.PostCommitInsert, new [] { (IPostInsertEventListener)o }); break;

            case ListenerType.PostCommitDelete: config.AppendListeners(ListenerType.PostCommitDelete, new [] { (IPostDeleteEventListener)o }); break;

            case ListenerType.PreCollectionRecreate: config.AppendListeners(ListenerType.PreCollectionRecreate, new [] { (IPreCollectionRecreateEventListener)o }); break;

            case ListenerType.PreCollectionRemove: config.AppendListeners(ListenerType.PreCollectionRemove, new [] { (IPreCollectionRemoveEventListener)o }); break;

            case ListenerType.PreCollectionUpdate: config.AppendListeners(ListenerType.PreCollectionUpdate, new [] { (IPreCollectionUpdateEventListener)o }); break;

            case ListenerType.PostCollectionRecreate: config.AppendListeners(ListenerType.PostCollectionRecreate, new [] { (IPostCollectionRecreateEventListener)o }); break;

            case ListenerType.PostCollectionRemove: config.AppendListeners(ListenerType.PostCollectionRemove, new [] { (IPostCollectionRemoveEventListener)o }); break;

            case ListenerType.PostCollectionUpdate: config.AppendListeners(ListenerType.PostCollectionUpdate, new [] { (IPostCollectionUpdateEventListener)o }); break;
            }
            return(config);
        }
コード例 #6
0
        public static void ClassInit(TestContext context)
        {
            EventListener eventListener = new EventListener();
            Configuration cfg = new Configuration();
            cfg.DataBaseIntegration(db =>
            {
                db.Dialect<MsSql2008Dialect>();
                db.LogFormattedSql = true;
                db.LogSqlInConsole = true;
                db.ConnectionStringName = "Blogger";
            });
            cfg.AddAssembly(Assembly.GetExecutingAssembly());
            cfg.AppendListeners(ListenerType.PreLoad, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PreInsert, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PreUpdate, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PreDelete, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PostLoad, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PostInsert, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PostUpdate, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PostDelete, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PreCollectionRecreate, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PreCollectionRemove, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PreCollectionUpdate, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PostCollectionRecreate, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PostCollectionRemove, new[] { eventListener });
            cfg.AppendListeners(ListenerType.PostCollectionUpdate, new[] { eventListener });
            cfg.AppendListeners(ListenerType.Load, new[] { eventListener });
            cfg.AppendListeners(ListenerType.SaveUpdate, new[] { eventListener });
            cfg.AppendListeners(ListenerType.Delete, new[] { eventListener });

            factory = cfg.BuildSessionFactory();
            try
            {
                new SchemaValidator(cfg).Validate();
            }
            catch (Exception)
            {
                new SchemaUpdate(cfg).Execute(false, true);
            }
        }
コード例 #7
0
ファイル: ListenerDisablerTests.cs プロジェクト: neozhu/MrCMS
 protected override void AppendConfiguration(Configuration configuration)
 {
     TestListener.Reset();
     _testListener = new TestListener();
     configuration.AppendListeners(ListenerType.PostCommitInsert, new IPostInsertEventListener[] { TestListener });
 }