コード例 #1
0
def transference(elems):
    type_elems = []
    for key, value in elems:
        if key[len(key)-2] == '[' and key[len(key)-1] == ']':
            type_elems.append(('List<' + tools.gentypetocsharp(key[:-2]) + '>', value))
        else:
            type_elems.append((tools.gentypetocsharp(key), value))
    return type_elems
コード例 #2
0
def gen_module_module(module_name, funcs):
    code = "    public class " + module_name + "_module : common.imodule\n    {\n"
    code += "        public string module_name;\n\n"

    cb_code_Constructor = "        public " + module_name + "_module(client.client _client)\n"
    cb_code_Constructor += "        {\n"
    cb_code_Constructor += "            module_name = \"" + module_name + "\";\n\n"

    for i in funcs:
        func_name = i[0]

        cb_code_Constructor += "            reg_event(\"" + func_name + "\", " + func_name + ");\n"

        if i[1] != "ntf" and i[1] != "multicast" and i[1] != "broadcast":
            raise "func:" + func_name + " wrong rpc type:" + i[
                1] + ", must ntf or broadcast"

        code += "        public delegate void " + func_name + "_handle("
        count = 0
        for item in i[2]:
            code += tools.gentypetocsharp(item) + " argv" + str(count)
            count = count + 1
            if count < len(i[2]):
                code += ", "
        code += ");\n"
        code += "        public event " + func_name + "_handle on" + func_name + ";\n"
        code += "        void " + func_name + "(ArrayList _event)\n"
        code += "        {\n"
        code += "            if (on" + func_name + " == null)\n"
        code += "            {\n"
        code += "                return;\n"
        code += "            }\n\n"
        count = 0
        for item in i[2]:
            code += "            var argv" + str(
                count) + " = ((" + tools.gentypetocsharp(
                    item) + ")_event[" + str(count) + "]);\n"
            count = count + 1
        code += "\n            on" + func_name + "("
        count = 0
        for item in i[2]:
            code += "argv" + str(count)
            count = count + 1
            if count < len(i[2]):
                code += ", "
        code += ");\n"
        code += "        }\n\n"

    cb_code_Constructor += "\n            _client.modulemanager.add_module(\"" + module_name + "\", this);\n"
    cb_code_Constructor += "        }\n"

    code += cb_code_Constructor
    code += "    }\n"

    return code
コード例 #3
0
ファイル: gencaller.py プロジェクト: qdsloop/juggle
def gencaller(module_name, funcs):
    code = "/*this caller file is codegen by juggle for c#*/\n"
    code += "using System;\n"
    code += "using System.Collections;\n"
    code += "using System.IO;\n\n"

    code += "namespace caller\n"
    code += "{\n"
    code += "    public class " + module_name + " : juggle.Icaller \n"
    code += "    {\n"
    code += "        public " + module_name + "(juggle.Ichannel _ch) : base(_ch)\n"
    code += "        {\n"
    code += "            module_name = \"" + module_name + "\";\n"
    code += "        }\n\n"

    for i in funcs:
        code += "        public void " + i[1] + "("
        count = 0
        for item in i[2]:
            code += tools.gentypetocsharp(item) + " argv" + str(count)
            count = count + 1
            if count < len(i[2]):
                code += ","
        code += ")\n"
        code += "        {\n"
        code += "            ArrayList _argv = new ArrayList();\n"
        for n in range(len(i[2])):
            code += "            _argv.Add(argv" + str(n) + ");\n"
        code += "            call_module_method(\"" + i[1] + "\", _argv);\n"
        code += "        }\n\n"

    code += "    }\n"
    code += "}\n"

    return code
コード例 #4
0
ファイル: gencaller.py プロジェクト: Ding8222/abelkhan
def gencaller(module_name, funcs):
        code = "/*this caller file is codegen by juggle for c#*/\n"
        code += "using System;\n"
        code += "using System.Collections;\n"
        code += "using System.IO;\n\n"

        code += "namespace caller\n"
        code += "{\n"
        code += "    public class " + module_name + " : juggle.Icaller \n"
        code += "    {\n"
        code += "        public " + module_name + "(juggle.Ichannel _ch) : base(_ch)\n"
        code += "        {\n"
        code += "            module_name = \"" + module_name + "\";\n"
        code += "        }\n\n"

        for i in funcs:
                code += "        public void " + i[1] + "("
                count = 0
                for item in i[2]:
                        code += tools.gentypetocsharp(item) + " argv" + str(count)
                        count = count + 1
                        if count < len(i[2]):
                                code += ","
                code += ")\n"
                code += "        {\n"
                code += "            ArrayList _argv = new ArrayList();\n"
                for n in range(len(i[2])):
                        code += "            _argv.Add(argv" + str(n) + ");\n"
                code += "            call_module_method(\"" + i[1] + "\", _argv);\n"
                code += "        }\n\n"

        code += "    }\n"
        code += "}\n"

        return code
コード例 #5
0
ファイル: genmodule.py プロジェクト: qdsloop/juggle
def genmodule(module_name, funcs):
        code = "/*this module file is codegen by juggle for c#*/\n"
        code += "using System;\n"
        code += "using System.Collections;\n"
        code += "using System.Collections.Generic;\n\n"

        code += "namespace module\n{\n"
        code += "    public class " + module_name + " : juggle.Imodule \n    {\n"

        code += "        public " + module_name + "()\n        {\n"
        code += "			module_name = \"" + module_name + "\";\n"
        code += "        }\n\n"

        for i in funcs:
                code += "        public delegate void " + i[1] + "handle("
                count = 0
                for item in i[2]:
                        code += tools.gentypetocsharp(item) + " argv" + str(count)
                        count = count + 1
                        if count < len(i[2]):
                                code += ", "
                code += ");\n"
                code += "        public event " + i[1] + "handle on" + i[1] + ";\n"
                code += "        public void " + i[1] + "(ArrayList _event)\n        {\n"
                code += "            if(on" + i[1] + " != null)\n            {\n"
                count = 0
                for item in i[2]:
                        code += "                var argv" + str(count) + " = ((" + tools.gentypetocsharp(item) + ")_event[" + str(count) + "]);\n"
                        count = count + 1
                code += "                on" + i[1] + "("
                count = 0
                for item in i[2]:
                        code += " argv" + str(count)
                        count = count + 1
                        if count < len(i[2]):
                                code += ", "
                code += ");\n"
                code += "            }\n"
                code += "        }\n\n"

        code += "	}\n"
        code += "}\n"

        return code
コード例 #6
0
def gen_module_caller(module_name, funcs):
    cb_func = ""

    cb_code = "    /*this cb code is codegen by abelkhan for c#*/\n"
    cb_code += "    public class cb_" + module_name + " : common.imodule\n    {\n"

    cb_code_Constructor = "        public cb_" + module_name + "()\n        {\n"

    code = "    public class " + module_name + "\n"
    code += "    {\n"
    code += "        private client.client client_handle;\n"
    code += "        private cb_" + module_name + " cb_" + module_name + "_handle;\n\n"
    code += "        public " + module_name + "(client.client cli)\n"
    code += "        {\n"
    code += "            cb_" + module_name + "_handle = new cb_" + module_name + "();\n"
    code += "            client_handle = cli;\n"
    code += "            client_handle.modulemanager.add_module(\"" + module_name + "\", cb_" + module_name + "_handle);\n"
    code += "        }\n\n"
    code += "        public " + module_name + "_hubproxy get_hub(string hub_name)\n"
    code += "        {\n"
    code += "            return new " + module_name + "_hubproxy(hub_name, client_handle, cb_" + module_name + "_handle);\n"
    code += "        }\n\n"
    code += "    }\n\n"

    code += "    public class " + module_name + "_hubproxy\n"
    code += "    {\n"
    code += "        public string hub_name;\n"
    code += "        public cb_" + module_name + " cb_" + module_name + "_handle;\n"
    code += "        public client.client client_handle;\n\n"
    code += "        public " + module_name + "_hubproxy(string _hub_name, client.client _client_handle, cb_" + module_name + " _cb_" + module_name + "_handle)\n"
    code += "        {\n"
    code += "            hub_name = _hub_name;\n"
    code += "            client_handle = _client_handle;\n"
    code += "            cb_" + module_name + "_handle = _cb_" + module_name + "_handle;\n"
    code += "        }\n\n"

    for i in funcs:
        func_name = i[0]

        if i[1] == "ntf":
            code += "        public void " + func_name + "("
            count = 0
            for item in i[2]:
                code += tools.gentypetocsharp(item) + " argv" + str(count)
                count = count + 1
                if count < len(i[2]):
                    code += ", "
            code += ")\n        {\n"
            code += "            client_handle.call_hub(hub_name, \"" + module_name + "\", \"" + func_name + "\""
            count = 0
            for item in i[2]:
                code += ", argv" + str(count)
                count = count + 1
            code += ");\n        }\n\n"
        elif i[1] == "req" and i[3] == "rsp" and i[5] == "err":
            cb_code_Constructor += "            reg_event(\"" + func_name + "_rsp\", " + func_name + "_rsp);\n"
            cb_code_Constructor += "            reg_event(\"" + func_name + "_err\", " + func_name + "_err);\n"

            code += "        public cb_" + func_name + "_func " + func_name + "("
            count = 0
            for item in i[2]:
                code += tools.gentypetocsharp(item) + " argv" + str(count)
                count = count + 1
                if count < len(i[2]):
                    code += ", "
            code += ")\n        {\n"
            code += "            var uuid = System.Guid.NewGuid().ToString();\n"
            code += "            client_handle.call_hub(hub_name, \"" + module_name + "\", \"" + func_name + "\", uuid"
            count = 0
            for item in i[2]:
                code += ", argv" + str(count)
                count = count + 1
            code += ");\n\n"
            code += "            var cb_" + func_name + "_obj = new cb_" + func_name + "_func();\n"
            code += "            cb_" + module_name + "_handle.map_" + func_name + ".Add(uuid, cb_" + func_name + "_obj);\n\n"
            code += "            return cb_" + func_name + "_obj;\n        }\n\n"

            cb_code += "        public Hashtable map_" + func_name + " = new Hashtable();\n\n"
            cb_code += "        public void " + func_name + "_rsp(ArrayList _events)\n        {\n"
            cb_code += "            string uuid = (string)_events[0];\n"
            count = 0
            for item in i[4]:
                cb_code += "            var argv" + str(
                    count) + " = (" + tools.gentypetocsharp(
                        item) + ")_events[" + str(count + 1) + "];\n"
                count = count + 1
            cb_code += "            var rsp = (cb_" + func_name + "_func)map_" + func_name + "[uuid];\n"
            cb_code += "            rsp.cb("
            count = 0
            for item in i[4]:
                cb_code += "argv" + str(count)
                count = count + 1
                if count < len(i[4]):
                    cb_code += ", "
            cb_code += ");\n"
            cb_code += "        }\n\n"
            cb_code += "        public void " + func_name + "_err(ArrayList _events)\n        {\n"
            cb_code += "            string uuid = (string)_events[0];\n"
            count = 0
            for item in i[6]:
                cb_code += "            var argv" + str(
                    count) + " = (" + tools.gentypetocsharp(
                        item) + ")_events[" + str(count + 1) + "];\n"
                count = count + 1
            cb_code += "            var rsp = (cb_" + func_name + "_func)map_" + func_name + "[uuid];\n"
            cb_code += "            rsp.err("
            count = 0
            for item in i[6]:
                cb_code += "argv" + str(count)
                count = count + 1
                if count < len(i[6]):
                    cb_code += ", "
            cb_code += ");\n"
            cb_code += "        }\n\n"

            cb_func += "    public class cb_" + func_name + "_func\n    {\n"
            cb_func += "        public delegate void " + func_name + "_handle_cb("
            count = 0
            for item in i[4]:
                cb_func += tools.gentypetocsharp(item) + " argv" + str(count)
                count = count + 1
                if count < len(i[4]):
                    cb_func += ", "
            cb_func += ");\n"
            cb_func += "        public event " + func_name + "_handle_cb on" + func_name + "_cb;\n"
            cb_func += "        public void cb("
            count = 0
            for item in i[4]:
                cb_func += tools.gentypetocsharp(item) + " argv" + str(count)
                count = count + 1
                if count < len(i[4]):
                    cb_func += ", "
            cb_func += ")\n        {\n"
            cb_func += "            if (on" + func_name + "_cb != null)\n            {\n"
            cb_func += "                on" + func_name + "_cb("
            count = 0
            for item in i[4]:
                cb_func += "argv" + str(count)
                count = count + 1
                if count < len(i[4]):
                    cb_func += ", "
            cb_func += ");\n            }\n"
            cb_func += "        }\n\n"
            cb_func += "        public delegate void " + func_name + "_handle_err("
            count = 0
            for item in i[6]:
                cb_func += tools.gentypetocsharp(item) + " argv" + str(count)
                count = count + 1
                if count < len(i[6]):
                    cb_func += ", "
            cb_func += ");\n"
            cb_func += "        public event " + func_name + "_handle_err on" + func_name + "_err;\n"
            cb_func += "        public void err("
            count = 0
            for item in i[6]:
                cb_func += tools.gentypetocsharp(item) + " argv" + str(count)
                count = count + 1
                if count < len(i[6]):
                    cb_func += ", "
            cb_func += ")\n        {\n"
            cb_func += "            if (on" + func_name + "_err != null)\n            {\n"
            cb_func += "                on" + func_name + "_err("
            count = 0
            for item in i[6]:
                cb_func += "argv" + str(count)
                count = count + 1
                if count < len(i[6]):
                    cb_func += ", "
            cb_func += ");\n            }\n"
            cb_func += "        }\n\n"
            cb_func += "        public void callBack(" + func_name + "_handle_cb cb, " + func_name + "_handle_err err)\n        {\n"
            cb_func += "            on" + func_name + "_cb += cb;\n"
            cb_func += "            on" + func_name + "_err += err;\n"
            cb_func += "        }\n\n"
            cb_func += "    }\n\n"
        else:
            raise "func:" + func_name + " wrong rpc type:" + i[
                1] + ", must req or ntf"

    cb_code += cb_code_Constructor + "        }\n"
    cb_code += "    }\n\n"
    code += "    }\n"

    return cb_func + cb_code + code
コード例 #7
0
def gen_module_caller(module_name, funcs):
        code = "    public class " + module_name + "\n"
        code += "    {\n"
        code += "        public " + module_name + "()\n"
        code += "        {\n"
        code += "        }\n\n"
        code += "        public " + module_name + "_cliproxy get_client(string uuid)\n"
        code += "        {\n"
        code += "            return new " + module_name + "_cliproxy(uuid);\n"
        code += "        }\n\n"
        code += "        public " + module_name + "_cliproxy_multi get_multicast(ArrayList uuids)\n"
        code += "        {\n"
        code += "            return new " + module_name + "_cliproxy_multi(uuids);\n"
        code += "        }\n\n"
        code += "        public " + module_name + "_broadcast get_broadcast()\n"
        code += "        {\n"
        code += "            return new " + module_name + "_broadcast();\n"
        code += "        }\n\n"
        code += "    }\n\n"

        cp_code = "    public class " + module_name + "_cliproxy\n"
        cp_code += "    {\n"
        cp_code += "        private string uuid;\n\n"
        cp_code += "        public " + module_name + "_cliproxy(string _uuid)\n"
        cp_code += "        {\n"
        cp_code += "            uuid = _uuid;\n"
        cp_code += "        }\n\n"

        cm_code = "    public class " + module_name + "_cliproxy_multi\n"
        cm_code += "    {\n"
        cm_code += "        private ArrayList uuids;\n\n"
        cm_code += "        public " + module_name + "_cliproxy_multi(ArrayList _uuids)\n"
        cm_code += "        {\n"
        cm_code += "            uuids = _uuids;\n"
        cm_code += "        }\n\n"

        cb_code = "    public class " + module_name + "_broadcast\n"
        cb_code += "    {\n"
        cb_code += "        public " + module_name + "_broadcast()\n"
        cb_code += "        {\n"
        cb_code += "        }\n\n"

        for i in funcs:
                func_name = i[0]

                if i[1] != "ntf" and i[1] != "multicast" and i[1] != "broadcast":
                        raise "func:" + func_name + " wrong rpc type:" + i[1] + ", must ntf or broadcast"

                tmp_code = "        public void " + func_name + "("
                count = 0
                for item in i[2]:
                        tmp_code += tools.gentypetocsharp(item) + " argv" + str(count)
                        count = count + 1
                        if count < len(i[2]):
                                tmp_code += ", "
                tmp_code += ")\n"
                tmp_code += "        {\n"

                argvs = ""
                count = 0
                for item in i[2]:
                        argvs += ", argv" + str(count)
                        count = count + 1

                if i[1] == "ntf":
                        cp_code += tmp_code
                        cp_code += "            hub.hub.gates.call_client(uuid, \"" + module_name + "\", \"" + func_name + "\"" + argvs + ");\n"
                        cp_code += "        }\n\n"
                elif i[1] == "multicast":
                        cm_code += tmp_code
                        cm_code += "            hub.hub.gates.call_group_client(uuids, \"" + module_name + "\", \"" + func_name + "\"" + argvs + ");\n"
                        cm_code += "        }\n\n"
                elif i[1] == "broadcast":
                        cb_code += tmp_code
                        cb_code += "            hub.hub.gates.call_global_client(\"" + module_name + "\", \"" + func_name + "\"" + argvs + ");\n"
                        cb_code += "        }\n\n"

        cp_code += "    }\n\n"
        cm_code += "    }\n\n"
        cb_code += "    }\n\n"

        return code + cp_code + cm_code + cb_code
コード例 #8
0
def gen_module_module(module_name, funcs):
        rsp_code = ""

        code = "    public class " + module_name + "_module : abelkhan.Module\n    {\n"
        code += "        public string module_name;\n"
        code += "        public hub.hub hub_handle;\n"
        code += "        public " + module_name + "_module(hub.hub _hub)\n        {\n"
        code += "            module_name = \"" + module_name + "\";\n"
        code += "            hub_handle = _hub;\n"
        code += "            hub.hub.modules.add_module(\"" + module_name + "\", this);\n"
        code += "        }\n\n"

        for i in funcs:
                func_name = i[0]

                code += "        public delegate void " + func_name + "handle("
                count = 0
                for item in i[2]:
                        code += tools.gentypetocsharp(item) + " argv" + str(count)
                        count = count + 1
                        if count < len(i[2]):
                                code += ", "
                code += ");\n"
                code += "        public event " + func_name + "handle on" + func_name + ";\n"

                code += "        public void " + func_name + "("
                if i[1] == "ntf":
                        count = 0
                        for item in i[2]:
                                code += tools.gentypetocsharp(item) + " argv" + str(count)
                                count = count + 1
                                if count < len(i[2]):
                                    code += ", "
                elif i[1] == "req" and i[3] == "rsp" and i[5] == "err":
                        code += "string hub_name, string uuid"
                        count = 0
                        for item in i[2]:
                                code += ", " + tools.gentypetocsharp(item) + " argv" + str(count)
                                count = count + 1
                code += ")\n        {\n"

                code += "            if(on" + func_name + " == null)\n"
                code += "            {\n"
                code += "                return;\n"
                code += "            }\n\n"

                if i[1] == "ntf":
                        pass
                elif i[1] == "req" and i[3] == "rsp" and i[5] == "err":
                        code += "            rsp = new rsp_" + func_name + "(hub_name, uuid);\n"

                        rsp_code += "    public class rsp_" + func_name + " : abelkhan.Response\n    {\n"
                        rsp_code += "        public string hub_name;\n"
                        rsp_code += "        public string uuid;\n\n"
                        rsp_code += "        public rsp_" + func_name + "(string _hub_name, string _uuid)\n"
                        rsp_code += "        {\n"
                        rsp_code += "            hub_name = _hub_name;\n"
                        rsp_code += "            uuid = _uuid;\n"
                        rsp_code += "        }\n\n"

                        rsp_code += "        public void call("
                        count = 0
                        for item in i[4]:
                                rsp_code += tools.gentypetocsharp(item) + " argv" + str(count)
                                count = count + 1
                                if count < len(i[4]):
                                        rsp_code += ", "
                        rsp_code += ")\n        {\n"
                        rsp_code += "            hub.hub.hubs.call_hub(hub_name, \"" + module_name + "\", \"" + func_name + "_rsp\", uuid"
                        count = 0
                        for item in i[4]:
                                rsp_code += ", argv" + str(count)
                                count = count + 1
                        rsp_code += ");\n"
                        rsp_code += "        }\n"

                        rsp_code += "        public void err("
                        count = 0
                        for item in i[6]:
                                rsp_code += tools.gentypetocsharp(item) + " argv" + str(count)
                                count = count + 1
                                if count < len(i[6]):
                                        rsp_code += ", "
                        rsp_code += ")\n        {\n"
                        rsp_code += "            hub.hub.hubs.call_hub(hub_name, \"" + module_name + "\", \"" + func_name + "_err\", uuid"
                        count = 0
                        for item in i[6]:
                                rsp_code += ", argv" + str(count)
                                count = count + 1
                        rsp_code += ");\n"
                        rsp_code += "        }\n"
                        rsp_code += "    }\n\n"
                else:
                        raise "func:%s wrong rpc type:%s must req or ntf" % (func_name, i[1])

                code += "            on" + func_name + "("
                count = 0
                for item in i[2]:
                        code += " argv" + str(count)
                        count = count + 1
                        if count < len(i[2]):
                                code += ", "
                code += ");\n"

                if i[1] == "ntf":
                        pass
                elif i[1] == "req" and i[3] == "rsp" and i[5] == "err":
                        code += "            rsp = null;\n"
                else:
                        raise "func:%s wrong rpc type:%s must req or ntf" % (func_name, i[1])

                code += "        }\n\n"

        code += "    }\n"

        return rsp_code + code