Ejemplo n.º 1
0
        /// <summary>
        /// 根据一个页面请求路径,返回内部表示的调用信息。
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public InvokeInfo GetActionInvokeInfo(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }


            MatchActionDescription md     = null;
            ActionDescription      action = null;

            // 先直接用URL从字典中查找匹配项。
            if (s_metadata.PageActionDict.TryGetValue(url, out action) == false)
            {
                // 如果不能直接匹配URL,就用正则表达式再逐个匹配。
                md = GetActionByRegex(url);
                if (md == null)
                {
                    if (this.DiagnoseResult != null)
                    {
                        // 填充诊断结果
                        SetPageUrlDiagnoseResult(url);
                    }


                    return(null);
                }
                else
                {
                    action = md.ActionDescription;
                }
            }

            InvokeInfo vkInfo = new InvokeInfo();

            vkInfo.Controller = action.PageController;
            vkInfo.Action     = action;

            if (md != null)
            {
                vkInfo.RegexMatch = md.Match;
            }

            if (vkInfo.Action.MethodInfo.IsStatic == false)
            {
                vkInfo.Instance = ControllerFactory.GetController(vkInfo.Controller.ControllerType);
            }


            return(vkInfo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据一个Action的调用信息(类名与方法名),返回内部表示的调用信息。
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public InvokeInfo GetActionInvokeInfo(UrlActionInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            HttpRequest request = _context.Request;

            if (info.Action == null)
            {
                info.Action = info.MethodName;
            }

            if (info.Controller == null)
            {
                info.Namesapce  = GetNamespaceMap(info.Namesapce);
                info.Controller = s_recognizer.GetServiceFullName(info);
            }

            InvokeInfo vkInfo = new InvokeInfo();

            vkInfo.Controller = info.ControllerDescription ?? GetServiceController(info.Controller);
            if (vkInfo.Controller == null)
            {
                return(null);
            }


            vkInfo.Action = info.ActionDescription ?? GetServiceAction(vkInfo.Controller.ControllerType, info.Action);
            if (vkInfo.Action == null)
            {
                return(null);
            }

            if (vkInfo.Action.MethodInfo.IsStatic)
            {
                throw new NotSupportedException("不支持静态的Action方法。");
            }


            vkInfo.Instance = ControllerFactory.GetController(vkInfo.Controller.ControllerType);

            vkInfo.UrlActionInfo = info;
            return(vkInfo);
        }