public void ConfigurationWatcherTestOnSqlMapConfig() { //string fileName = @"..\..\Maps\MSSQL\SqlClient\Account.xml"; ConfigureHandler handler = new ConfigureHandler(MyHandler); DomSqlMapBuilder builder = new DomSqlMapBuilder(); NameValueCollection properties = new NameValueCollection(); properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test"); properties.Add("nullableInt", "int"); builder.Properties = properties; ISqlMapper mapper = builder.ConfigureAndWatch(_fileName, handler); // test that the mapper was correct build Assert.IsNotNull(mapper); FileInfo fi = Resources.GetFileInfo(_fileName); fi.LastWriteTime = DateTime.Now; fi.Refresh(); // Let's give a small bit of time for the change to propagate. // The ConfigWatcherHandler class has a timer which // waits for 500 Millis before delivering // the event notification. System.Threading.Thread.Sleep(600); Assert.IsTrue(_hasChanged); _hasChanged = false; }
protected static ISqlMapper InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); return(builder.Configure()); }
protected void InitMapper(string databaseName) { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); _mapper[databaseName] = builder.ConfigureAndWatch(databaseName, handler); }
public static ServiceConfig GetInstance() { if (_instance == null) { lock (_synRoot) { if (_instance == null) { try { ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset); DomDaoManagerBuilder builder = new DomDaoManagerBuilder(); builder.ConfigureAndWatch("dao.config", handler); } catch (Exception ex) { throw ex; } _instance = new ServiceConfig(); // TODO:默认为sqlMapDao指定的Context, 要提供对多个Context的支持. _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao"); } } } return _instance; }
/// <summary> /// 实现IBatis接口 /// </summary> /// <param name="connectConfig"></param> protected static ISqlMapper InitMapper(string sqlMapConfig) { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); ISqlMapper mp = null; try { if (_mappers.ContainsKey(sqlMapConfig)) { mp = _mappers[sqlMapConfig]; } else { mp = builder.ConfigureAndWatch(sqlMapConfig, handler); _mappers.Add(sqlMapConfig, mp); } } catch (System.Exception e) { Logger.Error(e.StackTrace); return(null); //logger.Exception(e.Message, e); } return(mp); }
protected static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); _mapper = builder.ConfigureAndWatch(handler); }
/// <summary> /// Init the 'default' SqlMapper defined by the SqlMap.Config file. /// </summary> public static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); _mapper = builder.ConfigureAndWatch("NurDocMapper.config", handler); }
/// <summary> /// Configure and monitor the configuration file for modifications and /// automatically reconfigure /// </summary> /// <param name="resource"> /// A relative ressource path from your Application root /// or an absolue file path file://c:\dir\a.config /// </param> ///<param name="configureDelegate"> /// Delegate called when the file has changed, to rebuild the dal. /// </param> public void ConfigureAndWatch(string resource, ConfigureHandler configureDelegate) { XmlDocument document = null; if (resource.StartsWith("file://")) { document = Resources.GetUrlAsXmlDocument(resource.Remove(0, 7)); } else { document = Resources.GetResourceAsXmlDocument(resource); } ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch(Resources.GetFileInfo(resource)); BuildDaoManagers(document, true); TimerCallback callBakDelegate = new TimerCallback(DomDaoManagerBuilder.OnConfigFileChange); StateConfig state = new StateConfig(); state.FileName = resource; state.ConfigureHandler = configureDelegate; new ConfigWatcherHandler(callBakDelegate, state); }
static public ServiceConfig GetInstance() { if (_instance == null) { lock (_synRoot) { if (_instance == null) { try { ConfigureHandler _handler = new ConfigureHandler(ServiceConfig.Reset); DomDaoManagerBuilder _builder = new DomDaoManagerBuilder(); //_builder.Configure(); _builder.ConfigureAndWatch("dao.config", _handler); _instance = new ServiceConfig(); _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao"); } catch (Exception e) { LogHelper.Error(e.Message); } } } } return(_instance); }
static public ServiceConfig GetInstance() { if (_instance == null) { lock (_synRoot) { if (_instance == null) { try { ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset); DomDaoManagerBuilder builder = new DomDaoManagerBuilder(); builder.ConfigureAndWatch("dao.config", handler); } catch (Exception ex) { throw ex; } _instance = new ServiceConfig(); // TODO:默认为sqlMapDao指定的Context, 要提供对多个Context的支持. _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao"); } } } return(_instance); }
protected static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); mapper = builder.ConfigureAndWatch(handler); }
public static void writeDefaultConfiguration() { ConfigureHandler.WriteIniData("Default", "IP", "127.0.0.1"); ConfigureHandler.WriteIniData("Default", "Port", Convert.ToString(82)); ConfigureHandler.WriteIniData("Default", "MaxClientCount", Convert.ToString(10)); ConfigureHandler.WriteIniData("Default", "DataBase", "SKY-LAPTOP\\SQLEXPRESS"); ConfigureHandler.WriteIniData("Default", "Home", @"D:\RemoteDiskServer\"); }
protected static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); _mapper = builder.ConfigureAndWatch("sqlmap.config", handler); _mapper.SessionStore = new HybridWebThreadSessionStore(_mapper.Id); }
public static void loadDefaultConfiguration() { HostIp = ConfigureHandler.ReadIniData("Default", "IP"); Port = Convert.ToInt32(ConfigureHandler.ReadIniData("Default", "Port")); maxClientCount = Convert.ToInt32(ConfigureHandler.ReadIniData("Default", "MaxClientCount")); dataBase = ConfigureHandler.ReadIniData("Default", "DataBase"); connectString = "Data Source = " + dataBase + ";Initial Catalog = db_remoteDisk;Trusted_Connection = yes;Integrated Security = true"; homePath = ConfigureHandler.ReadIniData("Default", "Home"); }
protected static ISqlMapper InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); XmlDocument doc = GetConfig(); return(builder.Configure(doc)); }
public void InitMapper(string sqlMapperPath) { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); //设置文件缓存依赖,每当sqlMapperPath指向的配置文件被修改,就调用handler,即Configure方法将实例置为null,再重新获取 _mapper = builder.ConfigureAndWatch(sqlMapperPath, handler); _mapper.SessionStore = new IBatisNet.DataMapper.SessionStore.HybridWebThreadSessionStore(_mapper.Id); }
public static void InitMapper() { string configPath = GetConfigPath(); ConfigureHandler hanlder = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); mapper = builder.ConfigureAndWatch(configPath, hanlder); }
private static void BuildingMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); _mapper = builder.ConfigureAndWatch(Path, handler); CallContextSessionStore ss = new CallContextSessionStore(_mapper.Id); _mapper.SessionStore = ss; }
protected static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); /* XmlDocument sqlMapConfig = Resources.GetEmbeddedResourceAsXmlDocument("MamShare.Persistence.Config.SqlMap.config, MamShare.Persistence"); _mapper = builder.Configure(sqlMapConfig); */ _mapper = builder.ConfigureAndWatch("SqlMap.config",handler); }
protected static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); XmlDocument doc = GetConfig(); _mapper = builder.Configure(doc); //_mapper = builder.ConfigureAndWatch(path, handler); }
public ISqlMapper GetLocalSqlMap() { if (sqlMap == null) { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); sqlMap = builder.ConfigureAndWatch(fileName, handler); sqlMap.SessionStore = new HybridWebThreadSessionStore(sqlMap.Id); } return(sqlMap); }
protected static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); /* * XmlDocument sqlMapConfig = Resources.GetEmbeddedResourceAsXmlDocument("MamShare.Persistence.Config.SqlMap.config, MamShare.Persistence"); * _mapper = builder.Configure(sqlMapConfig); */ _mapper = builder.ConfigureAndWatch("SqlMap.config", handler); }
private void btnOK_Click(object sender, EventArgs e) { IP = txtBoxIP.Text.Trim(); Port = txtBoxPort.Text.Trim(); HomePath = txtBoxHome.Text.Trim(); ConfigureHandler.WriteIniData("Configuration", "IP", IP); ConfigureHandler.WriteIniData("Configuration", "Port", Port); ConfigureHandler.WriteIniData("Configuration", "Home", HomePath); CommonStaticVariables.loadConfiguration(); this.Close(); }
/// <summary> /// 请不要使用此方法,下个版本将移除 /// 解决多线程问题请使用ModeBaseDao类 /// </summary> /// <returns></returns> public ISqlMapper GetSqlMap2() { if (sqlMap2 == null) { ConfigureHandler handler = new ConfigureHandler(Configure2); DomSqlMapBuilder builder = new DomSqlMapBuilder(); sqlMap2 = builder.ConfigureAndWatch(fileName2, handler); sqlMap2.SessionStore = new HybridWebThreadSessionStore(sqlMap2.Id); } return(sqlMap2); }
/// <summary> /// Init the 'default' SqlMapper defined by the SqlMap.Config file. /// </summary> protected static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); string resourceDirectory = ConfigurationManager.AppSettings.Get("sqlmapconfig"); string resource = InitMapXML(resourceDirectory); InitMapXML(resourceDirectory); ISqlMapper sqlmapper = builder.ConfigureAndWatch(resource, handler); _Mapper = sqlmapper; }
/// <summary> /// 针对视图查询使用 /// </summary> /// <returns></returns> protected static void NewInitMapper(string path) { XmlDocument XD = readdatabase(path); ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); //_mapper = builder.ConfigureAndWatch(DefaultConfig.LISMap, handler); _newmapper = builder.Configure(XD); //连接串解密 // _mapper.DataSource.ConnectionString = _mapper.DataSource.ConnectionString.Replace(conn, new DESEncrypt().Decrypt(conn.Trim(), key)); // _mapper.DataSource.ConnectionString = info.Connectionstring; }
/// <summary> /// Initialize an sqlMap /// </summary> protected static void InitSqlMap() { //DateTime start = DateTime.Now; ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); sqlMap = builder.ConfigureAndWatch("sqlmap" + "_" + Configuration["database"] + "_" + Configuration["providerType"] + ".config", handler); //string loadTime = DateTime.Now.Subtract(start).ToString(); //Console.WriteLine("Loading configuration time :"+loadTime); }
protected static void InitMapper(cPos.Model.LoggingManager loggingManager) { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); _mapper = builder.ConfigureAndWatch("Sql2010SqlMap.config", handler); if (loggingManager.Customer_Id != null) { CustomerID = loggingManager.Customer_Id; string customer_connection_str = loggingManager.Connection_String.ToString(); _mapper.DataSource.ConnectionString = customer_connection_str; } }
/// <summary> /// 实例化SqlMapper /// </summary> /// <param name="configUrl"></param> protected static void InitMapper(string configUrl) { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); try { ISqlMapper mapper = builder.ConfigureAndWatch(configUrl, handler); m_ISqlMappers.Add(configUrl, mapper); } catch (Exception ex) { throw ex; } }
private void btnOK_Click(object sender, EventArgs e) { IP = txtBoxIP.Text.Trim(); Port = txtBoxPort.Text.Trim(); MaxClientCount = txtBoxMaxClientCount.Text.Trim(); DataBase = txtBoxDataBase.Text.Trim(); HomePath = txtBoxHome.Text.Trim(); ConfigureHandler.WriteIniData("Configuration", "IP", IP); ConfigureHandler.WriteIniData("Configuration", "Port", Port); ConfigureHandler.WriteIniData("Configuration", "MaxClientCount", MaxClientCount); ConfigureHandler.WriteIniData("Configuration", "DataBase", DataBase); ConfigureHandler.WriteIniData("Configuration", "Home", HomePath); CommonStaticVariables.loadConfiguration(); MessageBox.Show("配置成功!\n下次启动机器时生效!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
//protected static void InitMapper() //{ // ConfigureHandler handler = new ConfigureHandler(Configure); // DomSqlMapBuilder builder = new DomSqlMapBuilder(); // _mapper = builder.ConfigureAndWatch("Sql2010SqlMap.config", handler); //} protected static void InitMapper() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); //#if DEBUG _mapper = builder.ConfigureAndWatch("Sql2010SqlMap.config", handler); //#else //string fileMap = HttpContext.Current.Server.MapPath("..\\mssqlmap.dat"); //if (!File.Exists(fileMap)) //{ // throw new FileNotFoundException("mssqlmap.dat"); //} //string fileKey = HttpContext.Current.Server.MapPath("..\\keys\\apself.key"); //if (!File.Exists(fileKey)) //{ // throw new FileNotFoundException("apself.key"); //} //byte[] keys, iv; //bool k_ret = CryptKeyManager.GetCryptKeyAndIV(fileKey, out keys, out iv); //if (!k_ret) //{ // throw new Exception("密钥文件错误!"); //} //StreamReader tr = new StreamReader(fileMap, Encoding.UTF8); //string input = tr.ReadToEnd(); //tr.Close(); //string output = DecryptManager.Decrypt(input, keys, iv, CryptProviderType.TripleDES); //System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //doc.LoadXml(output); //_mapper = builder.Configure(doc); //#endif //取客户的专用连接串 //#if DEBUG //#else //if (HttpContext.Current.Session[KEY_CUSTOMER_ID] != null) //{ //string customer_id = HttpContext.Current.Session[SessionManager.KEY_CUSTOMER_ID].ToString(); //string customer_connection_str = HttpContext.Current.Session[customer_id].ToString(); //_mapper.DataSource.ConnectionString = customer_connection_str; //} RefreshMapperDataSource(null); //#endif }
/// <summary> /// ConfigurationWatcher Test /// </summary> [Test] public void ConfigurationWatcherTest() { //Assembly a = Assembly.GetExecutingAssembly(); //Uri uri = new System.Uri(a.CodeBase); //string binDirectory = Path.GetDirectoryName(uri.LocalPath); string fileName = "test.config"; FileInfo fi = new FileInfo(fileName); if (!fi.Exists) { using (FileStream fs = fi.Create()); } // Configure a watcher ConfigureHandler configureDelegate = new ConfigureHandler(Configure); ConfigWatcherHandler.ClearFilesMonitored(); CustomUriBuilder builder = new CustomUriBuilder(fileName, AppDomain.CurrentDomain.BaseDirectory); IResource resource = new FileResource(builder.Uri); ConfigWatcherHandler.AddFileToWatch(resource.FileInfo); TimerCallback callBakDelegate = new TimerCallback(ConfigWatcherTest.OnConfigFileChange); StateConfig state = new StateConfig(); state.FileName = fileName; state.ConfigureHandler = configureDelegate; new ConfigWatcherHandler(callBakDelegate, state); resource.FileInfo.LastWriteTime = DateTime.Now; resource.FileInfo.Refresh(); // Let's give a small bit of time for the change to propagate. // The ConfigWatcherHandler class has a timer which // waits for 500 Millis before delivering // the event notification. System.Threading.Thread.Sleep(600); Assert.IsTrue(_hasChanged); }
/// <summary> /// Initialize an sqlMap /// </summary> protected static void InitSqlMap() { //DateTime start = DateTime.Now; ConfigureHandler handler = new ConfigureHandler( Configure ); DomSqlMapBuilder builder = new DomSqlMapBuilder(); #if dotnet2 sqlMap = builder.ConfigureAndWatch("sqlmap" + "_" + ConfigurationManager.AppSettings["database"] + "_" + ConfigurationManager.AppSettings["providerType"] + ".config", handler); #else sqlMap = builder.ConfigureAndWatch( "sqlmap"+ "_" + ConfigurationSettings.AppSettings["database"] + "_" + ConfigurationSettings.AppSettings["providerType"] +".config", handler ); #endif //string loadTime = DateTime.Now.Subtract(start).ToString(); //Console.WriteLine("Loading configuration time :"+loadTime); }
public void TestConfigureAndWatchRelativePathViaBuilder() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); NameValueCollection properties = new NameValueCollection(); properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test"); properties.Add("nullableInt", "int"); ChildSetupProperties(properties); builder.Properties = properties; ISqlMapper mapper = builder.ConfigureAndWatch(_fileName, handler); Assert.IsNotNull(mapper); }
/// <summary> /// Configure and monitor the configuration file for modifications /// and automatically reconfigure SqlMap. /// </summary> /// <param name="resource"> /// A FileInfo to your config file. /// </param> ///<param name="configureDelegate"> /// Delegate called when the file has changed, to rebuild the dal. /// </param> /// <returns>An SqlMap</returns> public void ConfigureAndWatch(FileInfo resource, ConfigureHandler configureDelegate) { XmlDocument document = Resources.GetFileInfoAsXmlDocument(resource); ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch(resource); BuildDaoManagers(document, true); TimerCallback callBakDelegate = new TimerCallback(DomDaoManagerBuilder.OnConfigFileChange); StateConfig state = new StateConfig(); state.FileName = resource.FullName; state.ConfigureHandler = configureDelegate; new ConfigWatcherHandler(callBakDelegate, state); }
public void TestConfigureAndWatchAbsolutePathWithFileSuffixViaBuilder() { _fileName = "file://" + Resources.BaseDirectory + Path.DirectorySeparatorChar + _fileName; ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); NameValueCollection properties = new NameValueCollection(); properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test"); properties.Add("nullableInt", "int"); ChildSetupProperties(properties); builder.Properties = properties; ISqlMapper mapper = builder.ConfigureAndWatch(_fileName, handler); Assert.IsNotNull(mapper); }
public static ServiceConfig GetInstance() { if (_instance == null) { lock (_synRoot) { if (_instance == null) { ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset); DomDaoManagerBuilder builder = new DomDaoManagerBuilder(); builder.ConfigureAndWatch("dao.config", handler); _instance = new ServiceConfig(); // TODO:Ĭ��ΪsqlMapDaoָ����Context, Ҫ�ṩ�Զ��Context��֧��. _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao"); } } } return _instance; }
/// <summary> /// Configure and monitor the configuration file for modifications /// and automatically reconfigure the ISqlMapper instance. /// </summary> /// <param name="resource"> /// A FileInfo to a SqlMap.config file. /// </param> ///<param name="configureDelegate"> /// Delegate called when the file has changed. /// </param> /// <returns>An ISqlMapper instance.</returns> public ISqlMapper ConfigureAndWatch( FileInfo resource, ConfigureHandler configureDelegate ) { XmlDocument document = Resources.GetFileInfoAsXmlDocument(resource); ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch( resource ); TimerCallback callBakDelegate = new TimerCallback( OnConfigFileChange ); StateConfig state = new StateConfig(); state.FileName = resource.FullName; state.ConfigureHandler = configureDelegate; ISqlMapper sqlMapper = Build( document, true ); new ConfigWatcherHandler(callBakDelegate, state); return sqlMapper; }
public static void ConfigureAndWatch(string resource, ConfigureHandler configureDelegate) { ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch( Resources.GetFileInfo( resource ) ); XmlDocument document = Resources.GetConfigAsXmlDocument( resource ); new DomDaoManagerBuilder().BuildDaoManagers( document, true ); TimerCallback callBackDelegate = new TimerCallback( DomDaoManagerBuilder.OnConfigFileChange ); StateConfig state = new StateConfig(); state.FileName = resource; state.ConfigureHandler = configureDelegate; new ConfigWatcherHandler( callBackDelegate, state ); }
public void TestConfigureAndWatchAbsolutePathWithFileSuffixViaBuilder() { _fileName = "file://"+Resources.BaseDirectory+Path.DirectorySeparatorChar+_fileName; ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); NameValueCollection properties = new NameValueCollection(); properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test"); properties.Add("nullableInt", "int"); builder.Properties = properties; ISqlMapper mapper = builder.ConfigureAndWatch(_fileName, handler); Assert.IsNotNull(mapper); }
public void TestConfigureAndWatchRelativePathViaBuilder() { ConfigureHandler handler = new ConfigureHandler(Configure); DomSqlMapBuilder builder = new DomSqlMapBuilder(); NameValueCollection properties = new NameValueCollection(); properties.Add("collection2Namespace", "IBatisNet.DataMapper.Test.Domain.LineItemCollection, IBatisNet.DataMapper.Test"); properties.Add("nullableInt", "int"); builder.Properties = properties; ISqlMapper mapper = builder.ConfigureAndWatch(_fileName, handler); Assert.IsNotNull(mapper); }
public static void ConfigureAndWatch(ConfigureHandler configureDelegate) { ConfigureAndWatch( DomDaoManagerBuilder.DEFAULT_FILE_CONFIG_NAME, configureDelegate ); }
/// <summary> /// 获取数据链接配置 /// </summary> /// <param name="daoid">数据链接配置ID</param> /// <returns></returns> public static ServiceConfig GetInstance(string daoid) { if (_instance == null) { lock (_synRoot) { if (_instance == null) { string[] str = projectlist.Split(','); //生成配置文件SqlServerMap.config string name = "SqlServerMap"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fileName + name + "Pub.config"); XmlNode sqlMapConfig = xmlDoc.DocumentElement;//获取节点 XmlNodeList sqlMapList = sqlMapConfig.ChildNodes;//获取所有字节点 foreach (XmlNode child in sqlMapList) { if (child.Name.Equals("sqlMaps")) { foreach (string st in str) { if (File.Exists(fileName + st + "Map.config")) { XmlDocument xmlDocOA = new XmlDocument(); xmlDocOA.Load(fileName + st + "Map.config"); XmlNode sqlMapConfigOA = xmlDocOA.DocumentElement;//获取节点 XmlNode sqlMapsOA = sqlMapConfigOA.FirstChild; XmlNodeList courseNodeList = sqlMapsOA.ChildNodes; if (courseNodeList != null) { foreach (XmlNode courseNode in courseNodeList) { if (courseNode.Attributes != null) { string value = courseNode.Attributes.GetNamedItem("resource").Value; XmlNode newNode = xmlDoc.CreateElement("sqlMap", xmlDoc.DocumentElement.NamespaceURI); CreateAttribute(newNode, "resource", value); child.AppendChild(newNode); } } } } } break; } } xmlDoc.Save(fileName + name + ".config"); ConfigureHandler handler = new ConfigureHandler(ServiceConfig.Reset); DomDaoManagerBuilder builder = new DomDaoManagerBuilder(); builder.ConfigureAndWatch("Config/dao.config", handler); _instance = new ServiceConfig(); //清空数据库连接键值列表 daoManageKeyList = null; } } } if (daoManageKeyList == null || !daoManageKeyList.Contains(daoid)) { lock (_synRoot) { if (daoManageKeyList == null || !daoManageKeyList.Contains(daoid)) { // TODO:默认为sqlMapDao指定的Context, 要提供对多个Context的支持. _instance._daoManager = IBatisNet.DataAccess.DaoManager.GetInstance(daoid); } } } return _instance; }
/// <summary> /// Configure and monitor the default configuration file (SqlMap.config) for modifications /// and automatically reconfigure SqlMap. /// </summary> /// <returns>An ISqlMapper instance.</returns> public ISqlMapper ConfigureAndWatch(ConfigureHandler configureDelegate) { return ConfigureAndWatch( DEFAULT_FILE_CONFIG_NAME, configureDelegate ) ; }
/// <summary> /// Configure and monitor the configuration file for modifications /// and automatically reconfigure the ISqlMapper instance. /// </summary> /// <param name="resource"> /// A relative ressource path from your Application root /// or an absolue file path file:\\c:\dir\a.config /// </param> ///<param name="configureDelegate"> /// Delegate called when the file has changed. /// </param> /// <returns>An ISqlMapper instance.</returns> public ISqlMapper ConfigureAndWatch( string resource, ConfigureHandler configureDelegate ) { XmlDocument document = null; if (resource.StartsWith("file://")) { document = Resources.GetUrlAsXmlDocument( resource.Remove(0, 7) ); } else { document = Resources.GetResourceAsXmlDocument( resource ); } ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch( Resources.GetFileInfo( resource ) ); TimerCallback callBakDelegate = new TimerCallback( OnConfigFileChange ); StateConfig state = new StateConfig(); state.FileName = resource; state.ConfigureHandler = configureDelegate; ISqlMapper sqlMapper = Build( document, true ); new ConfigWatcherHandler( callBakDelegate, state ); return sqlMapper; }