示例#1
0
        public void HandleEvent(PreActionHookEvent eventMessage)
        {
            var entries = eventMessage.ModifiedEntries;

            if (!entries.Any() || !_preHooks.Any())
            {
                return;
            }

            foreach (var entry in entries)
            {
                var e        = entry;          // Prevents access to modified closure
                var preHooks = GetPreHookInstancesFor(e.Entity.GetType());
                foreach (var hook in preHooks)
                {
                    if (hook.HookStates == e.PreSaveState && hook.RequiresValidation == eventMessage.RequiresValidation)
                    {
                        var metadata = new HookEntityMetadata(e.PreSaveState);
                        hook.HookObject(e.Entity, metadata);

                        if (metadata.HasStateChanged)
                        {
                            e.PreSaveState = metadata.State;
                        }
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Implements the interface.  This causes the hook to only run for objects that are assignable to TEntity.
 /// </summary>
 public void HookObject(object entity, HookEntityMetadata metadata)
 {
     if (typeof(TEntity).IsAssignableFrom(entity.GetType()))
     {
         Hook((TEntity)entity, metadata);
     }
 }
示例#3
0
        public void HandleEvent(PostActionHookEvent eventMessage)
        {
            var entries = eventMessage.ModifiedEntries;

            if (!entries.Any() || !_postHooks.Any())
            {
                return;
            }

            foreach (var entry in entries)
            {
                var e         = entry;         // Prevents access to modified closure
                var postHooks = GetPostHookInstancesFor(e.Entity.GetType());
                foreach (var hook in postHooks)
                {
                    if (hook.HookStates == e.PreSaveState)
                    {
                        var metadata = new HookEntityMetadata(e.PreSaveState);
                        hook.HookObject(e.Entity, metadata);
                    }
                }
            }
        }
示例#4
0
 /// <summary>
 /// The logic to perform per entity after the registered action gets performed.
 /// This gets run once per entity that has been changed.
 /// </summary>
 public abstract void Hook(TEntity entity, HookEntityMetadata metadata);