Example #1
0
        public static object ExecutinonMethod(string ass, string className, string method, HttpContext context)
        {
            var result = new AjaxResult();
            try
            {
                var info = new MethodPathInfo
                               {
                                   Assembly = ass,
                                   ClassName = className,
                                   MethodName = method
                               };
                var helper = new MethodHelper(context, info);
                var m = helper.GetMethod();
                if (method != null)
                {
                    result.state = 1;
                    var rt = (helper.ExecutinonMethod(m) ?? string.Empty);
                    if (rt is string)
                        result.result = rt;
                    else
                        result.result = rt;

                }
                else
                {
                    result.state = 0;
                    result.msg = "方法调用失败!";
                }
                return result.state == 1 ? result.result : result;
            }
            catch (AjaxException ex)
            {
                return ex.GetResult();
            }
        }
Example #2
0
 public MethodHelper(HttpContext context, MethodPathInfo info)
 {
     if (context == null)
         throw new AjaxException("没有请求上下文!");
     if (!info.IsValidate)
         throw new AjaxException("请求路径错误!");
     _context = context;
     _pathInfo = info;
 }
Example #3
0
        /// <summary>
        /// 得到方法的一些基本的路径信息
        /// </summary>
        /// <param name="virtualPath"></param>
        /// <returns></returns>
        public static MethodPathInfo GetMethodPathInfo(string virtualPath)
        {
            MethodPathInfo methodPathInfo = null;

            Match match = Regex.Match(virtualPath, RegexText, RegexOptions.IgnoreCase);
            //如果匹配到了
            if (match.Success)
            {
                //取出class和method
                methodPathInfo = new MethodPathInfo
                                     {
                                         ClassName = match.Groups["class"].Value.Replace("/", "."),
                                         MethodName = match.Groups["method"].Value,
                                         Assembly = Assembly
                                     };
            }
            return methodPathInfo;
        }
Example #4
0
 /// <summary>
 /// 构造方法  主要是初始化请求方法的一些路径信息 比如 空间 类  方法名
 /// </summary>
 ///<param name="virtualPath">请求的一个虚拟路径</param>
 public ResponseHandler(string virtualPath)
 {
     CurrentMethodPathInfo = UrlHelper.GetMethodPathInfo(virtualPath);
 }