Пример #1
0
 private static string GenerateMethod(MethodBase method, AjaxMethodAttribute attribute, string url)
 {
     // FORMAT:
     // 1. Async:
     // <MethodName>:function(<Parameters: pi>,sc,ec) {var p={<Parameters: pi:pi>};MkAJAX.callAsync(<URL>,<RequestType>,p,sc,ec);}
     // 2. Blocking:
     // <MethodName>:function(<Parameters: pi>) {var p={<Parameters: pi:pi>};return MkAJAX.callBlock(<URL>,<RequestType>,p);}
     ParameterInfo[] methodParams = method.GetParameters();
     string name = attribute.Name ?? method.Name;
     bool isAsync = attribute.ExecutionType == ExecutionType.Async;
     return string.Format("{0}{1}:function({2}{3}){{var p={{{4}}};{5}(\"{6}/{7}\",{8},p{9}{3});}}",
         /*0*/Environment.NewLine,
         /*1*/attribute.UseJavaScriptNamingConvention ? FirstCharacterToLower(name) : name,
         /*2*/string.Format("{0}{1}", string.Join(",", Array.ConvertAll(methodParams, p => p.Name)),
             methodParams.Length > 0 && isAsync ? "," : string.Empty),
         /*3*/isAsync ? "cb" : string.Empty,
         /*4*/methodParams.Length > 0
             ? string.Join(",", Array.ConvertAll(methodParams, p => string.Format("{0}:{0}", p.Name)))
             : string.Empty,
         /*5*/isAsync ? "MkAjax.callAsync" : "return MkAjax.callBlock",
         /*6*/url,
         /*7*/method.Name,
         /*8*/attribute.RequestType == RequestType.Post ? "true" : "false", // false for now mean GET
         /*9*/isAsync ? "," : string.Empty);
 }
Пример #2
0
        protected virtual bool IsAjaxMethod(MethodInfo methodInfo, ref string httpMethod)
        {
            AjaxMethodAttribute ajaxMethod = methodInfo.GetAttribute <AjaxMethodAttribute>();

            httpMethod = ajaxMethod.HttpMethod;
            return(ajaxMethod != null);
        }
Пример #3
0
 public void StoreUnknownType(AjaxMethodAttribute value)
 {
 }
Пример #4
0
 public void StoreUnknownType(AjaxMethodAttribute value)
 {
 }
Пример #5
0
        public void findAjaxMethods(IEnumerable <Type> types)
        {
            foreach (Type t in types)
            {
                AjaxClass ac = new AjaxClass();

                ac.Id   = "gAjax";
                ac.Type = t;

                foreach (MethodInfo mi in t.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    object[] ajaxattrs = mi.GetCustomAttributes(typeof(AjaxMethodAttribute), true);
                    if (ajaxattrs != null && ajaxattrs.Length == 1)
                    {
                        AjaxMethodAttribute am         = ajaxattrs[0] as AjaxMethodAttribute;
                        AjaxMethod          ajaxMethod = new AjaxMethod();
                        ajaxMethod.MethodName   = mi.Name;
                        ajaxMethod.AjaxType     = am.Type.ToString();
                        ajaxMethod.CacheMinutes = am.CacheMinutes;
                        ajaxMethod.Exception    = new AjaxServerException()
                        {
                            Action = am.OnExceptionAction, Parameter = am.OnExceptionParameter
                        };

                        foreach (ParameterInfo param in mi.GetParameters())
                        {
                            string paramType = string.Empty;
                            if (param.ParameterType == typeof(long))
                            {
                                paramType = "long";
                            }
                            else if (param.ParameterType == typeof(int))
                            {
                                paramType = "int";
                            }
                            else if (param.ParameterType == typeof(double))
                            {
                                paramType = "double";
                            }
                            else if (param.ParameterType == typeof(bool))
                            {
                                paramType = "bool";
                            }
                            else if (param.ParameterType == typeof(string[]))
                            {
                                paramType = "strings";
                            }
                            else if (param.ParameterType == typeof(int[]))
                            {
                                paramType = "ints";
                            }
                            else
                            {
                                paramType = param.ParameterType.Name;
                            }

                            ajaxMethod.Params.Add(new AjaxParam()
                            {
                                ParamType = paramType, ParamName = param.Name
                            });
                        }

                        ac.Methods.Add(ajaxMethod);
                    }
                }

                AjaxConfiguration.ControllerAjax[t] = ac;
            }
        }