/// <summary> /// This method loads the property from the database and returns /// the value of the property as strongly typed object based on the /// type of the default value /// </summary> /// <param name="attrib">The attribute</param> /// <returns>The real property value</returns> public static object Load(ServerPropertyAttribute attrib) { string key = attrib.Key; ServerProperty property = GameServer.Database.SelectObject<ServerProperty>("`Key` = '" + GameServer.Database.Escape(key) + "'"); if (property == null) { property = new ServerProperty(); property.Category = attrib.Category; property.Key = attrib.Key; property.Description = attrib.Description; property.DefaultValue = attrib.DefaultValue.ToString(); property.Value = attrib.DefaultValue.ToString(); GameServer.Database.AddObject(property); log.Debug("Cannot find server property " + key + " creating it"); } log.Debug("Loading " + key + " Value is " + property.Value); try { //we do this because we need "1.0" to be considered double sometimes its "1,0" in other countries CultureInfo myCIintl = new CultureInfo("en-US", false); IFormatProvider provider = myCIintl.NumberFormat; return Convert.ChangeType(property.Value, attrib.DefaultValue.GetType(), provider); } catch (Exception e) { log.Error("Exception in ServerProperties Load: ", e); log.Error("Trying to load " + key + " value is " + property.Value); return null; } }
/// <summary> /// This method loads the property from the database and returns /// the value of the property as strongly typed object based on the /// type of the default value /// </summary> /// <param name="attrib">The attribute</param> /// <returns>The real property value</returns> public static void Load(ServerPropertyAttribute attrib, FieldInfo field, ServerProperty prop) { string key = attrib.Key; // Not Added to database... if (!prop.IsPersisted) { GameServer.Database.AddObject(prop); log.DebugFormat("Cannot find server property {0} creating it", key); } log.DebugFormat("Loading {0} Value is {1}", key, prop.Value); try { if (field.IsInitOnly) log.WarnFormat("Property {0} is ReadOnly, Value won't be changed - {1} !", key, field.GetValue(null)); //we do this because we need "1.0" to be considered double sometimes its "1,0" in other countries CultureInfo myCIintl = new CultureInfo("en-US", false); IFormatProvider provider = myCIintl.NumberFormat; field.SetValue(null, Convert.ChangeType(prop.Value, attrib.DefaultValue.GetType(), provider)); } catch (Exception e) { log.ErrorFormat("Exception in ServerProperties Load: {0}", e); log.ErrorFormat("Trying to load {0} value is {1}", key, prop.Value); } }