コード例 #1
0
        /// <summary>
        /// Trigger Command starting event
        /// </summary>
        /// <returns>Return starting event result</returns>
        public CommandStartingEventExecuteResult TriggerStartingEvent()
        {
            #region Execute async handlers

            if (!AsyncExecutingEventHandlers.IsNullOrEmpty())
            {
                AsyncExecutingEventHandlers.ForEach(handler =>
                {
                    var eventHandler = handler;
                    ThreadPool.QueueUserWorkItem(s => { eventHandler.Item1(handler.Item2); });
                });
            }

            #endregion

            #region Execut sync handlers

            if (SyncExecutingEventHandlers.IsNullOrEmpty())
            {
                return(CommandStartingEventExecuteResult.DefaultSuccess);
            }
            CommandStartingEventExecuteResult result = null;
            foreach (var handler in SyncExecutingEventHandlers)
            {
                result = handler.Item1(handler.Item2);
                if (result?.BreakCommand ?? false)
                {
                    break;
                }
            }
            return(result ?? CommandStartingEventExecuteResult.DefaultSuccess);

            #endregion
        }
コード例 #2
0
        /// <summary>
        /// Trigger Command starting event
        /// </summary>
        /// <returns>Return starting event result</returns>
        public CommandStartingEventExecuteResult TriggerStartingEvent()
        {
            #region Execute async handlers

            if (!AsyncExecutingEventHandlers.IsNullOrEmpty())
            {
                AsyncExecutingEventHandlers.ForEach(handler =>
                {
                    var eventHandler = handler;
                    ThreadPool.QueueUserWorkItem(s => { eventHandler.Item1(handler.Item2); });
                });
            }

            #endregion

            #region Execut sync handlers

            if (SyncExecutingEventHandlers.IsNullOrEmpty())
            {
                return(CommandStartingEventExecuteResult.DefaultSuccess);;
            }
            var result = new CommandStartingEventExecuteResult();
            foreach (var handler in SyncExecutingEventHandlers)
            {
                var eventResult = handler.Item1(handler.Item2);
                result.AllowExecuteCommand = result.AllowExecuteCommand && eventResult.AllowExecuteCommand;
                if (!result.AllowExecuteCommand)
                {
                    break;
                }
            }
            return(result);

            #endregion
        }