Beispiel #1
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);
            }
        }