Exemple #1
0
        /// <summary>
        /// 重写以实现触发事件的执行
        /// </summary>
        /// <param name="factory">事件处理器工厂</param>
        /// <param name="eventType">事件类型</param>
        /// <param name="eventData">事件数据</param>
        /// <param name="wait">是否等待结果返回</param>
        protected void InvokeHandler(IEventHandlerFactory factory, Type eventType, IEventData eventData, bool wait = true)
        {
            EventHandlerDisposeWrapper handlerWrapper = factory.GetHandler();
            IEventHandler handler = handlerWrapper.EventHandler;

            try
            {
                if (handler == null)
                {
                    Logger.LogWarning($"事件源“{eventData.GetType()}”的事件处理器无法找到");
                    return;
                }
                if (!handler.CanHandle(eventData))
                {
                    return;
                }
                if (wait)
                {
                    Run(factory, handler, eventType, eventData);
                }
                else
                {
                    Task.Run(() =>
                    {
                        Run(factory, handler, eventType, eventData);
                    });
                }
            }
            finally
            {
                handlerWrapper.Dispose();
            }
        }
Exemple #2
0
        /// <summary>
        /// 重写以实现异步触发事件的执行
        /// </summary>
        /// <param name="factory">事件处理器工厂</param>
        /// <param name="eventType">事件类型</param>
        /// <param name="eventData">事件数据</param>
        /// <param name="wait">是否等待结果返回</param>
        /// <returns></returns>
        protected virtual async Task InvokeHandlerAsync(IEventHandlerFactory factory, Type eventType, IEventData eventData, bool wait = true)
        {
            EventHandlerDisposeWrapper handlerWrapper = factory.GetHandler();
            IEventHandler handler = handlerWrapper.EventHandler;

            try
            {
                if (handler == null)
                {
                    Logger.LogWarning($"事件源“{eventData.GetType()}”的事件处理器无法找到");
                    return;
                }
                if (wait)
                {
                    await RunAsync(factory, handler, eventType, eventData);

                    return;
                }
                Task.Run(async() =>
                {
                    await RunAsync(factory, handler, eventType, eventData);
                });
            }
            finally
            {
                handlerWrapper.Dispose();
            }
        }
Exemple #3
0
        /// <summary>
        /// 重写以实现触发事件的执行
        /// </summary>
        /// <param name="factory">事件处理器工厂</param>
        /// <param name="eventType">事件类型</param>
        /// <param name="eventData">事件数据</param>
        protected void InvokeHandler(IEventHandlerFactory factory, Type eventType, IEventData eventData)
        {
            EventHandlerDisposeWrapper handlerWrapper = factory.GetHandler();
            IEventHandler handler = handlerWrapper.EventHandler;

            try
            {
                if (handler == null)
                {
                    Logger.LogWarning($"事件源“{eventData.GetType()}”的事件处理器无法找到");
                    return;
                }

                Run(handler, eventType, eventData);
            }
            finally
            {
                handlerWrapper.Dispose();
            }
        }