Esempio n. 1
0
        public void CallMethod(string module, string MethodName, List <Type> argTypeList, List <byte[]> arglist, out object[] args)
        {
            args = null;

            RPCCallPack call = new RPCCallPack()
            {
                Id         = MakeID.GetID(),
                CallTime   = MakeID.GetTick(),
                CallModule = module,
                Method     = MethodName,
                Arguments  = arglist
            };

            WaitReturnValue var = new WaitReturnValue();

            using (var.waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset))
            {
                ReturnValueDiy.Add(call.Id, var);

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

                if (CallBufferOutSend != null)
                {
                    CallBufferOutSend(data);
                }

                if (var.waitHandle.WaitOne(OutTime))
                {
                    ZYClient_Result_Return returnx = var.returnvalue;

                    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.Count; i++)
                        {
                            args[i] = Serialization.UnpackSingleObject(argTypeList[i], returnx.Arguments[i]);
                        }
                    }

                    return;
                }
                else
                {
                    ReturnValueDiy.Remove(call.Id);


                    if (ErrMsgOut != null)
                    {
                        ErrMsgOut(module + "->" + MethodName + " out time,Please set the timeout time.");
                    }

                    return;
                }
            }
        }
Esempio n. 2
0
        public void CallMethod(string module, string MethodName, List <Type> argTypeList, List <byte[]> arglist, out object[] args)
        {
            args = null;

            RPCCallPack call = new RPCCallPack()
            {
                Id         = MakeID.GetID(),
                CallTime   = MakeID.GetTick(),
                CallModule = module,
                Method     = MethodName,
                Arguments  = arglist
            };

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


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


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

            if (CallBufferOutSend != null)
            {
                CallBufferOutSend(data);
            }


            if (var.Task.Wait(OutTime))
            {
                ZYClient_Result_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.Count; i++)
                    {
                        args[i] = Serialization.UnpackSingleObject(argTypeList[i], returnx.Arguments[i]);
                    }
                }
            }
            else
            {
                ReturnValueDiy.TryRemove(call.Id, out var);

                if (ErrMsgOut != null)
                {
                    ErrMsgOut(module + "->" + MethodName + " out time,Please set the timeout time.");
                }
            }
        }
Esempio n. 3
0
        public void CallMethod(string module, string MethodName, List <RPCArgument> arglist, out object[] args)
        {
            args = null;

            RPCCallPack call = new RPCCallPack()
            {
                Id           = MakeID.GetID(),
                CallTime     = DateTime.Now,
                CallModule   = module,
                Method       = MethodName,
                Arguments    = arglist,
                IsNeedReturn = true,
            };

            WaitReturnValue var = new WaitReturnValue();

            using (var.waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset))
            {
                ReturnValueDiy.AddOrUpdate(call.Id, var, (a, b) => var);

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

                if (CallBufferOutSend != null)
                {
                    CallBufferOutSend(data);
                }


                if (var.waitHandle.WaitOne(OutTime))
                {
                    ZYClient_Result_Return returnx = var.returnvalue;

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

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

                    return;
                }
                else
                {
                    ReturnValueDiy.TryRemove(call.Id, out var);

                    throw new TimeoutException("out time,Please set the timeout time.");
                }
            }
        }
Esempio n. 4
0
        public void Format()
        {
            if (ReturnValue != null)
            {
                ReturnType = ReturnValue.ReturnType;
                Return     = Serialization.UnpackSingleObject(ReturnType, ReturnValue.Return);

                if (ReturnValue.Arguments.Count > 0)
                {
                    foreach (var item in ReturnValue.Arguments)
                    {
                        Argument tmp = new Argument()
                        {
                            Type  = item.type,
                            value = Serialization.UnpackSingleObject(item.type, item.Value)
                        };
                    }
                }
            }
        }
Esempio n. 5
0
        public void Format(Type ReturnType, List <Type> argTypelist)
        {
            if (ReturnValue != null && ReturnValue.Return != null)
            {
                Return = Serialization.UnpackSingleObject(ReturnType, ReturnValue.Return);
            }

            if (ReturnValue.Arguments != null && ReturnValue.Arguments.Count > 0)
            {
                ArgList = new List <Argument>();

                for (int i = 0; i < argTypelist.Count; i++)
                {
                    Argument tmp = new Argument()
                    {
                        Type  = argTypelist[i],
                        value = Serialization.UnpackSingleObject(argTypelist[i], ReturnValue.Arguments[i])
                    };

                    ArgList.Add(tmp);
                }
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }