public static bool Publish(IEntity entity, EntityPersistentEventType eventType)
        {
            var _event  = new EntityEventArgs(entity, eventType);
            var subject = new EntityPersistentSubject(entity.EntityType, eventType, _event);

            SynchronizedSubscribeManager.Instance.Publish(subject);

            return(!_event.Cancel);
        }
        public static bool Publish <TEntity>(EntityPersistentEventType eventType)
        {
            var _event  = new EntityEventTypeArgs(eventType);
            var subject = new EntityPersistentSubject(typeof(TEntity), eventType, _event);

            SynchronizedSubscribeManager.Instance.Publish(subject);

            return(!_event.Cancel);
        }
        public static bool Publish <TEntity>(IEnumerable <IEntity> entities, EntityPersistentOperater operType, EntityPersistentEventType eventType)
        {
            var _event  = new EntitiesArgs(entities, operType, eventType);
            var subject = new EntityPersistentSubject(typeof(TEntity), eventType, _event);

            SynchronizedSubscribeManager.Instance.Publish(subject);

            return(!_event.Cancel);
        }
        /// <summary>
        /// 接收主题信息并进行处理。
        /// </summary>
        /// <param name="subject"></param>
        public void Accept(EntityPersistentSubject subject)
        {
            switch (subject.EventType)
            {
            case EntityPersistentEventType.BeforeCreate:
            {
                if (subject.Argument is EntityEventArgs arg)
                {
                    arg.Cancel = !OnBeforeCreate(arg.Entity);
                }
            }
            break;

            case EntityPersistentEventType.AfterCreate:
            {
                if (subject.Argument is EntityEventArgs arg)
                {
                    OnAfterCreate(arg.Entity);
                }
            }

                OnCreate(subject.EntityType);
                break;

            case EntityPersistentEventType.BeforeUpdate:
            {
                if (subject.Argument is EntityEventArgs arg)
                {
                    arg.Cancel = !OnBeforeUpdate(arg.Entity);
                }
            }
            break;

            case EntityPersistentEventType.AfterUpdate:
            {
                if (subject.Argument is EntityEventArgs arg)
                {
                    OnAfterUpdate(arg.Entity);
                }
            }

                OnUpdate(subject.EntityType);
                break;

            case EntityPersistentEventType.BeforeRemove:
            {
                if (subject.Argument is EntityEventArgs arg)
                {
                    arg.Cancel = !OnBeforeRemove(arg.Entity);
                }
            }
            break;

            case EntityPersistentEventType.AfterRemove:
            {
                if (subject.Argument is EntityEventArgs arg)
                {
                    OnAfterRemove(arg.Entity);
                }
            }

                OnRemove(subject.EntityType);
                break;

            case EntityPersistentEventType.BeforeBatch:
            {
                var arg = subject.Argument as EntitiesArgs;
                arg.Cancel = !OnBeforeBatch(arg.Entities, arg.OperType);
            }
            break;

            case EntityPersistentEventType.AfterBatch:
            {
                var arg = subject.Argument as EntitiesArgs;
                OnAfterBatch(arg.Entities, arg.OperType);

                switch (arg.OperType)
                {
                case EntityPersistentOperater.Create:
                    OnCreate(subject.EntityType);
                    break;

                case EntityPersistentOperater.Update:
                    OnUpdate(subject.EntityType);
                    break;

                case EntityPersistentOperater.Remove:
                    OnRemove(subject.EntityType);
                    break;
                }
            }

            break;
            }
        }
Exemple #5
0
        public static void Publish(IEntity entity, EntityPersistentEventType eventType)
        {
            var subject = new EntityPersistentSubject(entity.EntityType, eventType, new EntityEventArgs(entity, eventType));

            DefaultSubscribeManager.Instance.Publish(subject);
        }
Exemple #6
0
        public static void Publish <TEntity>(EntityPersistentEventType eventType)
        {
            var subject = new EntityPersistentSubject(typeof(TEntity), eventType, new EntityEventTypeArgs(eventType));

            DefaultSubscribeManager.Instance.Publish(subject);
        }
Exemple #7
0
        public static void Publish <TEntity>(IEnumerable <IEntity> entities, EntityPersistentOperater operType, EntityPersistentEventType eventType)
        {
            var subject = new EntityPersistentSubject(typeof(TEntity), eventType, new EntitiesArgs(entities, operType, eventType));

            DefaultSubscribeManager.Instance.Publish(subject);
        }