Пример #1
0
        /// <summary>
        ///     功能:静态构造函数,创建默认的缓存实例
        /// </summary>
        static CacheHelper()
        {
            try
            {
                //获取缓存策略类别
                string strCacheStrategyType = ConfigurationManager.AppSettings["CacheStrategyType"];
                if (!string.IsNullOrWhiteSpace(strCacheStrategyType))
                {
                    //获取缓存过期时间
                    string strCacheExpiration = ConfigurationManager.AppSettings["CacheExpiration"];
                    double value;
                    if (!string.IsNullOrWhiteSpace(strCacheExpiration))
                    {
                        double.TryParse(strCacheExpiration, out value);
                        s_cacheExpiration = TimeSpan.FromMinutes(value);
                    }

                    //创建缓存策略类实例
                    var redisConfigInfo = JsonConfigInfo.LoadFromFile("cache.json");
                    s_cacheStrategy = ComponentLoader.Load <ICacheStrategy>(redisConfigInfo);
                }
            }
            catch (Exception ex)
            {
                string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
                SysLogHelper.LogMessage("CacheHelper.Static", strMessage, LogLevel.Error);
            }
        }
        /// <summary>
        ///     功能:获取一个 Message Queue
        /// </summary>
        /// <param name="messageQueueName">队列配置文件名称</param>
        /// <returns></returns>
        public static IMessageQueue GetMessageQueue(string messageQueueName = "messagequeue")
        {
            if (messageQueueName == null)
            {
                throw new ArgumentNullException("messageQueueName");
            }


            var mongoConfigInfo = JsonConfigInfo.LoadFromFile(messageQueueName + ".mq.json");

            return(ComponentLoader.Load <IMessageQueue>(mongoConfigInfo));
        }
Пример #3
0
 /// <summary>
 /// 功能:加载Json配置文件信息
 /// </summary>
 /// <param name="configFile">Json配置文件信息对象</param>
 /// <returns></returns>
 public static JsonConfigInfo LoadFromFile(string configFile)
 {
     return(JsonConfigInfo.LoadFromFile(configFile));
 }