/// <summary> /// 用默认配置实例化一个数据库 /// </summary> public Common() { if (NowDataBase == null) { try { IKeelHack ik = KeelHackHelper.GetKeelHack(); try { NowDataBase = GetIDatabaseByNamespace(ik.DBProviderName, ik.DBConnectionString); } catch (Exception) { NowDataBase = null; } if (NowDataBase != null && NowDataBase.ConnectString == "NULL") { NowDataBase.ConnectString = Encoding.Default.GetString(Convert.FromBase64String(KeelHackHelper.ReadKeelHack("DBINFO"))); } if (NowDataBase == null) { NowDataBase = KeelHackHelper.ReadConnectionString(); } } catch (Exception) { NowDataBase = null; } } if (NowDataBase == null) { throw new DataBaseConnectionStringIsException(); } }
/// <summary> /// 读取默认的KeelHack实例 /// </summary> /// <returns></returns> public static IKeelHack GetKeelHack() { IKeelHack result = null; string ss = System.AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; ConfigXmlDocument cxd = new System.Configuration.ConfigXmlDocument(); cxd.Load(ss); string keelhackpath = System.AppDomain.CurrentDomain.SetupInformation.PrivateBinPath + "\\" + ReadConfig(cxd, "KeelHack"); if (System.IO.File.Exists(keelhackpath)) { Assembly asm = System.Reflection.Assembly.LoadFile(keelhackpath); Type t = asm.GetType("Keel.KeelHack", false, true); result = (IKeelHack)Activator.CreateInstance(t); } return(result); }