/// <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); }
/// <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="activationOptions">Activation options</param> /// <param name="callback">Callback</param> public static void PublishModify <TObject>(Type eventSource, IModify modify, IQuery query, ActivationOptions activationOptions = 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, activationOptions); } } callback?.Invoke(DataOperationEventExecuteResult.Empty); }
/// <summary> /// publish modify /// </summary> /// <param name="eventSource">event source</param> /// <param name="eventType">event type</param> /// <param name="query">query</param> /// <param name="callback">callback</param> public static void PublishModify <T>(Type eventSource, IModify modify, IQuery query, RepositoryEventCallback callback = null) { if (modify == null) { return; } var eventHandlers = GetEventHandlers(eventSource, EventType.ModifyExpression, typeof(T)); if (eventHandlers.IsNullOrEmpty()) { callback?.Invoke(DataOperationEventResult.Empty); return; } foreach (var handler in eventHandlers) { ModifyEventHandler eventHandler = handler as ModifyEventHandler; if (eventHandler == null) { continue; } eventHandler.Execute(modify, query); } callback?.Invoke(DataOperationEventResult.Empty); }