public void Monitoring() { PopulatingWatchingList(); _threadList = new List <BaseWatcher>(); Console.WriteLine("starting watchers......."); foreach (BaseWatchingObject watchingObject in _watchingList) { string watchType = watchingObject.GetWatchType(); BaseWatcher baseWatcher = MonitoringAux(watchType, watchingObject); _threadList.Add(baseWatcher); } foreach (BaseWatcher watcher in _threadList) { watcher.Start(); } Console.WriteLine("Press \'q\' to quite the program"); while (Console.Read() != 'q') { ; } foreach (BaseWatcher watcher in _threadList) { watcher.Finish(); } }
private BaseWatcher MonitoringAux(string watchType, BaseWatchingObject watchingObject) { BaseWatcher baseWatcher = null; switch (watchType) { case "file": WatchingFileObject watchingFileObject = (WatchingFileObject)watchingObject; string path = watchingFileObject.GetPath(); string fileName = watchingFileObject.GetFileName(); baseWatcher = new FileWatcher(watchingFileObject.GetWatchId(), path, "*." + watchingFileObject.GetFileType(), fileName, new FileInfo(path + "\\" + fileName).Length); if (fileName.Equals("watcher.config")) { ((FileWatcher)baseWatcher).ConfigFileUpdated += MainConfigFileUpdated; } break; case "database": WatchingDatabaseObject watchingDataObject = (WatchingDatabaseObject)watchingObject; baseWatcher = new DatabaseWatcher(watchingDataObject.GetWatchId(), watchingDataObject.GetDataSource(), watchingDataObject.GetDatabaseName(), watchingDataObject.GetUserId()); break; } return(baseWatcher); }
public void MainConfigFileUpdated(object sender, EventArgs e) { BaseWatchingObject watchingObejct = PopulatingWatchingListAux((XmlNode)sender); BaseWatcher baseWatcher = MonitoringAux(watchingObejct.GetWatchType(), watchingObejct); baseWatcher.Start(); Object locker = new Object(); lock (locker) { _threadList.Add(baseWatcher); } Console.WriteLine($"e type: {((FileSystemEventArgs)e).ChangeType}, Initiating one more watcher({watchingObejct.GetWatchType()})...."); }