示例#1
0
 public static void AfterDo <T>(ProxyBase __instance, T __result)
 {
     try
     {
         if (__result == null)
         {
             return;
         }
         Type type = __instance.GetType();
         Logger.Error(type.FullName + "-AfterDo-SessionID:" + ServiceSession.SessionID);
         ProxyType proxyType = null;
         if (!string.IsNullOrEmpty(type.FullName))
         {
             ProxyTypeDict.TryGetValue(type.FullName, out proxyType);
         }
         Logger.Error("ReturnData:" + (proxyType == null
             ? ProxyJsonHelper.ProxyResultToJsonString(__result)
             : ProxyJsonHelper.ProxyResultToJsonString(__result, proxyType.UseDataMemberTransData,
                                                       proxyType.OutMaxExpandDepth)));
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
     }
 }
示例#2
0
        /// <summary>
        ///     执行请求
        /// </summary>
        /// <param name="proxy"></param>
        /// <returns></returns>
        public ReturnMessage <string> ProxyDo(Proxy proxy)
        {
            if (proxy == null)
            {
                throw new ProxyServiceException("proxy is null");
            }
            var  proxyType     = proxy.ProxyType;
            Type proxyBaseType = ProxyHelper.GetType(proxyType);

            if (string.IsNullOrEmpty(proxy.ProxyJsonString))
            {
                throw new ProxyServiceException("proxy.ProxyJsonString is empty");
            }
            if (proxyType.OutMaxExpandDepth <= 0)
            {
                proxyType.OutMaxExpandDepth = ProxyJsonHelper.DefaultOutMaxWritingDepth;
            }
            if (proxyType.OutMaxExpandDepth > ProxyJsonHelper.MaxOutMaxWritingDepth)
            {
                throw new ProxyServiceException(string.Format("outMaxExpandDepth is max value is {0}",
                                                              ProxyJsonHelper.MaxOutMaxWritingDepth));
            }
            ProxyBase proxyBase =
                ProxyJsonHelper.ProxyObjectFromJsonString(proxy.ProxyJsonString,
                                                          proxyBaseType, proxyType.UseDataMemberTransData) as
                ProxyBase;

            if (proxyBase == null)
            {
                throw new ProxyServiceException(string.Format("proxyType:{0},{1} is not proxy base object",
                                                              proxyType.FullName,
                                                              proxyType.AssemblyName));
            }
            MethodInfo methodInfo = proxyBase.GetType().GetMethod("Do", new Type[] {});

            if (methodInfo == null)
            {
                throw new ProxyServiceException(string.Format("no find Do() method in proxyType:{0},{1}",
                                                              proxyType.FullName,
                                                              proxyType.AssemblyName));
            }
            object result = methodInfo.Invoke(proxyBase, null);
            ReturnMessage <string> ret = new ReturnMessage <string>();

            ret.IsSuccess = true;
            ret.Result    = result == null
                ? string.Empty
                : ProxyJsonHelper.ProxyResultToJsonString(result, proxyType.UseDataMemberTransData,
                                                          proxyType.OutMaxExpandDepth);
            return(ret);
        }