示例#1
0
 private void FileSystemWatcher_Created(object sender, FileSystemEventArgs e)
 {
     if (_filterRegex.IsMatch(e.FullPath))
     {
         Created?.Invoke(this, e);
     }
 }
示例#2
0
        //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);
        }
示例#3
0
        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;
        }
示例#4
0
        //-------------------------------------------------------------------------------------
        private void fileDeleted(object source, FileSystemEventArgs args)
        {
            if (!(source is System.IO.FileSystemWatcher))
            {
                return;
            }

            onFileDeleted?.Invoke(source as System.IO.FileSystemWatcher, args);
        }
示例#5
0
 private void InvokeAction(FileSystemEventArgs eventArgs)
 {
     try
     {
         _actionOnFolderCreated.Invoke(this, eventArgs);
     }
     catch (Exception)
     {
         // Suppress Exception
     }
 }
示例#6
0
        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;
        }
示例#7
0
        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;
            }
        }
示例#8
0
 protected void OnDeleted(FileSystemEventArgs e)
 {
     _onDeletedHandler?.Invoke(this, e);
 }
示例#9
0
        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);
        }