private static void FileReceivedHandler(Object o, FileSystemEventArgs arg) { lock (s_lock) { try { FileSystemWatcher watcher = (FileSystemWatcher)o; string fullFileName = ((FileSystemEventArgs)arg).FullPath; string filename = ((FileSystemEventArgs)arg).Name; string path = ((FileSystemEventArgs)arg).FullPath.Replace(@"\" + filename, String.Empty); log.InfoFormat("File received at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); //early return for hidden files if (File.Exists(fullFileName) && ( ((File.GetAttributes(fullFileName) & FileAttributes.Hidden) == FileAttributes.Hidden))) { log.InfoFormat("Bailing out on hidden file received at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); return; } foreach (WatchFolderDetails wDetails in FlatFileLoader.InstanceOf().filewatcherDetailsDictionary.Values) { DateTime earliestRundate = DateTime.MinValue; DateTime latestRundate = DateTime.MaxValue; ConfigUtils.GetInitialRunDateTime(wDetails, ref earliestRundate, ref latestRundate); if (wDetails.Path.Equals(path)) { if (wDetails.JobName.Equals("JobFolder") || DateTime.Now.CompareTo(earliestRundate) > 0 && DateTime.Now.CompareTo(latestRundate) < 0) { wDetails.FileName = filename; wDetails.HashCode = o.GetHashCode(); if (!wDetails.Filter.Equals(String.Empty)) { Regex rxInclusion = new Regex(wDetails.Filter); if (!rxInclusion.IsMatch(filename)) { log.InfoFormat("Bailing out on file filter inclusion at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); break; } } if (!wDetails.FilterExclude.Equals(String.Empty)) { Regex rxExclusion = new Regex(wDetails.FilterExclude); if (rxExclusion.IsMatch(filename)) { log.InfoFormat("Bailing out on file filter exclusion at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); break; } } FlatFileAdapterFactory factory = new FlatFileAdapterFactory(); DataSourceAdapter adapter = FlatFileAdapterFactory.GetAdapter(wDetails); AdapterLoader adapterLoader = new AdapterLoader(); ThreadPool.QueueUserWorkItem(new WaitCallback(adapterLoader.LoadAdapter), adapter); log.InfoFormat("File load started at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); } else log.WarnFormat("Skipping job; out of time range {0} [{1} - {2}]", wDetails.JobName, wDetails.EarliestRunTime, wDetails.LatestRunTime); } } } catch (Exception ex) { log.Error(ex); } } }
private int FileReceived(int watcherId, string fullFileName, string filename, string path) { //early return for hidden files if (File.Exists(fullFileName) && ( ((File.GetAttributes(fullFileName) & FileAttributes.Hidden) == FileAttributes.Hidden))) { log.InfoFormat("Bailing out on hidden file received at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); return -1; } foreach (WatchFolderDetails wDetails in FlatFileLoader.InstanceOf().filewatcherDetailsDictionary.Values) { DateTime earliestRundate = DateTime.MinValue; DateTime latestRundate = DateTime.MaxValue; ConfigUtils.GetInitialRunDateTime(wDetails, ref earliestRundate, ref latestRundate); string detailsPath = MetaTagReplacer.InlineMetatagSubstitution(wDetails.Path, GlobalConfig.GlobalParameters); if (detailsPath.Equals(path)) { if (wDetails.JobName.Equals("JobFolder") || DateTime.Now.CompareTo(earliestRundate) > 0 && DateTime.Now.CompareTo(latestRundate) < 0) { wDetails.FileName = filename; wDetails.HashCode = watcherId; if (!wDetails.Filter.Equals(String.Empty)) { Regex rxInclusion = new Regex(wDetails.Filter); if (!rxInclusion.IsMatch(filename)) { log.InfoFormat("Bailing out on file filter inclusion at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); break; } } if (!wDetails.FilterExclude.Equals(String.Empty)) { Regex rxExclusion = new Regex(wDetails.FilterExclude); if (rxExclusion.IsMatch(filename)) { log.InfoFormat("Bailing out on file filter exclusion at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); break; } } FlatFileAdapterFactory factory = new FlatFileAdapterFactory(); DataSourceAdapter adapter = FlatFileAdapterFactory.GetAdapter(wDetails); AdapterLoader adapterLoader = new AdapterLoader(); ThreadPool.QueueUserWorkItem(new WaitCallback(adapterLoader.LoadAdapter), adapter); log.InfoFormat("File load started at {0}: {1} in {2} ", DateTime.Now.ToString(), filename, path); } else log.WarnFormat("Skipping job; out of time range {0} [{1} - {2}]", wDetails.JobName, wDetails.EarliestRunTime, wDetails.LatestRunTime); } } return 0; }