Ejemplo n.º 1
0
        private object LoadConfigProperty(ConfigPropertyAttribute attrib)
        {
            string key  = attrib.Key;
            string text = ConfigurationManager.AppSettings[key];

            if (text == null)
            {
                text = attrib.DefaultValue.ToString();
                BaseAppConfig.log.Warn("Loading " + key + " value is null,using default vaule:" + text);
            }
            else
            {
                BaseAppConfig.log.Debug("Loading " + key + " Value is " + text);
            }
            object result;

            try
            {
                result = Convert.ChangeType(text, attrib.DefaultValue.GetType());
            }
            catch (Exception exception)
            {
                BaseAppConfig.log.Error("Exception in ServerProperties Load: ", exception);
                result = null;
            }
            return(result);
        }
Ejemplo n.º 2
0
        private object LoadConfigProperty(ConfigPropertyAttribute attrib)
        {
            string key   = attrib.Key;
            string value = AppConfig.AppSettings[key];

            if (value == null)
            {
                value = attrib.DefaultValue.ToString();
                LogProvider.Default.Warn("Loading " + key + " value is null,using default vaule:" + value);
            }
            else
            {
                LogProvider.Default.Debug("Loading " + key + " Value is " + value);
            }
            object result;

            try
            {
                result = Convert.ChangeType(value, attrib.DefaultValue.GetType());
            }
            catch (Exception e)
            {
                LogProvider.Default.Error("Exception in ServerProperties Load: ", e);
                result = null;
            }
            return(result);
        }
Ejemplo n.º 3
0
 protected virtual void Load(Type type)
 {
     ConfigurationManager.RefreshSection("appSettings");
     foreach (FieldInfo info in type.GetFields())
     {
         object[] customAttributes = info.GetCustomAttributes(typeof(ConfigPropertyAttribute), false);
         if (customAttributes.Length != 0)
         {
             ConfigPropertyAttribute attrib = (ConfigPropertyAttribute)customAttributes[0];
             info.SetValue(this, this.LoadConfigProperty(attrib));
         }
     }
 }
Ejemplo n.º 4
0
 protected virtual void Load(Type type)
 {
     ConfigurationManager.RefreshSection("appSettings");
     FieldInfo[] fields = type.GetFields();
     for (int i = 0; i < fields.Length; i++)
     {
         FieldInfo fieldInfo        = fields[i];
         object[]  customAttributes = fieldInfo.GetCustomAttributes(typeof(ConfigPropertyAttribute), false);
         if (customAttributes.Length != 0)
         {
             ConfigPropertyAttribute attrib = (ConfigPropertyAttribute)customAttributes[0];
             fieldInfo.SetValue(this, this.LoadConfigProperty(attrib));
         }
     }
 }
Ejemplo n.º 5
0
        protected virtual void Load(Type type)
        {
            ConfigurationManager.RefreshSection("appSettings");

            foreach (FieldInfo f in type.GetFields())
            {
                object[] attribs = f.GetCustomAttributes(typeof(ConfigPropertyAttribute), false);
                if (attribs.Length == 0)
                {
                    continue;
                }
                ConfigPropertyAttribute attrib = (ConfigPropertyAttribute)attribs[0];
                f.SetValue(this, LoadConfigProperty(attrib));
            }
        }
Ejemplo n.º 6
0
        public void Save(string fileName, Type type)
        {
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap
            {
                ExeConfigFilename = fileName
            }, ConfigurationUserLevel.None);

            FieldInfo[] fields = type.GetFields();
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo f       = fields[i];
                object[]  attribs = f.GetCustomAttributes(typeof(ConfigPropertyAttribute), false);
                if (attribs.Length != 0)
                {
                    ConfigPropertyAttribute attrib = (ConfigPropertyAttribute)attribs[0];
                    config.AppSettings.Settings[attrib.Key].Value = f.GetValue(this).ToString();
                }
            }
            config.Save();
        }
Ejemplo n.º 7
0
 private object LoadConfigProperty(ConfigPropertyAttribute attrib)
 {
     string key = attrib.Key;
     string value = ConfigurationManager.AppSettings[key];
     if (value == null)
     {
         value = attrib.DefaultValue.ToString();
         log.Warn("Loading " + key + " value is null,using default vaule:"+value);
     }
     else
     {
         log.Debug("Loading " + key + " Value is " + value);
     }
     try
     {
         return Convert.ChangeType(value, attrib.DefaultValue.GetType());
     }
     catch (Exception e)
     {
         log.Error("Exception in ServerProperties Load: ", e);
         return null;
     }
 }
Ejemplo n.º 8
0
        private object LoadConfigProperty(ConfigPropertyAttribute attrib)
        {
            string key   = attrib.Key;
            string value = ConfigurationSettings.AppSettings[key];

            if (value == null)
            {
                value = attrib.DefaultValue.ToString();
                log.Warn("Loading " + key + " value is null,using default vaule:" + value);
            }
            else
            {
                log.Debug("Loading " + key + " Value is " + value);
            }
            try
            {
                return(Convert.ChangeType(value, attrib.DefaultValue.GetType()));
            }
            catch (Exception e)
            {
                log.Error("Exception in ServerProperties Load: ", e);
                return(null);
            }
        }
Ejemplo n.º 9
0
 private static object LoadProperty(ConfigPropertyAttribute attrib, ServiceBussiness sb)
 {
     String key = attrib.Key;
     ServerProperty property = sb.GetServerPropertyByKey(key);
     if (property == null)
     {
         property = new ServerProperty();
         property.Key = key;
         property.Value = attrib.DefaultValue.ToString();
         log.Error("Cannot find server property " + key + ",keep it default value!");
     }
     log.Debug("Loading " + key + " Value is " + property.Value);
     try
     {
         return Convert.ChangeType(property.Value, attrib.DefaultValue.GetType());
     }
     catch (Exception e)
     {
         log.Error("Exception in GameProperties Load: ", e);
         return null;
     }
 }
Ejemplo n.º 10
0
 private static void SaveProperty(ConfigPropertyAttribute attrib, ServiceBussiness sb,object value)
 {
     try
     {
         sb.UpdateServerPropertyByKey(attrib.Key, value.ToString());
     }
     catch (Exception ex)
     {
         log.Error("Exception in GameProperties Save: ", ex);
     }
 }