Ejemplo n.º 1
0
 public object[] GetParameters(System.Web.HttpRequest request, ActionDescription action)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     object[] parameters = new object[action.Parameters.Length];
     byte[]   input      = request.BinaryRead(request.TotalBytes);
     for (int i = 0; i < action.Parameters.Length; i++)
     {
         ParameterInfo p = action.Parameters[i];
         if (p.IsOut)
         {
             continue;
         }
         if (p.ParameterType == typeof(byte[]))
         {
             parameters[i] = input;
         }
     }
     return(parameters);
 }
Ejemplo n.º 2
0
 public object[] GetParameters(System.Web.HttpRequest request, ActionDescription action)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     object[] parameters = new object[action.Parameters.Length];
     for (int i = 0; i < action.Parameters.Length; i++)
     {
         ParameterInfo p = action.Parameters[i];
         if (p.IsOut)
         {
             continue;
         }
         Type paramterType = p.ParameterType.GetRealType();
         //如果参数是可支持的类型,直接从HttpRequest中读取并赋值
         if (paramterType.IsSupportableType())
         {
         }
     }
 }
Ejemplo n.º 3
0
 private static object[] GetActionCallParameters(HttpContext context, ActionDescription action)
 {
     if (action.Parameters == null || action.Parameters.Length == 0)
     {
         return null;
     }
     IActionParamProvider provider = ActionParametersProviderFactory.CreateActionParamProvider(context.Request);
     return provider.GetParameters(context.Request, action);
 }
Ejemplo n.º 4
0
        private static object[] GetActionCallParameters(HttpContext context, ActionDescription action)
        {
            if (action.Parameters == null || action.Parameters.Length == 0)
            {
                return(null);
            }
            IActionParamProvider provider = ActionParametersProviderFactory.CreateActionParamProvider(context.Request);

            return(provider.GetParameters(context.Request, action));
        }
Ejemplo n.º 5
0
        public object[] GetParameters(HttpRequest request, ActionDescription action)
        {
            if (request == null)
                throw new ArgumentNullException("request");
            if (action == null)
                throw new ArgumentNullException("action");
            object[] parameters = new object[action.Parameters.Length];
            for (int i = 0; i < action.Parameters.Length; i++)
            {
                ParameterInfo p = action.Parameters[i];
                if (p.IsOut)
                    continue;
                if (p.ParameterType == typeof(NameValueCollection))
                {
                    if (string.Compare(p.Name, "Form", StringComparison.OrdinalIgnoreCase) == 0)
                        parameters[i] = request.Form;
                    else if (string.Compare(p.Name, "QueryString", StringComparison.OrdinalIgnoreCase) == 0)
                        parameters[i] = request.QueryString;
                }
                else
                {
                    Type paramterType = p.ParameterType.GetRealType();
                    //
                    if (paramterType.IsSupportableType())
                    {
                        object val = ModelHelper.GetValueByNameAndTypeFromRequest(request, p.Name, paramterType, null);
                        if (val != null)
                            parameters[i] = val;
                        else
                        {
                            if (p.ParameterType.IsValueType || p.ParameterType.IsNullableType() == true)
                            {

                            }
                            else if (p.ParameterType.FullName == "System.String")
                            {

                            }
                            else
                            {
                                throw new ArgumentException("未能找到指定的参数值:" + p.Name);
                            }
                        }
                    }
                    else
                    {
                        // 自定义的类型。首先创建实例,然后给所有成员赋值。  暂不支持
                        // 注意:这里不支持嵌套类型的自定义类型。
                        //object item = Activator.CreateInstance(paramterType);

                    }
                }
            }
            return parameters;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 加载所有Controller
 /// </summary>
 private static void InitControllers()
 {
     List<ControllerDescription> controllerList = new List<ControllerDescription>();//控制器集合
     ICollection assemblies = BuildManager.GetReferencedAssemblies();
     foreach (Assembly assembly in assemblies)
     {
         //过滤system开头的程序集,加快速度
         if (assembly.FullName.StartsWith("System", StringComparison.OrdinalIgnoreCase))
             continue;
         foreach (Type t in assembly.GetExportedTypes())
         {
             if (t.IsClass == false)
                 continue;
             if (t.Name.EndsWith("Controller"))
             {
                 AllowRoleAttribute allowRole = null;
                 AllowUserAttribute allowUser = null;
                 IControllerInjector injector = null;
                 if (t.GetCustomAttributes(typeof(AllowRoleAttribute), false).Length != 0)
                 {
                     allowRole = (AllowRoleAttribute)t.GetCustomAttributes(typeof(AllowRoleAttribute), false)[0];
                 }
                 if (t.GetCustomAttributes(typeof(AllowUserAttribute), false).Length != 0)
                 {
                     allowUser = (AllowUserAttribute)t.GetCustomAttributes(typeof(AllowUserAttribute), false)[0];
                 }
                 if (t.GetCustomAttributes(typeof(IControllerInjector), false).Length != 0)
                 {
                     injector = (IControllerInjector)t.GetCustomAttributes(typeof(IControllerInjector), false)[0];
                 }
                 controllerList.Add(new ControllerDescription(t, allowRole, allowUser, injector));
             }
         }
     }
     s_ControllerNameDict = controllerList.ToDictionary(x => x.ControllerType.Name, StringComparer.OrdinalIgnoreCase);
     // 提前加载Page Controller中的所有Action方法
     s_ControllerActionDict = new Dictionary<string, ActionDescription>();
     foreach (ControllerDescription controller in controllerList)
     {
         foreach (MethodInfo m in controller.ControllerType.GetMethods(ActionBindingFlags))
         {
             if (m.Name.EndsWith("Action"))
             {
                 ActionAttribute actionAttr = m.GetMyAttribute<ActionAttribute>();
                 AllowRoleAttribute allowRole = m.GetMyAttribute<AllowRoleAttribute>();
                 AllowUserAttribute allowUser = m.GetMyAttribute<AllowUserAttribute>();
                 ActionDescription actionDescription = new ActionDescription(m, actionAttr, allowRole, allowUser) { PageController = controller };
                 s_ControllerActionDict.Add(controller.ControllerType.Name.ToLower() + "_" + m.Name.ToLower(), actionDescription);
             }
         }
     }
 }
Ejemplo n.º 7
0
 public object[] GetParameters(System.Web.HttpRequest request, ActionDescription action)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     object[] parameters = new object[action.Parameters.Length];
     for (int i = 0; i < request.Files.Count; i++)
     {
         parameters[i] = request.Files[i];
     }
     return(parameters);
 }
Ejemplo n.º 8
0
 public object[] GetParameters(System.Web.HttpRequest request, ActionDescription action)
 {
     if (request == null)
         throw new ArgumentNullException("request");
     if (action == null)
         throw new ArgumentNullException("action");
     object[] parameters = new object[action.Parameters.Length];
     for (int i = 0; i < action.Parameters.Length; i++)
     {
         ParameterInfo p = action.Parameters[i];
         if (p.IsOut)
             continue;
         Type paramterType = p.ParameterType.GetRealType();
         //如果参数是可支持的类型,直接从HttpRequest中读取并赋值
         if (paramterType.IsSupportableType()) { 
             
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 根据URL获取 调用信息
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static InvokeInfo GetInvokeInfo(string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException("url");
            }
            if (url == "/")
            {
                if (RouteTable.Routes["Default"] != null)
                {
                    //string a = ((Route)(RouteTable.Routes["Default"]));
                    //url = url + ((Route)(RouteTable.Routes["Default"])).Defaults.Values["0"].ToString() + "/" + ((Route)(RouteTable.Routes["Default"])).Defaults.Values[1];
                }
            }
            url = url.StartsWith("/") ? url.Substring(1) : url;
            if (url.Contains('.'))
            {
                url = url.Substring(0, url.IndexOf("."));
            }
            string[] controllerActionPair = url.Split('/');
            string   controllerName       = (controllerActionPair[0] + "Controller").ToLower();
            string   actionName           = (controllerActionPair[1] + "Action").ToLower();

            if (s_ControllerActionDict.ContainsKey(controllerName + "_" + actionName))
            {
                ActionDescription action = s_ControllerActionDict[controllerName + "_" + actionName];
                InvokeInfo        vkInfo = new InvokeInfo();
                vkInfo.Controller = action.PageController;
                vkInfo.Action     = action;
                vkInfo.Instance   = vkInfo.Controller.ControllerType.FastNew();
                return(vkInfo);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 加载所有Controller
        /// </summary>
        private static void InitControllers()
        {
            List <ControllerDescription> controllerList = new List <ControllerDescription>();//控制器集合
            ICollection assemblies = BuildManager.GetReferencedAssemblies();

            foreach (Assembly assembly in assemblies)
            {
                //过滤system开头的程序集,加快速度
                if (assembly.FullName.StartsWith("System", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                foreach (Type t in assembly.GetExportedTypes())
                {
                    if (t.IsClass == false)
                    {
                        continue;
                    }
                    if (t.Name.EndsWith("Controller"))
                    {
                        AllowRoleAttribute  allowRole = null;
                        AllowUserAttribute  allowUser = null;
                        IControllerInjector injector  = null;
                        if (t.GetCustomAttributes(typeof(AllowRoleAttribute), false).Length != 0)
                        {
                            allowRole = (AllowRoleAttribute)t.GetCustomAttributes(typeof(AllowRoleAttribute), false)[0];
                        }
                        if (t.GetCustomAttributes(typeof(AllowUserAttribute), false).Length != 0)
                        {
                            allowUser = (AllowUserAttribute)t.GetCustomAttributes(typeof(AllowUserAttribute), false)[0];
                        }
                        if (t.GetCustomAttributes(typeof(IControllerInjector), false).Length != 0)
                        {
                            injector = (IControllerInjector)t.GetCustomAttributes(typeof(IControllerInjector), false)[0];
                        }
                        controllerList.Add(new ControllerDescription(t, allowRole, allowUser, injector));
                    }
                }
            }
            s_ControllerNameDict = controllerList.ToDictionary(x => x.ControllerType.Name, StringComparer.OrdinalIgnoreCase);
            // 提前加载Page Controller中的所有Action方法
            s_ControllerActionDict = new Dictionary <string, ActionDescription>();
            foreach (ControllerDescription controller in controllerList)
            {
                foreach (MethodInfo m in controller.ControllerType.GetMethods(ActionBindingFlags))
                {
                    if (m.Name.EndsWith("Action"))
                    {
                        ActionAttribute    actionAttr        = m.GetMyAttribute <ActionAttribute>();
                        AllowRoleAttribute allowRole         = m.GetMyAttribute <AllowRoleAttribute>();
                        AllowUserAttribute allowUser         = m.GetMyAttribute <AllowUserAttribute>();
                        IActionInjector    injector          = m.GetMyAttribute <IActionInjector>();
                        ActionDescription  actionDescription = new ActionDescription(m, actionAttr, allowRole, allowUser, injector)
                        {
                            PageController = controller
                        };
                        s_ControllerActionDict.Add(controller.ControllerType.Name.ToLower() + "_" + m.Name.ToLower(), actionDescription);
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public object[] GetParameters(System.Web.HttpRequest request, ActionDescription action)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
 public object[] GetParameters(System.Web.HttpRequest request, ActionDescription action)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
 public object[] GetParameters(HttpRequest request, ActionDescription action)
 {
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     object[] parameters = new object[action.Parameters.Length];
     for (int i = 0; i < action.Parameters.Length; i++)
     {
         ParameterInfo p = action.Parameters[i];
         if (p.IsOut)
         {
             continue;
         }
         if (p.ParameterType == typeof(NameValueCollection))
         {
             if (string.Compare(p.Name, "Form", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 parameters[i] = request.Form;
             }
             else if (string.Compare(p.Name, "QueryString", StringComparison.OrdinalIgnoreCase) == 0)
             {
                 parameters[i] = request.QueryString;
             }
         }
         else
         {
             Type paramterType = p.ParameterType.GetRealType();
             //
             if (paramterType.IsSupportableType())
             {
                 object val = ModelHelper.GetValueByNameAndTypeFromRequest(request, p.Name, paramterType, null);
                 if (val != null)
                 {
                     parameters[i] = val;
                 }
                 else
                 {
                     if (p.ParameterType.IsValueType || p.ParameterType.IsNullableType() == true)
                     {
                     }
                     else if (p.ParameterType.FullName == "System.String")
                     {
                     }
                     else
                     {
                         throw new ArgumentException("未能找到指定的参数值:" + p.Name);
                     }
                 }
             }
             else
             {
                 // 自定义的类型。首先创建实例,然后给所有成员赋值。  暂不支持
                 // 注意:这里不支持嵌套类型的自定义类型。
                 //object item = Activator.CreateInstance(paramterType);
             }
         }
     }
     return(parameters);
 }