private void FileSystemWatcher_Created(object sender, FileSystemEventArgs e) { if (_filterRegex.IsMatch(e.FullPath)) { Created?.Invoke(this, e); } }
//TODO: Watch subfolders public IEnumerable <FileSystemWatcher> WatchSpecificFolder(string folder, bool invokeAfterCreation) { var watchers = new List <FileSystemWatcher>(); var dirInfo = new System.IO.DirectoryInfo(folder); var watchDir = dirInfo.FullName; LogInfo($"Watching folder: {watchDir}"); System.IO.FileSystemWatcher fsw = new FileSystemWatcher(watchDir); fsw.EnableRaisingEvents = true; FileSystemEventHandler fswChanged = (sender, e) => { LogSuccess($"{DateTime.Now.ToString("HH:mm:ss")}: Detected change {e.ChangeType} @ {e.FullPath} ({e.Name}"); _merger.MergePuzzleFiles(); //Merging all puzzles Console.Beep(); }; fsw.Changed += fswChanged; if (invokeAfterCreation) { LogInfo("Starting initial merge"); fswChanged.Invoke(this, new FileSystemEventArgs(WatcherChangeTypes.Changed, _sourcePath, "./")); } watchers.Add(fsw); //Check if we need to query subdirectories (for puzzles split in separate files) var subDirs = dirInfo.GetDirectories(); foreach (var subDir in subDirs) { watchers.AddRange(WatchSpecificFolder(subDir.FullName, false)); } return(watchers); }
public static void UnsetListeners(this FileSystemWatcher watcher, FileSystemEventHandler handler) { void renamedHandler(object o, RenamedEventArgs args) => handler.Invoke(o, args); watcher.Created -= handler; watcher.Changed -= handler; watcher.Renamed -= renamedHandler; watcher.Deleted -= handler; }
//------------------------------------------------------------------------------------- private void fileDeleted(object source, FileSystemEventArgs args) { if (!(source is System.IO.FileSystemWatcher)) { return; } onFileDeleted?.Invoke(source as System.IO.FileSystemWatcher, args); }
private void InvokeAction(FileSystemEventArgs eventArgs) { try { _actionOnFolderCreated.Invoke(this, eventArgs); } catch (Exception) { // Suppress Exception } }
void SafeEventHandle(FileSystemEventHandler pluginEvent, object sender, FileSystemEventArgs e) { if (pluginEvent == null) { return; } // Hack to avoid handling multiple events. More on: // http://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice _fileSystemWatcher.EnableRaisingEvents = false; pluginEvent.Invoke(sender, e); _fileSystemWatcher.EnableRaisingEvents = true; }
private void OnChanged(object source, FileSystemEventArgs e) { FileSystemWatcher watcher = source as FileSystemWatcher; DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath); if (lastWriteTime != lastRead) { if (onChangedEventHandler != null) { onChangedEventHandler.Invoke(source, e); } lastRead = lastWriteTime; } }
protected void OnDeleted(FileSystemEventArgs e) { _onDeletedHandler?.Invoke(this, e); }
void SafeEventHandle( FileSystemEventHandler pluginEvent, object sender, FileSystemEventArgs e ) { if ( pluginEvent == null ) return; // Hack to avoid handling multiple events. More on: // http://stackoverflow.com/questions/1764809/filesystemwatcher-changed-event-is-raised-twice _fileSystemWatcher.EnableRaisingEvents = false; pluginEvent.Invoke( sender, e ); _fileSystemWatcher.EnableRaisingEvents = true; }
protected void OnDeleted(object sender, FileSystemEventArgs args) { FileSystemEventHandler onDeleted = Deleted; onDeleted?.Invoke(sender, args); }