Esempio n. 1
0
 /// <summary>
 /// 注册 IServiceCollection,并返回 RegisterService,开始注册流程(必须)
 /// </summary>
 /// <param name="serviceCollection">IServiceCollection</param>
 /// <param name="certName">证书名称,必须全局唯一,并且确保在全局 HttpClientFactory 内唯一</param>
 /// <param name="certSecret">证书密码</param>
 /// <param name="certPath">证书路径(物理路径)</param>
 /// <param name="checkValidationResult">设置</param>
 /// <returns></returns>
 public static IServiceCollection AddSenparcHttpClientWithCertificate(this IServiceCollection serviceCollection,
                                                                      string certName, string certSecret, string certPath, bool checkValidationResult = false)
 {
     //添加注册
     if (!string.IsNullOrEmpty(certPath))
     {
         if (File.Exists(certPath))
         {
             try
             {
                 var cert = new X509Certificate2(certPath, certSecret, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);
                 return(AddSenparcHttpClientWithCertificate(serviceCollection, certName, cert, checkValidationResult));
             }
             catch (Exception ex)
             {
                 LogTrace.SendCustomLog($"添加微信支付证书发生异常", $"certName:{certName},certPath:{certPath}");
                 LogTrace.BaseExceptionLog(ex);
                 return(serviceCollection);
             }
         }
         else
         {
             LogTrace.SendCustomLog($"已设置微信支付证书,但无法找到文件", $"certName:{certName},certPath:{certPath}");
             return(serviceCollection);
         }
     }
     return(serviceCollection);
 }
        /// <summary>
        /// 注册列表
        /// </summary>
        /// <param name="configurationString">连接字符串</param>
        public static void RegisterServerList(string configurationString)
        {
            if (!string.IsNullOrEmpty(configurationString))
            {
                var dic     = new Dictionary <string, int>();
                var servers = configurationString.Split(';');
                foreach (var server in servers)
                {
                    try
                    {
                        var serverData = server.Split(':');
                        dic[serverData[0]] = int.Parse(serverData[1]);
                    }
                    catch (Exception ex)
                    {
                        LogTrace.BaseExceptionLog(new CacheException(ex.Message, ex));
                    }
                }

                if (dic.Count() > 0)
                {
                    OFoodDI.GlobalServiceCollection.AddSenparcMemcached(options =>
                    {
                        foreach (var item in dic)
                        {
                            options.AddServer(item.Key, item.Value);
                        }
                    });
                }


                RegisterServerList(dic);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// BaseException
 /// </summary>
 /// <param name="message">异常消息</param>
 /// <param name="inner">内部异常信息</param>
 /// <param name="logged">是否已经使用WeixinTrace记录日志,如果没有,BaseException会进行概要记录</param>
 public BaseException(string message, Exception inner, bool logged = false)
     : base(message, inner)
 {
     if (!logged)
     {
         //LogTrace.Log(string.Format("BaseException({0}):{1}", this.GetType().Name, message));
         LogTrace.BaseExceptionLog(this);
     }
 }
        /// <summary>
        /// 获取领域缓存(指定特定 的IBaseObjectCacheStrategy 缓存策略对象)
        /// </summary>
        /// <param name="baseObjectCacheStrategy">IBaseObjectCacheStrategy 缓存策略对象</param>
        /// <param name="cacheStrategyDomain">缓存领域</param>
        /// <returns></returns>
        public static IDomainExtensionCacheStrategy GetDomainExtensionCacheStrategy(IBaseObjectCacheStrategy baseObjectCacheStrategy,
                                                                                    ICacheStrategyDomain cacheStrategyDomain)
        {
            var identityName      = cacheStrategyDomain.IdentityName;
            var mappingCollection = GetMappingCollection(identityName);//当前扩展缓存可能已经注册的所有基础缓存

            if (mappingCollection.ContainsKey(baseObjectCacheStrategy))
            {
                var item = mappingCollection[baseObjectCacheStrategy];
                return(item.DomainExtensionCacheStrategy);
            }
            else
            {
                //未注册,默认情况下使用本地缓存策略(应急)
                var ex = new Exceptions.UnregisteredDomainCacheStrategyException(cacheStrategyDomain.GetType(), baseObjectCacheStrategy.GetType());
                LogTrace.BaseExceptionLog(ex);
                throw ex;
            }
        }