/// <summary> /// Subscribe condition remove /// </summary> /// <param name="eventType">Event type</param> /// <param name="eventSourceType">Event source type</param> /// <param name="objectType">Event object type</param> /// <param name="eventHandlerType">Event handler type</param> /// <param name="actionName">Action name</param> public static void SubscribeConditionOperation(EventType eventType, 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(IQuery), typeof(ActivationOption) }); if (actionMember == null) { return; } var handlerAction = Delegate.CreateDelegate(typeof(ConditionOperation), eventHandler, actionMember); if (handlerAction == null) { return; } var conditionEventHandler = new ConditionEventHandler() { EventType = eventType, HandlerRepositoryType = eventHandler.GetType(), ObjectType = objectType, Operation = (ConditionOperation)handlerAction }; Subscribe(eventSource.GetType(), conditionEventHandler); }
/// <summary> /// Publish condition event /// </summary> /// <typeparam name="TObject">Data type</typeparam> /// <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 PublishCondition <TObject>(Type eventSource, EventType eventType, IQuery query, ActivationOption activationOption = null, RepositoryEventCallback callback = null) { var eventHandlers = GetEventHandlers(eventSource, eventType, typeof(TObject)); if (!eventHandlers.IsNullOrEmpty()) { foreach (var handler in eventHandlers) { ConditionEventHandler eventHandler = handler as ConditionEventHandler; if (eventHandler == null) { continue; } eventHandler.Execute(query, activationOption); } } callback?.Invoke(DataOperationEventExecuteResult.Empty); }