Exemplo n.º 1
0
        /// <summary>
        /// 控制器执行的主入口方法
        /// </summary>
        private void OnProcessRequest()
        {
            //获取操作方法
            ActionMethodInfo action = ((IActionExecutor)this).ActionSelector.GetActionMethod(ControllerContext);

            //调用预置方法
            if (this._PreActionExecute != null)
            {
                this._PreActionExecute(this, new ActionEventArgs(Name, ControllerContext.ActionName));
            }
            PreActionExecute();

            //执行操作方法
            ((IActionExecutor)this).ExecuteAction(action);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 从当前控制器实例执行请求的操作方法
        /// </summary>
        void IActionExecutor.ExecuteAction(ActionMethodInfo action)
        {
            if (action == null)
            {
                var op = OnActionNotFound();
                switch (op.ToDo)
                {
                case DecisiveOperatingInstruction.Operation.Abort: return;

                case DecisiveOperatingInstruction.Operation.ThrowException: throw op.ExcpetionToThrow;

                case DecisiveOperatingInstruction.Operation.NoOperation: break;
                }
                if (_ActionNotFound != null)
                {
                    _ActionNotFound(this, new ActionEventArgs(Name, ControllerContext.ActionName));
                }
            }
            else
            {
                try
                {
                    action.BaseMethod.Invoke(this, action.Parameters);
                }
                catch (Threading.ThreadAbortException)
                {
                    //此异常由HttpResponse.End()导致,无需处理
                }
                catch (Exception e)
                {
                    var op = OnActionExecutionError(e);
                    switch (op.ToDo)
                    {
                    case DecisiveOperatingInstruction.Operation.Abort: return;

                    case DecisiveOperatingInstruction.Operation.ThrowException: throw op.ExcpetionToThrow;

                    case DecisiveOperatingInstruction.Operation.NoOperation: break;
                    }
                    if (_ActionExecutionError != null)
                    {
                        _ActionExecutionError(this, new ActionExecutionErrorEventArgs(Name, ControllerContext.ActionName, e));
                    }
                    throw e;
                }
            }
        }