示例#1
0
        /// <summary>
        /// 调用CALL
        /// </summary>
        /// <param name="tmp">调用包</param>
        /// <param name="needReturn">是否需要返回</param>
        /// <param name="returnValue">返回值</param>
        /// <returns></returns>
        public bool RunModule(RPCCallPack tmp, bool needReturn, out object returnValue)
        {
            returnValue = null;

            try
            {
                if (ModuleDiy.ContainsKey(tmp.Tag))
                {
                    var module = ModuleDiy[tmp.Tag];

                    if (module.MethodInfoDiy.ContainsKey(tmp.Method))
                    {
                        var method = module.MethodInfoDiy[tmp.Method];

                        if (tmp.Arguments != null)
                        {
                            object[] arguments = new object[method.ArgsType.Length];


                            for (int i = 0; i < tmp.Arguments.Count; i++)
                            {
                                arguments[i] = Serialization.UnpackSingleObject(method.ArgsType[i], tmp.Arguments[i]);
                            }

                            returnValue = method.methodInfo.Invoke(module.Token, arguments);

                            if (needReturn)
                            {
                                if (method.IsOut)
                                {
                                    for (int i = 0; i < arguments.Length; i++)
                                    {
                                        tmp.Arguments[i] = Serialization.PackSingleObject(method.ArgsType[i], arguments[i]);
                                    }
                                }
                                else
                                {
                                    tmp.Arguments = null;
                                }
                            }

                            return(true);
                        }
                        else
                        {
                            returnValue = method.methodInfo.Invoke(module.Token, null);
                            return(true);
                        }
                    }
                    else
                    {
                        LogAction.Warn("Not find " + tmp.Tag + "-> public " + tmp.Method);

                        return(false);
                    }
                }
                else
                {
                    LogAction.Warn("Not find " + tmp.Tag);
                }

                return(false);
            }
            catch (Exception er)
            {
                LogAction.Err(er.ToString());
                return(false);
            }
        }
示例#2
0
        public bool RunModule(RPCCallPack tmp, out object returnValue)
        {
            returnValue = null;

            if (ModuleDiy.ContainsKey(tmp.CallModule))
            {
                object o = ModuleDiy[tmp.CallModule];

                Type _type = o.GetType();

                if (tmp.Arguments == null)
                {
                    tmp.Arguments = new List <RPCArgument>();
                }



                object[] arguments = new object[tmp.Arguments.Count];

                Type[] argumentstype = new Type[tmp.Arguments.Count];

                for (int i = 0; i < tmp.Arguments.Count; i++)
                {
                    argumentstype[i] = tmp.Arguments[i].RefType;
                    arguments[i]     = Serialization.UnpackSingleObject(tmp.Arguments[i].type, tmp.Arguments[i].Value);
                }


                MethodInfo method = null;

                if (argumentstype.Length > 0)
                {
                    method = _type.GetMethod(tmp.Method, argumentstype);
                }
                else
                {
                    method = _type.GetMethod(tmp.Method);
                }

                if (method != null)
                {
                    returnValue = method.Invoke(o, arguments);

                    for (int i = 0; i < arguments.Length; i++)
                    {
                        tmp.Arguments[i].Value = Serialization.PackSingleObject(arguments[i].GetType(), arguments[i]);
                    }

                    return(true);
                }
                else
                {
                    string msg = "Not find " + tmp.CallModule + "-> public " + tmp.Method + "(";
                    int    l   = 0;
                    foreach (var item in argumentstype)
                    {
                        l++;
                        msg += item.Name;
                        if (l < argumentstype.Length)
                        {
                            msg += ",";
                        }
                    }
                    msg += ")";

                    if (ErrMsgOut != null)
                    {
                        ErrMsgOut(msg);
                    }

                    return(false);
                }
            }
            else
            {
                string msg = "Not find " + tmp.CallModule;

                if (ErrMsgOut != null)
                {
                    ErrMsgOut(msg);
                }
            }


            return(false);
        }
示例#3
0
        public bool RunModule(RPCCallPack tmp, out object returnValue)
        {
            returnValue = null;

            if (ModuleDiy.ContainsKey(tmp.CallModule))
            {
                var module = ModuleDiy[tmp.CallModule];

                if (module.MethodInfoDiy.ContainsKey(tmp.Method))
                {
                    var method = module.MethodInfoDiy[tmp.Method];

                    if (tmp.Arguments != null)
                    {
                        object[] arguments = new object[method.ArgsType.Length];


                        for (int i = 0; i < tmp.Arguments.Count; i++)
                        {
                            arguments[i] = Serialization.UnpackSingleObject(method.ArgsType[i], tmp.Arguments[i]);
                        }


                        returnValue = method.methodInfo.Invoke(module.Token, arguments);

                        if (method.IsOut)
                        {
                            for (int i = 0; i < arguments.Length; i++)
                            {
                                tmp.Arguments[i] = Serialization.PackSingleObject(method.ArgsType[i], arguments[i]);
                            }
                        }
                        else
                        {
                            tmp.Arguments = null;
                        }

                        return(true);
                    }
                    else
                    {
                        returnValue = method.methodInfo.Invoke(module.Token, null);
                        return(true);
                    }
                }
                else
                {
                    string msg = "Not find " + tmp.CallModule + "-> public " + tmp.Method;

                    if (ErrMsgOut != null)
                    {
                        ErrMsgOut(msg);
                    }

                    return(false);
                }
            }
            else
            {
                string msg = "Not find " + tmp.CallModule;

                if (ErrMsgOut != null)
                {
                    ErrMsgOut(msg);
                }
            }


            return(false);
        }