Example #1
0
        public override IMessage Invoke(IMessage reqMsg)
        {
            IMethodCallMessage ctorMsg = reqMsg as IMethodCallMessage;

            if (Call != null)
            {
                List <RPCArgument> arglist = new List <RPCArgument>();

                Type[]   types = ctorMsg.MethodSignature as Type[];
                object[] args  = ctorMsg.Args;

                for (int i = 0; i < ctorMsg.ArgCount; i++)
                {
                    RPCArgument tmp = new RPCArgument();
                    tmp.RefType = types[i];
                    tmp.type    = args[i].GetType();
                    tmp.Value   = Serialization.PackSingleObject(tmp.type, args[i]);
                    arglist.Add(tmp);
                }

                ReturnValue returnval = Call(ModuleName, ctorMsg.MethodName, arglist);


                return(new ReturnMessage(returnval.returnVal, returnval.Args, returnval.Args == null ? 0 : returnval.Args.Length, null, ctorMsg));
            }


            throw new Exception("event not register");
        }
Example #2
0
        public override IMessage Invoke(IMessage reqMsg)
        {

            IMethodCallMessage ctorMsg = reqMsg as IMethodCallMessage;

            if (Call != null)
            {
                List<RPCArgument> arglist = new List<RPCArgument>();

                Type[] types = ctorMsg.MethodSignature as Type[];
                object[] args = ctorMsg.Args;

                for (int i = 0; i < ctorMsg.ArgCount; i++)
                {
                    RPCArgument tmp = new RPCArgument();
                    tmp.RefType = types[i];
                    tmp.type = args[i].GetType();
                    tmp.Value = Serialization.PackSingleObject(tmp.type, args[i]);
                    arglist.Add(tmp);
                }

                ReturnValue returnval = Call(ModuleName, ctorMsg.MethodName, arglist);


                return new ReturnMessage(returnval.returnVal, returnval.Args, returnval.Args == null ? 0 : returnval.Args.Length, null, ctorMsg);


            }


            throw new Exception("event not register");

        }
Example #3
0
        /// <summary>
        /// 同步调用返回
        /// </summary>
        /// <typeparam name="Mode"></typeparam>
        /// <typeparam name="Result"></typeparam>
        /// <param name="action"></param>
        /// <returns></returns>
        public Result Call <Mode, Result>(Expression <Func <Mode, Result> > action)
        {
            MethodCallExpression body = action.Body as MethodCallExpression;

            List <RPCArgument> argumentlist = new List <RPCArgument>();

            var parameters = body.Method.GetParameters();

            for (int i = 0; i < parameters.Length; i++)
            {
                dynamic p = Expression.Call(FormatValue.GetMethodInfo(body.Arguments[i].Type), body.Arguments[i]);
                dynamic x = Expression.Lambda <Func <dynamic> >(p).Compile()();

                RPCArgument tmp = new RPCArgument();
                tmp.type    = body.Arguments[i].Type;
                tmp.RefType = parameters[i].ParameterType;
                tmp.Value   = Serialization.PackSingleObject(body.Arguments[i].Type, x);
                argumentlist.Add(tmp);
            }

            object[] args;

            Result res = CallMethod <Result>(body.Object.Type.Name, body.Method.Name, argumentlist, out args);

            if (args != null)
            {
                if (args.Length == body.Arguments.Count)
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (body.Arguments[i].NodeType == ExpressionType.MemberAccess)
                        {
                            var set = Expression.Assign(body.Arguments[i], Expression.Constant(args[i]));

                            Expression.Lambda <Action>(set).Compile()();
                        }
                    }
                }
            }

            return(res);
        }
Example #4
0
        /// <summary>
        /// 异步调用,返回值后调用 Callback
        /// </summary>
        /// <typeparam name="Mode"></typeparam>
        /// <typeparam name="Result"></typeparam>
        /// <param name="action"></param>
        /// <param name="Callback"></param>
        public void CallAsyn <Mode, Result>(Expression <Func <Mode, Result> > action, Action <AsynReturn> Callback)
        {
            MethodCallExpression body = action.Body as MethodCallExpression;

            List <RPCArgument> argumentlist = new List <RPCArgument>();

            var parameters = body.Method.GetParameters();

            for (int i = 0; i < parameters.Length; i++)
            {
                dynamic p = Expression.Call(FormatValue.GetMethodInfo(body.Arguments[i].Type), body.Arguments[i]);
                dynamic x = Expression.Lambda <Func <dynamic> >(p).Compile()();

                RPCArgument tmp = new RPCArgument();
                tmp.type    = body.Arguments[i].Type;
                tmp.RefType = parameters[i].ParameterType;
                tmp.Value   = Serialization.PackSingleObject(body.Arguments[i].Type, x);
                argumentlist.Add(tmp);
            }



            RPCCallPack call = new RPCCallPack()
            {
                Id           = MakeID.GetID(),
                CallTime     = DateTime.Now,
                CallModule   = body.Object.Type.Name,
                Method       = body.Method.Name,
                Arguments    = argumentlist,
                IsNeedReturn = true,
            };

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

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


            AsynRetrunDiy.AddOrUpdate(call.Id, Callback, (a, b) => Callback);
        }