public void StartWatching(Upload upload) { // only need to watch if the datasource is a spreadsheet if (upload.DataSourceType == DataSourceType.Spreadsheet) { // try and find an existing watcher FileWatchers result = _watcherList.Find( delegate(FileWatchers fw) { return fw.Upload == upload; } ); if (result == null) { // start new FileWatchers fw = new FileWatchers(); fw.FileWatcher = StartWatching(upload.DataSource); fw.Upload = upload; _watcherList.Add(fw); } else { // restart existing result.Upload = upload; result.FileWatcher.Dispose(); // releases any held resources from previous source result.FileWatcher.Path = upload.DataSource; // update if user has made changes result.FileWatcher.EnableRaisingEvents = true; } } }
public FileWatcher() { // list to store all fileWatchers for each upload _watcherList = new List<FileWatchers>(); // get all the directories that need to be watched ISession iSession = DBFactory.CreateNewSession(); IList<Upload> uploadList = DataLoader.GetSpreadSheetUploadList(iSession); iSession.Close(); foreach (Upload upload in uploadList) { if (upload.DataSource != null) { try { FileWatchers fw = new FileWatchers(); fw.FileWatcher = StartWatching(upload.DataSource); fw.Upload = upload; _watcherList.Add(fw); } catch { MessageBox.Show("The directory location path for " + upload.Name + " can not be found please check if the path name is correct.", "Spreadsheet directory path error"); } } } }