Пример #1
0
        /// <summary>
        /// 调用NULL返回值的函数,out ref将失效,不等待同步
        /// </summary>
        /// <param name="Tag"></param>
        /// <param name="methodName"></param>
        /// <param name="argTypeList"></param>
        /// <param name="arglist"></param>
        public void CallMethod(string Tag, string methodName, Type[] argTypeList, List <byte[]> arglist)
        {
            RPCCallPack callpack = new RPCCallPack()
            {
                Tag        = Tag,
                Method     = methodName,
                Arguments  = arglist,
                NeedReturn = false,
            };

            byte[] data = BufferFormat.FormatFCA(callpack);

            if (CallBufferOutSend != null)
            {
                CallBufferOutSend(data);
            }
        }
Пример #2
0
        private void Call(RPCCallPack rpcPack, RPCUserInfo e)
        {
            try
            {
                object returnValue;

                CallContext.SetData("Current", e);

                if (e.RPC_Call.RunModule(rpcPack, rpcPack.NeedReturn, out returnValue))
                {
                    if (rpcPack.NeedReturn)
                    {
                        Result_Have_Return var = new Result_Have_Return()
                        {
                            Id        = rpcPack.Id,
                            Arguments = rpcPack.Arguments,
                        };

                        if (returnValue != null)
                        {
                            var.Return = Serialization.PackSingleObject(returnValue.GetType(), returnValue);
                        }

                        e.SendData(BufferFormat.FormatFCA(var));
                    }
                }
            }
            catch (Exception er)
            {
                if (e.Asyn.RemoteEndPoint != null)
                {
                    LogAction.Err(e.Asyn.RemoteEndPoint.ToString() + "::" + rpcPack.Tag + "->" + rpcPack.Method + "\r\n" + er.ToString());
                }
                else
                {
                    LogAction.Err(rpcPack.Tag + "->" + rpcPack.Method + "\r\n" + er.ToString());
                }
            }
        }
Пример #3
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);
            }
        }
Пример #4
0
        public object CallMethod(string tag, string methodName, Type[] argTypelist, List <byte[]> arglist, out object[] args, Type returnType)
        {
            args = null;

            RPCCallPack call = new RPCCallPack()
            {
                Id         = Make.GetID(),
                Tag        = tag,
                Method     = methodName,
                Arguments  = arglist,
                NeedReturn = true
            };


            TaskCompletionSource <Result_Have_Return> var = new TaskCompletionSource <Result_Have_Return>(TaskCreationOptions.AttachedToParent);

            if (!ResultDiy.TryAdd(call.Id, var))
            {
                SpinWait.SpinUntil(() => ResultDiy.TryAdd(call.Id, var));
            }


            byte[] data = BufferFormat.FormatFCA(call);
            if (CallBufferOutSend != null)
            {
                CallBufferOutSend(data);
            }

            if (var.Task.Wait(OutTime))
            {
                Result_Have_Return returnx = var.Task.Result;

                if (returnx.Arguments != null && returnx.Arguments.Count > 0 && arglist.Count == returnx.Arguments.Count)
                {
                    args = new object[returnx.Arguments.Count];

                    for (int i = 0; i < argTypelist.Length; i++)
                    {
                        args[i] = Serialization.UnpackSingleObject(argTypelist[i], returnx.Arguments[i]);
                    }
                }

                if (returnx.Return != null)
                {
                    object returnobj = Serialization.UnpackSingleObject(returnType, returnx.Return);
                    return(returnobj);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                if (!ResultDiy.TryRemove(call.Id, out var))
                {
                    SpinWait.SpinUntil(() => ResultDiy.TryRemove(call.Id, out var));
                }

                LogAction.Warn(tag + "->" + methodName + " out time,Please set the timeout time.");

                return(null);
            }
        }