Пример #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
        static void Main(string[] args)
        {
            try
            {
                XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config"));
                //获取配置的服务名称列表
                List <string> lstConfigServices = ServiceHelper.GetConfigServices();
                //启动服务
                if (null != lstConfigServices && lstConfigServices.Count > 0)
                {
                    //获取Windows服务信息
                    JsonConfigInfo winServiceInfo = ConfigHelper.LoadFromFile("WinServiceInfo.json");

                    //获取待启动的Windows服务的名称
                    string strServiceInfo = lstConfigServices[0];
                    int    intPosition    = strServiceInfo.LastIndexOf(".");
                    string strServiceName = strServiceInfo.Substring(intPosition + 1);

                    //获取服务配置
                    JObject joServiceInfo = winServiceInfo.GetValue <JObject>(strServiceName);

                    //运行服务
                    HostFactory.Run(cf =>
                    {
                        cf.SetServiceName(joServiceInfo["ServiceName"].Value <string>());
                        cf.SetDisplayName(joServiceInfo["DisplayName"].Value <string>());
                        cf.SetDescription(joServiceInfo["Description"].Value <string>());

                        cf.Service <TopshelfWrapper>(sv =>
                        {
                            sv.ConstructUsing(b => new TopshelfWrapper());
                            sv.WhenStarted(o => o.Start());
                            sv.WhenStopped(o => o.Stop());
                        });

                        cf.RunAsLocalSystem();
                        cf.StartAutomatically();
                        cf.EnablePauseAndContinue();
                    });
                }
                else
                {
                    Console.WriteLine("没有配置服务,无服务可启动!");
                }
            }
            catch (Exception ex)
            {
                string strMessage = $"服务启动失败,原因:{SysLogHelper.GetErrorLogInfo(ex, true)}";
                SysLogHelper.LogMessage("Lx.Service.WinServiceHost.Main", strMessage);
            }

            Console.ReadLine();
        }
 static LogServiceHelper()
 {
     try
     {
         JsonConfigInfo lsConfigInfo = ConfigHelper.LoadFromFile("LogService.json");
         m_enableFileLog     = lsConfigInfo.GetValue <bool>("EnableFileLog");
         m_enableDataBaseLog = lsConfigInfo.GetValue <bool>("EnableDataBaseLog");
     }
     catch (Exception ex)
     {
         string strMessage = SysLogHelper.GetErrorLogInfo(ex, true);
         SysLogHelper.LogMessage("LogServiceHelper.static", strMessage);
     }
 }
Пример #5
0
    private void JsonInitialisation(JsonConfigInfo jsonConfigInfo)
    {
        sliderDamage = jsonConfigInfo._sliderDamage;
        flyerDamage  = jsonConfigInfo._flyerDamage;
        bossDamage   = jsonConfigInfo._bossDamage;
        playerDamage = jsonConfigInfo._playerDamage;
        sliderSpeed  = jsonConfigInfo._sliderSpeed;
        flyerSpeed   = jsonConfigInfo._flyerSpeed;
        bossSpeed    = jsonConfigInfo._bossSpeed;
        playerSpeed  = jsonConfigInfo._playerSpeed;

        sliderBulletSpeed = jsonConfigInfo._sliderBulletSpeed;
        playerBulletSpeed = jsonConfigInfo._playerBulletSpeed;
        bossBulletSpeed   = jsonConfigInfo._bossBulletSpeed;
        flyerBulletSpeed  = jsonConfigInfo._flyerBulletSpeed;

        sliderHp = jsonConfigInfo._sliderHp;
        flyerHp  = jsonConfigInfo._flyerHp;
        bossHp   = jsonConfigInfo._bossHp;
        playerHp = jsonConfigInfo._playerHp;
    }
        /// <summary>
        ///     功能:加载组件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configInfo"></param>
        /// <returns></returns>
        public static T Load <T>(JsonConfigInfo configInfo)
        {
            var componentTypeName = configInfo.GetString("_type");

            if (componentTypeName == null)
            {
                var message = $"无法加载组件:{typeof(T).FullName}配置文件中缺少 _type 属性";
                SysLogHelper.LogMessage("CacheHelper.Load", message, LogLevel.Error, WriteLogType.FileLog);
                throw new ArgumentOutOfRangeException(message);
            }
            var classNameArray = componentTypeName.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);

            if (classNameArray.Length == 1)
            {
                var message = $"无法加载组件:{typeof(T).FullName}配置文件中缺少 _type 属性,缺少命名空间:{componentTypeName}";
                SysLogHelper.LogMessage("CacheHelper.Load", message, LogLevel.Error, WriteLogType.FileLog);
                throw new ArgumentOutOfRangeException(message);
            }
            var @namespace = string.Join(".", classNameArray.Take(classNameArray.Length - 1));
            var className  = classNameArray.Last();
            var target     = ObjectFactoryHelper.CreateInstance <T>(className, @namespace, true);

            if (target == null)
            {
                var componentType = Type.GetType(componentTypeName);
                target = (T)Activator.CreateInstance(componentType);
            }
            JsonConvert.PopulateObject(configInfo.Itemes.ToString(), target);
            var component = target as IComponent;

            if (component != null)
            {
                component.Init();
            }
            return(target);
        }
Пример #7
0
 /// <summary>
 /// 功能: 从字符串加载配置
 /// </summary>
 /// <param name="config">配置对象</param>
 /// <returns></returns>
 public static JsonConfigInfo LoadFromObject(object config)
 {
     return(JsonConfigInfo.LoadFromString(JsonConvert.SerializeObject(config)));
 }
Пример #8
0
 /// <summary>
 /// 功能: 从字符串加载配置
 /// </summary>
 /// <param name="json">配置字符串</param>
 /// <returns></returns>
 public static JsonConfigInfo LoadFromString(string json)
 {
     return(JsonConfigInfo.LoadFromString(json));
 }
Пример #9
0
 /// <summary>
 /// 功能:加载Json配置文件信息
 /// </summary>
 /// <param name="configFile">Json配置文件信息对象</param>
 /// <returns></returns>
 public static JsonConfigInfo LoadFromFile(string configFile)
 {
     return(JsonConfigInfo.LoadFromFile(configFile));
 }