コード例 #1
0
        /// <summary>
        /// Subscribe condition remove
        /// </summary>
        /// <param name="eventSourceType">Event source type</param>
        /// <param name="objectType">Object type</param>
        /// <param name="eventHandlerType">Event handler type</param>
        /// <param name="actionName">Action name</param>
        public static void SubscribeModify(Type eventSourceType, Type objectType, Type eventHandlerType, string actionName)
        {
            if (eventSourceType == null || eventHandlerType == null || objectType == null || string.IsNullOrWhiteSpace(actionName))
            {
                return;
            }
            var eventSource  = ContainerManager.Resolve(eventSourceType);
            var eventHandler = ContainerManager.Resolve(eventHandlerType);

            if (eventSource == null || eventHandler == null)
            {
                return;
            }
            var actionMember = eventHandler.GetType().GetMethod(actionName, new Type[] { typeof(IModify), typeof(IQuery) });

            if (actionMember == null)
            {
                return;
            }
            var handlerAction = Delegate.CreateDelegate(typeof(ModifyOperation), eventHandler, actionMember);

            if (handlerAction == null)
            {
                return;
            }
            var modifyEventHandler = new ModifyEventHandler()
            {
                EventType             = EventType.ModifyExpression,
                HandlerRepositoryType = eventHandler.GetType(),
                ObjectType            = objectType,
                Operation             = (ModifyOperation)handlerAction
            };

            Subscribe(eventSource.GetType(), modifyEventHandler);
        }
コード例 #2
0
        /// <summary>
        /// Publish modify event
        /// </summary>
        /// <param name="eventSource">Event source type</param>
        /// <param name="eventType">Event type</param>
        /// <param name="query">Query</param>
        /// <param name="activationOption">Activation option</param>
        /// <param name="callback">Callback</param>
        public static void PublishModify <TObject>(Type eventSource, IModify modify, IQuery query, ActivationOption activationOption = null, RepositoryEventCallback callback = null)
        {
            var eventHandlers = GetEventHandlers(eventSource, EventType.ModifyExpression, typeof(TObject));

            if (!eventHandlers.IsNullOrEmpty())
            {
                foreach (var handler in eventHandlers)
                {
                    ModifyEventHandler eventHandler = handler as ModifyEventHandler;
                    if (eventHandler == null)
                    {
                        continue;
                    }
                    eventHandler.Execute(modify, query, activationOption);
                }
            }
            callback?.Invoke(DataOperationEventExecuteResult.Empty);
        }