Пример #1
0
 /// <summary>
 /// 调用请求使用同一个终结点;好处是远程服务切换后,已创建的接口对象可以继续使用
 /// </summary>
 /// <param name="request">请求</param>
 /// <returns></returns>
 private object Intercept_RemoteProceed(CallRequest request)
 {
     try {
         if (_beforeRequest != null)
         {
             request = _beforeRequest.Process(request);
         }
         var response = _messageRequester.GetResponse(request) as CallResponse;
         if (_afterResponse != null)
         {
             response = _afterResponse.Process(response);
         }
         if (!response.IsProcessSucceed)
         {
             throw (Exception)response.Transfer;
         }
         return(response.Transfer);
     }
     catch (Exception e) {
         if (ExceptionCatcher == null)
         {
             throw;
         }
         ExceptionCatcher.Catch(e, null, request.Method);
         return(null);
     }
 }
Пример #2
0
        public void Intercept(IInvocation invoc)
        {
            var request = new CallRequest {
                InterfaceType = InterfaceType,
                Method        = invoc.Method,
                Parameters    = invoc.Arguments
            };

            try {
                invoc.ReturnValue = RemoteProceed?.Invoke(request);
            }
            catch (Exception exception) {
                ExceptionCatcher.Catch(exception, invoc.MethodInvocationTarget, invoc.Method);
            }
        }
Пример #3
0
        public virtual object Execute(CallRequest request)
        {
            var resolve = Container.Resolve(request.InterfaceType);

            if (resolve == null)
            {
                throw new Exception($"服务容器没有注册接口{request.InterfaceType}对应的类");
            }
            var result     = request.Method.Invoke(resolve, request.Parameters);
            var returnType = request.Method.ReturnType;

            if (returnType.FullName.StartsWith("System.Collections.Generic.IEnumerable`1"))
            {
                var genericType   = returnType.GenericTypeArguments[0];
                var genericMethod = _baseCastMethod.MakeGenericMethod(genericType);
                result = genericMethod.Invoke(null, new[] { result });
            }
            return(result);
        }