/// <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> /// For now, we differentiate only boolean and string SPs /// </summary> /// <param name="this_sp"></param> /// <returns></returns> bool IsText(ServerProperty this_sp) { if (this_sp.DefaultValue.Trim().ToLower() == "true" || this_sp.DefaultValue.Trim().ToLower() == "false") return false; return true; }
/// <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); } }
/// <summary> /// Display the selected property /// </summary> /// <param name="spkey"></param> private void SelectProperty(string spkey) { // find the SP selected_sp = (ServerProperty)(from i in sp where i.Key == spkey.Split(Cte_sep)[0] select i).Single().Clone(); // combobox or textbox ? cb_spCurrentValue.Text = "False"; tb_spCurrentValue.Visible = false; cb_spCurrentValue.Visible = false; if (!IsText(selected_sp)) { if (selected_sp.Value.Trim().ToLower() == "true") cb_spCurrentValue.Text = "True"; cb_spCurrentValue.Visible = true; } else { tb_spCurrentValue.Text = selected_sp.Value; tb_spCurrentValue.Visible = true; } lbl_spName.Text = selected_sp.Key.ToUpper(); tb_spDesc.Text = selected_sp.Description; tb_spDefaultValue.Text = selected_sp.DefaultValue; selected_node = tv_spShow.SelectedNode; }