public static WeixinExceptionLog ( |
||
ex | ||
리턴 | void |
/// <summary> /// 开始 Senparc.Weixin SDK 初始化参数流程 /// </summary> /// <param name="registerService"></param> /// <param name="senparcWeixinSetting"></param> /// <param name="extensionCacheStrategiesFunc"><para>需要注册的扩展缓存策略</para> /// <para>(LocalContainerCacheStrategy、RedisContainerCacheStrategy、MemcacheContainerCacheStrategy已经自动注册),</para> /// <para>如果设置为 null(注意:不适委托返回 null,是整个委托参数为 null),则自动使用反射扫描所有可能存在的扩展缓存策略</para></param> /// <returns></returns> public static IRegisterService UseSenparcWeixin(this IRegisterService registerService, SenparcWeixinSetting senparcWeixinSetting, Func <IList <IDomainExtensionCacheStrategy> > extensionCacheStrategiesFunc = null) { senparcWeixinSetting = senparcWeixinSetting ?? new SenparcWeixinSetting(); //Senparc.Weixin SDK 配置 Senparc.Weixin.Config.IsDebug = senparcWeixinSetting.IsDebug; Senparc.Weixin.Config.DefaultSenparcWeixinSetting = senparcWeixinSetting; // 微信的 本地 缓存 var cache = LocalContainerCacheStrategy.Instance;//只要引用就可以被激活 if (extensionCacheStrategiesFunc != null) { var containerCacheStrategies = extensionCacheStrategiesFunc(); if (containerCacheStrategies != null) { foreach (var cacheStrategy in containerCacheStrategies) { var exCache = cacheStrategy;//确保能运行到就行,会自动注册 } } } else { var officialTypes = new List <Type>() { typeof(LocalContainerCacheStrategy) }; //自动注册 Redis 和 Memcached //Redis var redisConfiguration = senparcWeixinSetting.Cache_Redis_Configuration; if ((!string.IsNullOrEmpty(redisConfiguration) && redisConfiguration != "Redis配置")) { try { var redisInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Redis", "Senparc.Weixin.Cache.Redis", "RedisContainerCacheStrategy", "Instance"); officialTypes.Add(redisInstance.GetType()); } catch (Exception ex) { WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex)); } } //Memcached var memcachedConfiguration = senparcWeixinSetting.Cache_Memcached_Configuration; if ((!string.IsNullOrEmpty(memcachedConfiguration) && memcachedConfiguration != "Memcached配置")) { try { var memcachedInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Memcached", "Senparc.Weixin.Cache.Memcached", "MemcachedContainerCacheStrategy", "Instance"); officialTypes.Add(memcachedInstance.GetType()); } catch (Exception ex) { WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex)); } } //查找所有扩产缓存 var types = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetTypes() .Where(t => !t.IsAbstract && !officialTypes.Contains(t) && t.GetInterfaces().Contains(typeof(IDomainExtensionCacheStrategy)))) .ToArray(); foreach (var type in types) { try { var exCache = ReflectionHelper.GetStaticMember(type, "Instance"); } catch (Exception ex) { WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex)); } } } return(registerService); }
/// <summary> /// 开始 Senparc.Weixin SDK 初始化参数流程 /// </summary> /// <param name="registerService"></param> /// <param name="senparcWeixinSetting">微信全局设置参数,必填</param> /// <param name="senparcSetting">用于提供 SenparcSetting.Cache_Redis_Configuration 和 Cache_Memcached_Configuration 两个参数,如果不使用这两种分布式缓存可传入null</param> /// <returns></returns> public static IRegisterService UseSenparcWeixin(this IRegisterService registerService, SenparcWeixinSetting senparcWeixinSetting, SenparcSetting senparcSetting = null) { senparcWeixinSetting = senparcWeixinSetting ?? new SenparcWeixinSetting(); senparcSetting = (senparcSetting ?? CO2NET.Config.SenparcSetting) ?? new SenparcSetting(); //Senparc.Weixin SDK 配置 Senparc.Weixin.Config.SenparcWeixinSetting = senparcWeixinSetting; /* 扩展缓存注册开始 */ var cacheTypes = "";//所有注册的扩展缓存 // 微信的 本地 缓存 var cache = LocalContainerCacheStrategy.Instance;//只要引用就可以被激活 cacheTypes += typeof(LocalContainerCacheStrategy); var dt1 = SystemTime.Now; //官方扩展缓存注册 //var officialTypes = new List<Type>() { typeof(LocalContainerCacheStrategy) };//官方提供的扩展缓存策略 //自动注册 Redis 和 Memcached //Redis var redisConfiguration = senparcSetting.Cache_Redis_Configuration; if (!string.IsNullOrEmpty(redisConfiguration) && /*缓存配置默认值,不启用*/ redisConfiguration != "Redis配置" && redisConfiguration != "#{Cache_Redis_Configuration}#") { try { { //StackExchange.Redis var redisInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Redis", "Senparc.Weixin.Cache.Redis", "RedisContainerCacheStrategy", "Instance"); if (redisInstance != null) { //officialTypes.Add(redisInstance.GetType()); cacheTypes += "\r\n" + redisInstance.GetType(); } } { //CsRedis var redisInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.CsRedis", "Senparc.Weixin.Cache.CsRedis", "RedisContainerCacheStrategy", "Instance"); if (redisInstance != null) { //officialTypes.Add(redisInstance.GetType()); cacheTypes += "\r\n" + redisInstance.GetType(); } } } catch (Exception ex) { WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex)); } } //Memcached var memcachedConfiguration = senparcSetting.Cache_Memcached_Configuration; if (!string.IsNullOrEmpty(memcachedConfiguration) && /*缓存配置默认值,不启用*/ memcachedConfiguration != "Memcached配置" && memcachedConfiguration != "#{Cache_Memcached_Configuration}#") { try { var memcachedInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Memcached", "Senparc.Weixin.Cache.Memcached", "MemcachedContainerCacheStrategy", "Instance"); if (memcachedInstance != null) { //officialTypes.Add(memcachedInstance.GetType()); cacheTypes += "\r\n" + memcachedInstance.GetType(); } } catch (Exception ex) { WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex)); } } var exCacheLog = $"微信扩展缓存注册总用时:{SystemTime.DiffTotalMS(dt1, "f4")}ms\r\n扩展缓存:{cacheTypes}"; WeixinTrace.SendCustomLog("微信扩展缓存注册完成", exCacheLog); /* 扩展缓存注册结束 */ //ApiBind 自动扫描 Senparc.NeuChar.Register.RegisterApiBind(false); return(registerService); }
/// <summary> /// 开始 Senparc.Weixin SDK 初始化参数流程 /// </summary> /// <param name="registerService"></param> /// <param name="senparcWeixinSetting">微信全局设置参数,必填</param> /// <param name="senparcSetting">用于提供 SenparcSetting.Cache_Redis_Configuration 和 Cache_Memcached_Configuration 两个参数,如果不使用这两种分布式缓存可传入null</param> /// <returns></returns> public static IRegisterService UseSenparcWeixin(this IRegisterService registerService, SenparcWeixinSetting senparcWeixinSetting, SenparcSetting senparcSetting = null) { senparcWeixinSetting = senparcWeixinSetting ?? new SenparcWeixinSetting(); senparcSetting = senparcSetting ?? new SenparcSetting(); //Senparc.Weixin SDK 配置 Senparc.Weixin.Config.SenparcWeixinSetting = senparcWeixinSetting; /* 扩展缓存注册开始 */ var cacheTypes = "";//所有注册的扩展缓存 // 微信的 本地 缓存 var cache = LocalContainerCacheStrategy.Instance;//只要引用就可以被激活 cacheTypes += typeof(LocalContainerCacheStrategy); DateTime dt1 = DateTime.Now; //官方扩展缓存注册 //var officialTypes = new List<Type>() { typeof(LocalContainerCacheStrategy) };//官方提供的扩展缓存策略 //自动注册 Redis 和 Memcached //Redis var redisConfiguration = senparcSetting.Cache_Redis_Configuration; if ((!string.IsNullOrEmpty(redisConfiguration) && redisConfiguration != "Redis配置")) { try { var redisInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Redis", "Senparc.Weixin.Cache.Redis", "RedisContainerCacheStrategy", "Instance"); if (redisInstance != null) { //officialTypes.Add(redisInstance.GetType()); cacheTypes += "\r\n" + redisInstance.GetType(); } } catch (Exception ex) { WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex)); } } //Memcached var memcachedConfiguration = senparcSetting.Cache_Memcached_Configuration; if ((!string.IsNullOrEmpty(memcachedConfiguration) && memcachedConfiguration != "Memcached配置")) { try { var memcachedInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Memcached", "Senparc.Weixin.Cache.Memcached", "MemcachedContainerCacheStrategy", "Instance"); if (memcachedInstance != null) { //officialTypes.Add(memcachedInstance.GetType()); cacheTypes += "\r\n" + memcachedInstance.GetType(); } } catch (Exception ex) { WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex)); } } DateTime dt2 = DateTime.Now; var exCacheLog = "微信扩展缓存注册总用时:{0}ms\r\n扩展缓存:{1}".FormatWith((dt2 - dt1).TotalMilliseconds, cacheTypes); WeixinTrace.SendCustomLog("微信扩展缓存注册完成", exCacheLog); /* 扩展缓存注册结束 */ //ApiBind 自动扫描 Senparc.NeuChar.Register.RegisterApiBind(); return(registerService); }