Ejemplo n.º 1
0
        /// <summary>
        /// 设置返回值
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public bool SetReturnValue(ZYClient_Result_Return val)
        {
            if (AsynRetrunDiy.ContainsKey(val.Id))
            {
                AsynReturn asynRet = new AsynReturn()
                {
                    ReturnValue = val
                };

                var callback = AsynRetrunDiy[val.Id];

                asynRet.Format(callback.ReturnType, callback.ArgsType);

                AsynRetrunDiy.Remove(val.Id);

                ThreadPool.QueueUserWorkItem((o) =>
                {
                    callback.Call((AsynReturn)o);
                }, asynRet);

                return(true);
            }
            else if (ReturnValueDiy.ContainsKey(val.Id))
            {
                WaitReturnValue x = ReturnValueDiy[val.Id];
                ReturnValueDiy.Remove(val.Id);
                x.returnvalue = val;
                x.waitHandle.Set();
                return(true);
            }



            return(false);
        }
Ejemplo 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
            };

            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;
                }
            }
        }
Ejemplo 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.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 < returnx.Arguments.Count; i++)
                        {
                            args[i] = Serialization.UnpackSingleObject(returnx.Arguments[i].type, returnx.Arguments[i].Value);
                        }
                    }
                    return;
                }
                else
                {
                    ReturnValueDiy.Remove(call.Id);
                    throw new TimeoutException("out time,Please set the timeout time.");
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 设置返回值
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public bool SetReturnValue(Result_Have_Return val)
        {
            lock (ReturnValueDiy)
            {
                if (ReturnValueDiy.ContainsKey(val.Id))
                {
                    var x = ReturnValueDiy[val.Id];
                    x.returnvalue = val;
                    ReturnValueDiy.Remove(val.Id);
                    x.waitHandle.Set();
                    return(true);
                }

                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 设置返回值
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public bool SetReturnValue(ZYClient_Result_Return val)
        {
            if (AsynRetrunDiy.ContainsKey(val.Id))
            {
                AsynReturn asynRet = new AsynReturn()
                {
                    ReturnValue = val
                };

                asynRet.Format();


                Action <AsynReturn> callback = AsynRetrunDiy[val.Id];
                AsynRetrunDiy.Remove(val.Id);

                ThreadPool.QueueUserWorkItem((o) =>
                {
                    try
                    {
                        callback((AsynReturn)o);
                    }
                    catch (Exception er)
                    {
                        if (ErrMsgOut != null)
                        {
                            ErrMsgOut(er.ToString());
                        }
                    }
                }, asynRet);
            }
            else if (ReturnValueDiy.ContainsKey(val.Id))
            {
                WaitReturnValue x = ReturnValueDiy[val.Id];
                ReturnValueDiy.Remove(val.Id);
                x.returnvalue = val;
                x.waitHandle.Set();
            }



            return(false);
        }
Ejemplo n.º 6
0
        public object CallMethod(string tag, string methodName, Type[] argTypelist, List <byte[]> arglist, out object[] args, Type returnType)
        {
            args = null;

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


            WaitReturnValue var = new WaitReturnValue();

            lock (ReturnValueDiy)
            {
                call.Id = Make.GetID();


                ReturnValueDiy.Add(call.Id, var);
            }

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

            if (var.waitHandle.WaitOne(OutTime))
            {
                Result_Have_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.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
            {
                lock (ReturnValueDiy)
                {
                    ReturnValueDiy.Remove(call.Id);
                }

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

                return(null);
            }
        }