public static IDBManager CreateDBManager(DbManagerConfig config) { IDBManager result = null; Type dbtype = Type.GetType(config.Type); if (dbtype == null) { throw new CacheDBException("{0} dbmanager type notfound!", config.Type); } Type formaterType = Type.GetType(config.Formater); if (formaterType == null) { throw new CacheDBException("{0} formater notfound!", config.Formater); } result = (IDBManager)Activator.CreateInstance(dbtype); result.Formater = (IFormater)Activator.CreateInstance(formaterType); foreach (PropertyConfig p in config.Properties) { PropertyInfo pi = dbtype.GetProperty(p.Name, BindingFlags.Public | BindingFlags.Instance); if (pi != null && pi.CanWrite) { try { pi.SetValue(result, Convert.ChangeType(p.Value, pi.PropertyType), null); } catch { } } } return(result); }
public static IDBManager CreateDBManager(DbManagerConfig config) { IDBManager result = null; Type dbtype = Type.GetType(config.Type); if (dbtype == null) throw new CacheDBException("{0} dbmanager type notfound!", config.Type); Type formaterType = Type.GetType(config.Formater); if (formaterType == null) throw new CacheDBException("{0} formater notfound!", config.Formater); result = (IDBManager)Activator.CreateInstance(dbtype); result.Formater = (IFormater)Activator.CreateInstance(formaterType); foreach (PropertyConfig p in config.Properties) { PropertyInfo pi = dbtype.GetProperty(p.Name, BindingFlags.Public | BindingFlags.Instance); if (pi != null && pi.CanWrite) { try { pi.SetValue(result, Convert.ChangeType(p.Value, pi.PropertyType), null); } catch { } } } return result; }
private static ICachedManager GetCachedManager(CacheDbSection section) { implement.CachedManager cm = new implement.CachedManager(); DbManagerConfig dbconfig = section.DbManager; cm.DBManager = CreateDBManager(dbconfig); foreach (LevelCachedConfig config in section.Levels) { cm.AddLevel(config.Name, config.Maximum, config.UpgradeValue); } foreach (PolicyConfig policy in section.Policies) { CreatePolicy(policy, cm); } cm.DBManager.Open(); return(cm); }