private static object LoadProperty(ConfigPropertyAttribute attrib, ServiceBussiness sb) { string key = attrib.Key; ServerProperty serverProperty = sb.GetServerPropertyByKey(key); if (serverProperty == null) { serverProperty = new ServerProperty(); serverProperty.Key = key; serverProperty.Value = attrib.DefaultValue.ToString(); GameProperties.log.Error("Cannot find server property " + key + ",keep it default value!"); } object result; try { result = Convert.ChangeType(serverProperty.Value, attrib.DefaultValue.GetType()); } catch (Exception exception) { GameProperties.log.Error("Exception in GameProperties Load: ", exception); result = null; } return(result); }
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); } }
/// <summary> /// get property name in db,it is declara with config attribute or property info name /// </summary> /// <param name="propertyInfo"></param> /// <returns></returns> private static string GetPropertyInfoStorageName(PropertyInfo propertyInfo) { //get storage name from static dic if (cacheDic.ContainsKey(propertyInfo.Name)) { return(cacheDic[propertyInfo.Name]); } //get storage name from config attribute var attrName = ConfigPropertyAttribute.GetName(propertyInfo); if (!string.IsNullOrEmpty(attrName)) { return(cacheDic[propertyInfo.Name] = attrName); } //get storage name from property info return(cacheDic[propertyInfo.Name] = propertyInfo.Name); }
private static void Load(Type type) { using (ServiceBussiness sb = new ServiceBussiness()) { foreach (FieldInfo fieldInfo in type.GetFields()) { if (fieldInfo.IsStatic) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(ConfigPropertyAttribute), false); if (customAttributes.Length != 0) { ConfigPropertyAttribute attrib = (ConfigPropertyAttribute)customAttributes[0]; fieldInfo.SetValue((object)null, GameProperties.LoadProperty(attrib, sb)); } } } } }
private static void Save(Type type) { using (ServiceBussiness sb = new ServiceBussiness()) { foreach (FieldInfo f in type.GetFields()) { if (!f.IsStatic) { continue; } object[] attribs = f.GetCustomAttributes(typeof(ConfigPropertyAttribute), false); if (attribs.Length == 0) { continue; } ConfigPropertyAttribute attrib = (ConfigPropertyAttribute)attribs[0]; SaveProperty(attrib, sb, f.GetValue(null)); } } }
private static void Save(Type type) { using (ServiceBussiness serviceBussiness = new ServiceBussiness()) { FieldInfo[] fields = type.GetFields(); for (int i = 0; i < fields.Length; i++) { FieldInfo fieldInfo = fields[i]; if (fieldInfo.IsStatic) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(ConfigPropertyAttribute), false); if (customAttributes.Length != 0) { ConfigPropertyAttribute attrib = (ConfigPropertyAttribute)customAttributes[0]; GameProperties.SaveProperty(attrib, serviceBussiness, fieldInfo.GetValue(null)); } } } } }
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); } }