/// <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 ConfigurationWatcherTest() { //Assembly a = Assembly.GetExecutingAssembly(); //Uri uri = new System.Uri(a.CodeBase); //string binDirectory = Path.GetDirectoryName(uri.LocalPath); string fileName = "test.config"; // 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); }
public new ISqlMapper ConfigureAndWatch(string resource, ConfigureHandler configureDelegate) { XmlDocument document; if (resource.StartsWith("file://")) { document = Resources.GetUrlAsXmlDocument(resource.Remove(0, 7)); } else { document = Resources.GetResourceAsXmlDocument(resource); } ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch(Resources.GetFileInfo(resource)); TimerCallback onWhatchedFileChange = new TimerCallback(DomSqlMapBuilder.OnConfigFileChange); StateConfig state = default(StateConfig); state.FileName = resource; state.ConfigureHandler = configureDelegate; ISqlMapper result = this.Build(document, true); new ConfigWatcherHandler(onWhatchedFileChange, state); return(result); }
public void ConfigurationWatcherTest() { Assembly a = Assembly.GetExecutingAssembly(); Uri uri = new System.Uri(a.Location); string binDirectory = Path.GetDirectoryName(uri.LocalPath); string fileName = "test.config"; // Configure a watcher ConfigureHandler configureDelegate = new ConfigureHandler(Configure); ConfigWatcherHandler.ClearFilesMonitored(); ConfigWatcherHandler.AddFileToWatch(Resources.GetFileInfo(fileName)); TimerCallback callBakDelegate = new TimerCallback(ConfigWatcherTest.OnConfigFileChange); StateConfig state = new StateConfig(); state.FileName = fileName; state.ConfigureHandler = configureDelegate; new ConfigWatcherHandler(callBakDelegate, state); 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); }