Esempio n. 1
0
        private void CacheMethods()
        {
            foreach (var method in ProxiedType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                if (Methods.ContainsKey(method.Name))
                {
                    throw new ApplicationException("This service can not be proxied dynamically since it contains more than one definition for method " + method.Name);
                }

                var apiMethodInfo = new DynamicApiMethodInfo(method.Name, method, FindHttpVerb(method));

                Methods[method.Name] = apiMethodInfo;
            }
        }
Esempio n. 2
0
        private void AppendMethod(StringBuilder script, DynamicApiControllerInfo controllerInfo, DynamicApiMethodInfo methodInfo)
        {
            script.AppendLine("    var " + methodInfo.Name.ToCamelCase() + " = function(" + GenerateMethodParams(methodInfo.Method) + ") {");
            script.AppendLine("        return abp.ajax({");
            script.AppendLine("            url: '/api/services/" + controllerInfo.Name.ToCamelCase() + "/" + methodInfo.Name.ToCamelCase() + "',");
            script.Append("            type: '" + methodInfo.Verb.ToString().ToUpper() + "'");

            var parameters = methodInfo.Method.GetParameters();

            if (parameters.Length > 0)
            {
                script.AppendLine(",");
                //if (methodInfo.Verb == HttpVerb.Get || methodInfo.Verb == HttpVerb.Delete)
                //{
                //    script.AppendLine("            data: {");

                //    for (var i = 0; i < parameters.Length; i++)
                //    {
                //        var parameterInfo = parameters[i];
                //        script.AppendLine("                " + parameterInfo.Name.ToCamelCase() + ": " + parameterInfo.Name.ToCamelCase() + (i < parameters.Length - 1 ? "," : ""));
                //    }

                //    script.AppendLine("            }");
                //}
                //else if (methodInfo.Verb == HttpVerb.Post || methodInfo.Verb == HttpVerb.Put)
                //{
                script.AppendLine("            data: JSON.stringify(" + parameters[0].Name.ToCamelCase() + ")");
                //}
            }
            else
            {
                script.AppendLine();
            }

            script.AppendLine("        });");
            script.AppendLine("    };");
        }