コード例 #1
0
        /// <summary>
        /// 反转到具体的方法上
        /// </summary>
        /// <param name="IUserToken"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static byte[] Reversal(IUserToken IUserToken, RSocketMsg msg)
        {
            byte[] result = null;

            object[] inputs = null;

            if (msg.Data != null)
            {
                var serviceInfo = RPCMapping.Get(msg.ServiceName, msg.MethodName);

                if (serviceInfo == null)
                {
                    throw new RPCNotFundException($"找不到服务:{msg.ServiceName}/{msg.MethodName}");
                }

                var ptypes = serviceInfo.Pamars.Values.ToArray();

                inputs = SAEASerialize.Deserialize(ptypes, msg.Data);
            }

            var r = Reversal(IUserToken, msg.ServiceName, msg.MethodName, inputs);

            if (r != null)
            {
                return(SAEASerialize.Serialize(r));
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 反转到具体的方法上
        /// </summary>
        /// <param name="userToken"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static byte[] Reversal(IUserToken userToken, RSocketMsg msg)
        {
            byte[] result = null;
            try
            {
                object[] inputs = null;

                if (msg.Data != null)
                {
                    var ptypes = RPCMapping.Get(msg.ServiceName, msg.MethodName).Pamars.Values.ToArray();

                    inputs = ParamsSerializeUtil.Deserialize(ptypes, msg.Data);
                }

                var r = Reversal(userToken, msg.ServiceName, msg.MethodName, inputs);

                if (r != null)
                {
                    return(ParamsSerializeUtil.Serialize(r));
                }
            }
            catch (Exception ex)
            {
                throw new RPCPamarsException("RPCInovker.Invoke error:" + ex.Message, ex);
            }
            return(result);
        }
コード例 #3
0
        public static object Reversal(IUserToken userToken, string serviceName, string methodName, object[] inputs)
        {
            var serviceInfo = RPCMapping.Get(serviceName, methodName);

            if (serviceInfo == null)
            {
                throw new RPCNotFundException($"当前请求找不到:{serviceName}/{methodName}", null);
            }

            var nargs = new object[] { userToken, serviceName, methodName, inputs };

            if (serviceInfo.FilterAtrrs != null && serviceInfo.FilterAtrrs.Count > 0)
            {
                foreach (var arr in serviceInfo.FilterAtrrs)
                {
                    var goOn = (bool)arr.GetType().GetMethod("OnActionExecuting").Invoke(arr, nargs.ToArray());

                    if (!goOn)
                    {
                        return(null);
                    }
                }
            }

            if (serviceInfo.ActionFilterAtrrs != null && serviceInfo.ActionFilterAtrrs.Count > 0)
            {
                foreach (var arr in serviceInfo.ActionFilterAtrrs)
                {
                    var goOn = (bool)arr.GetType().GetMethod("OnActionExecuting").Invoke(arr, nargs.ToArray());

                    if (!goOn)
                    {
                        return(null);
                    }
                }
            }

            var result = ReversalMethod(serviceInfo.Instance, serviceInfo.Method, inputs);

            nargs = new object[] { userToken, serviceName, methodName, inputs, result };

            if (serviceInfo.FilterAtrrs != null && serviceInfo.FilterAtrrs.Count > 0)
            {
                foreach (var arr in serviceInfo.FilterAtrrs)
                {
                    arr.GetType().GetMethod("OnActionExecuted").Invoke(arr, nargs);
                }
            }

            if (serviceInfo.ActionFilterAtrrs != null && serviceInfo.ActionFilterAtrrs.Count > 0)
            {
                foreach (var arr in serviceInfo.FilterAtrrs)
                {
                    arr.GetType().GetMethod("OnActionExecuted").Invoke(arr, nargs);
                }
            }
            return(result);
        }
コード例 #4
0
        public static object Reversal(IUserToken userToken, string serviceName, string methodName, object[] inputs)
        {
            var serviceInfo = RPCMapping.Get(serviceName, methodName);

            if (serviceInfo == null)
            {
                throw new RPCNotFundException($"当前请求找不到:{serviceName}/{methodName}", null);
            }

            #region 执行前

            var nargs = new object[] { userToken, serviceName, methodName, inputs };

            if (serviceInfo.FilterAtrrs != null && serviceInfo.FilterAtrrs.Any())
            {
                foreach (var arr in serviceInfo.FilterAtrrs)
                {
                    var goOn = (bool)arr.GetType().GetMethod(ConstHelper.ONACTIONEXECUTING).Invoke(arr, nargs.ToArray());

                    if (!goOn)
                    {
                        return(null);
                    }
                }
            }

            if (serviceInfo.ActionFilterAtrrs != null && serviceInfo.ActionFilterAtrrs.Any())
            {
                foreach (var arr in serviceInfo.ActionFilterAtrrs)
                {
                    var goOn = (bool)arr.GetType().GetMethod(ConstHelper.ONACTIONEXECUTING).Invoke(arr, nargs.ToArray());

                    if (!goOn)
                    {
                        return(null);
                    }
                }
            }

            #endregion

            var result = ReversalMethod(serviceInfo.Instance, serviceInfo.Method, inputs);

            #region 执行后

            nargs = new object[] { userToken, serviceName, methodName, inputs, result };

            if (serviceInfo.FilterAtrrs != null && serviceInfo.FilterAtrrs.Any())
            {
                foreach (var arr in serviceInfo.FilterAtrrs)
                {
                    arr.GetType().GetMethod(ConstHelper.ONACTIONEXECUTED).Invoke(arr, nargs);
                }
            }

            if (serviceInfo.ActionFilterAtrrs != null && serviceInfo.ActionFilterAtrrs.Any())
            {
                foreach (var arr in serviceInfo.ActionFilterAtrrs)
                {
                    arr.GetType().GetMethod(ConstHelper.ONACTIONEXECUTED).Invoke(arr, nargs);
                }
            }

            #endregion

            return(result);
        }
コード例 #5
0
ファイル: RPCReversal.cs プロジェクト: windinternet/SAEA
        public static object Reversal(IUserToken userToken, string serviceName, string methodName, object[] inputs)
        {
            lock (_locker)
            {
                try
                {
                    var serviceInfo = RPCMapping.Get(serviceName, methodName);

                    if (serviceInfo == null)
                    {
                        throw new RPCNotFundException($"当前请求找不到:{serviceName}/{methodName}", null);
                    }

                    var nargs = new object[] { userToken, serviceName, methodName, inputs };

                    if (serviceInfo.FilterAtrrs != null && serviceInfo.FilterAtrrs.Count > 0)
                    {
                        foreach (var arr in serviceInfo.FilterAtrrs)
                        {
                            var goOn = (bool)FastInvoke.GetMethodInvoker(arr.GetType().GetMethod("OnActionExecuting")).Invoke(arr, nargs.ToArray());

                            if (!goOn)
                            {
                                return(new RPCNotFundException("当前逻辑已被拦截!", null));
                            }
                        }
                    }

                    if (serviceInfo.ActionFilterAtrrs != null && serviceInfo.ActionFilterAtrrs.Count > 0)
                    {
                        foreach (var arr in serviceInfo.ActionFilterAtrrs)
                        {
                            var goOn = (bool)FastInvoke.GetMethodInvoker(arr.GetType().GetMethod("OnActionExecuting")).Invoke(arr, nargs.ToArray());

                            if (!goOn)
                            {
                                return(new RPCNotFundException("当前逻辑已被拦截!", null));
                            }
                        }
                    }

                    var result = ReversalMethod(serviceInfo.Method, serviceInfo.MethodInvoker, serviceInfo.Instance, inputs);

                    nargs = new object[] { userToken, serviceName, methodName, inputs, result };

                    if (serviceInfo.FilterAtrrs != null && serviceInfo.FilterAtrrs.Count > 0)
                    {
                        foreach (var arr in serviceInfo.FilterAtrrs)
                        {
                            FastInvoke.GetMethodInvoker(arr.GetType().GetMethod("OnActionExecuted")).Invoke(arr, nargs);
                        }
                    }

                    if (serviceInfo.ActionFilterAtrrs != null && serviceInfo.ActionFilterAtrrs.Count > 0)
                    {
                        foreach (var arr in serviceInfo.FilterAtrrs)
                        {
                            FastInvoke.GetMethodInvoker(arr.GetType().GetMethod("OnActionExecuted")).Invoke(arr, nargs);
                        }
                    }
                    return(result);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("找不到此rpc方法"))
                    {
                        return(new RPCNotFundException("找不到此rpc方法", ex));
                    }
                    else
                    {
                        return(new RPCNotFundException("找不到此rpc方法", ex));
                    }
                }
            }
        }