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; } }
public ServerProperty GetServerPropertyByKey(string key) { ServerProperty serverProperty = null; SqlDataReader reader = null; try { SqlParameter[] para = new SqlParameter[1]; para[0] = new SqlParameter("@Key", key); db.GetReader(ref reader, "SP_Server_Config_Single",para); while (reader.Read()) { serverProperty = new ServerProperty(); serverProperty.Key = reader["Name"].ToString(); serverProperty.Value = reader["Value"].ToString(); } } catch (Exception e) { if (log.IsErrorEnabled) log.Error("GetServerConfig", e); } finally { if (reader != null && !reader.IsClosed) reader.Close(); } return serverProperty; }