예제 #1
0
        public string GenerateClass(Service service, Interface intr)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteLine(HEADER);
            writer.WriteLineFormat("package {0}", service.Name);
            writer.WriteLine("{");
            writer.PushIdent();
            writer.WriteLine(IMPORT);
            writer.WriteLine();
            writer.WriteLineFormat("public class {0}Client", intr.Name);
            writer.WriteLine("{");
            writer.PushIdent();
            writer.WriteLine("public var url: String = \"\";");
            writer.WriteLine(LOAD);
            writer.WriteLine();

            foreach(Method method in intr.Methods)
            {
                writer.WriteLine(GenerateMethodHeader(intr, method));
                writer.WriteLine("{"); 
                writer.PushIdent();
                writer.WriteLine(GenerateMethodBody(intr, method));
                writer.PopIdent();
                writer.WriteLine("}");
                writer.WriteLine();
            }
            writer.PopIdent();
            writer.WriteLine("}");
            writer.PopIdent();
            writer.WriteLine("}");
            return writer.Code;
        }
예제 #2
0
        public string GenerateInterface(Service service, Interface intr)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteFormat(".factory(\"{0}Client\", function($http, serviceUrl)", intr.Name);
            writer.WriteLineNoIdent(" {");
            writer.PushIdent();
            writer.WriteLine("return {");

            int methodCount = intr.Methods.Count;
            for (int i = 0; i < methodCount; i++)
            {
                writer.PushIdent();
                Method method = intr.Methods[i];
                string comma = i < methodCount - 1 ? "," : "";
                writer.Write(GenerateMethod(intr, method).Trim());
                writer.WriteLineNoIdent(comma);
                writer.WriteLine();
                writer.PopIdent();
            }
 
            writer.WriteLine("}");
            writer.PopIdent();
            writer.WriteLine("})");
            return writer.Code;
        }
예제 #3
0
 public static Interface BuildFromInterfaceType(Type interfaceType)
 {
     validate(interfaceType);
     Interface intr = new Interface();
     createMethods(intr, interfaceType);
     return intr;
 }
예제 #4
0
        public string GenerateInterface(Service service, Interface intr)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteLine("define([\"dojo/request\", \"dojo/json\"], function (request, JSON) {");
            writer.PushIdent();
            writer.WriteLine("var serviceClient = {");
            writer.PushIdent();
            writer.WriteLine("urlString: '',");
            writer.WriteLine();

            int methodCount = intr.Methods.Count;
            for (int i = 0; i < methodCount; i++)
            {
                Method method = intr.Methods[i];
                string comma = i < methodCount - 1 ? "," : "";
                writer.Write(GenerateMethod(intr, method).Trim());
                writer.WriteLineNoIdent(comma);
                writer.WriteLine();
            }
            writer.PopIdent();
            writer.WriteLine("}");
            writer.WriteLine("return serviceClient;");
            writer.PopIdent();
            writer.Write("});");
            return writer.Code;
        }
예제 #5
0
 public static Interface BuildFromInterfaceConf(InterfaceConfiguration interfaceConf)
 {
     validate(interfaceConf.RuntimeInfo.InterfaceType);
     Interface intr = new Interface();
     intr.Name = interfaceConf.Name;
     intr.Description = interfaceConf.Description;
     createMethods(intr, interfaceConf.RuntimeInfo.InterfaceType);
     return intr;
 }
예제 #6
0
 public string GenerateMethod(Interface intr, Method method)
 {
     CodeWriter writer = new CodeWriter();
     writer.Write(generateMethodHeader(intr, method));
     writer.WriteLine(" {");
     writer.PushIdent();
     writer.WriteLine(generateMethodBody(intr, method));
     writer.PopIdent();
     writer.Write("}");
     return writer.Code;
 }
예제 #7
0
 private void buildMethodsNode(Interface intr, TreeNode parentNode)
 {
     foreach (Method method in intr.Methods)
     {
         TreeNode methodNode = new TreeNode(method.Name, 3, 3);
         methodNode.Tag = method;
         TreeNode parametersNode = new TreeNode("Parameters", 1, 1);
         buildParametersNode(method, parametersNode);
         methodNode.Nodes.Add(parametersNode);
         parentNode.Nodes.Add(methodNode);
     }
 }
예제 #8
0
        private string generateMethodHeader(Interface intr, Method method)
        {
            StringBuilder sb = new StringBuilder();
            List<string> paramDefs = new List<string>();
            string methodName = method.Name;
            foreach (Parameter p in method.Parameters)
            {
                string def = p.Name;
                paramDefs.Add(def);
            }
            paramDefs.Add("successFunction");
            paramDefs.Add("failFunction");

            string paramDefString = StringUtils.GenerateCommaSeparatedString(paramDefs, "", "");
            string header = string.Format("{0}: function({1})", methodName, paramDefString.Trim());
            return header;
        }
예제 #9
0
 private string generateMethodBody(Interface intr, Method method)
 {
     CodeWriter writer = new CodeWriter();
     List<string> paramDefs = new List<string>();
     string methodName = method.Name;
     foreach (Parameter p in method.Parameters)
     {
         string def = string.Format("'{0}': {0}", p.Name);
         paramDefs.Add(def);
     }
     string paramDefString = "{" + StringUtils.GenerateCommaSeparatedString(paramDefs, "", "") + "}";
     string dataObjectDef = string.Format("var data = {{ 'interface': '{0}', 'method': '{1}', 'parameters': {2} }}", intr.Name, method.Name, paramDefString);
     writer.WriteLine(dataObjectDef);
     writer.WriteLine("var jsonData = JSON.stringify(data);");
     writer.WriteLine("request.post(this.urlString, { data: jsonData, handleAs: 'json' }).then(successFunction, failFunction);");
     return writer.Code;
 }
예제 #10
0
 private static void createMethods(Interface intr, Type interfaceType)
 {
     intr.Methods = new List<Method>();
     foreach (MethodInfo mi in interfaceType.GetMethods())
     {
         Method m = new Method();
         m.Name = mi.Name;
         m.Parameters = new List<Parameter>();
         foreach (ParameterInfo pi in mi.GetParameters())
         {
             Parameter p = new Parameter();
             p.Name = pi.Name;
             p.Type = GetTypeName(pi.ParameterType);
             m.Parameters.Add(p);
         }
         m.ReturnType = GetTypeName(mi.ReturnType);
         intr.Methods.Add(m);
     }
 }
예제 #11
0
 public string GenerateMethodHeader(Interface intr, Method method)
 {
     List<string> paramDefs = new List<string>();
     string methodName = method.Name;
     foreach (Parameter p in method.Parameters)
     {
         string type = TypeMap == null ? p.Type : TypeMap.MapDataType(p.Type);
         string def = string.Format("{0}: {1}", p.Name, type);
         paramDefs.Add(def);
     }
     paramDefs.Add("completeFunction: Function");
     string paramDefString = StringUtils.GenerateCommaSeparatedString(paramDefs, "", "");
     string methodHeader = string.Format("public function {0} ({1}) : {2}", methodName, paramDefString, "void");
     return methodHeader;
 }
예제 #12
0
 public string GenerateMethodBody(Interface intr, Method method)
 {
     CodeWriter writer = new CodeWriter();
     writer.WriteLine("var o: Object = new Object();");
     writer.WriteLine("var p: Object = new Object();");
     writer.WriteLineFormat("o[\"interface\"] = \"{0}\"", intr.Name);
     writer.WriteLineFormat("o[\"method\"] = \"{0}\"", method.Name);
     foreach (Parameter p in method.Parameters)
     {
         writer.WriteLineFormat("p[\"{0}\"]={0};", p.Name);
     }
     writer.WriteLine("o[\"parameters\"] = p;");
     writer.WriteLine("var data: String = JSON.stringify(o);");
     writer.WriteLine("load(data, completeFunction);");
     return writer.Code;
 }
예제 #13
0
 private string generateMethodBody(Interface intr, Method method)
 {
     CodeWriter writer = new CodeWriter();
     writer.WriteLine("JSONObject result = null;");
     writer.WriteLine("JSONObject o = new JSONObject();");
     writer.WriteLine("JSONObject p = new JSONObject();");
     writer.WriteLineFormat("o.put(\"interface\", \"{0}\");", intr.Name);
     writer.WriteLineFormat("o.put(\"method\", \"{0}\");", method.Name);
     foreach (Parameter p in method.Parameters)
     {
         writer.WriteLineFormat("p.put(\"{0}\",mapObject({0}));", p.Name);
     }
     writer.WriteLineFormat("o.put(\"parameters\", p);");
     writer.WriteLine(@"String s = o.toString();");
     writer.WriteLine(@"String r = load(s);");
     writer.WriteLine(@"result = new JSONObject(r);");
     writer.WriteLine(@"return result;");
     return writer.Code;
 }
예제 #14
0
 private string generateMethodHeader(Interface intr, Method method)
 {
     StringBuilder sb = new StringBuilder();
     List<string> paramDefs = new List<string>();
     string methodName = method.Name;
     foreach (Parameter p in method.Parameters)
     {
         string type = TypeMap == null ? p.Type : TypeMap.MapDataType(p.Type);
         string def = string.Format("{0} {1}", type, p.Name);
         paramDefs.Add(def);
     }
     string paramDefString = StringUtils.GenerateCommaSeparatedString(paramDefs, "", "");
     string returnType = "JSONObject";
     string header = string.Format("public {0} {1}({2}) throws Exception", returnType, methodName, paramDefString.Trim());
     return header;
 }
예제 #15
0
        public string GenerateClientClass(Service service, Interface intr)
        {
            CodeWriter writer = new CodeWriter();
            writer.WriteLine(HEADER);
            writer.WriteLineFormat("package {0};", service.Name);
            writer.WriteLine(IMPORT);
            writer.WriteLine();
            string className = intr.Name + "Client";
            writer.WriteLineFormat("public class {0}", className);
            writer.WriteLine("{");
            writer.PushIdent();
            writer.WriteLine("private static final String SERVICE_URL = \"\";");
            writer.WriteLine("private static final int BUFFER_SIZE = 4096;");
            writer.WriteLine();
            writer.WriteLine(LOAD_METHOD);
            writer.WriteLine();
            writer.WriteLine(MAP_OBJECT_METHOD);
            writer.WriteLine();
            writer.WriteLine(CONVERT_METHOD);
            writer.WriteLine();

            foreach (Method method in intr.Methods)
            {
                writer.WriteLine(GenerateMethod(intr, method));
                writer.WriteLine();
            }
            writer.PopIdent();
            writer.WriteLine("}");
            return writer.Code;
        }
예제 #16
0
 private string generateMethodBody(Interface intr, Method method)
 {
     CodeWriter writer = new CodeWriter();
     List<string> paramDefs = new List<string>();
     string methodName = method.Name;
     foreach (Parameter p in method.Parameters)
     {
         string def = string.Format("'{0}': {0}", p.Name);
         paramDefs.Add(def);
     }
     string paramDefString = "{" + StringUtils.GenerateCommaSeparatedString(paramDefs, "", "") + "}";
     string dataObjectDef = string.Format("var data = {{ 'interface': '{0}', 'method': '{1}', 'parameters': {2} }};", intr.Name, method.Name, paramDefString);
     writer.WriteLine(dataObjectDef);
     writer.WriteLine(CALL_DEF);
     return writer.Code;
 }