Beispiel #1
0
        private void OnDirectoryWatcherCreated(object sender, FileSystemEventArgs e)
        {
            mutex.WaitOne();
            string path  = e.FullPath;
            string name  = System.IO.Path.GetFileName(path);
            int    index = ExpectingDirectories.IndexOf(path);

            if (index >= 0)
            {
                ExpectingDirectories.RemoveAt(index);
                WatchedDirectories.Add(path);
                ItemAdded?.Invoke(this, new WatchingItemEventArgs(ItemType.Directory, path, name));
            }
            else
            {
                foreach (DirectoryScanOptions scanOptions in ScanOptions)
                {
                    if (scanOptions.IsIncluded(name, path, ItemType.Directory))
                    {
                        ItemAdded?.Invoke(this, new WatchingItemEventArgs(ItemType.Directory, path, name));
                        break;
                    }
                }
            }
            mutex.Set();
        }
Beispiel #2
0
        private void OnDirectoryWatcherRenamed(object sender, RenamedEventArgs e)
        {
            mutex.WaitOne();
            string removedPath = e.OldFullPath;
            string removedName = System.IO.Path.GetFileName(removedPath);
            string addedPath   = e.FullPath;
            string addedName   = System.IO.Path.GetFileName(addedPath);
            int    index       = WatchedFiles.IndexOf(removedPath);

            if (index >= 0)
            {
                WatchedDirectories.RemoveAt(index);
                ExpectingDirectories.Add(removedPath);
                ItemRemoved?.Invoke(this, new WatchingItemEventArgs(ItemType.Directory, removedPath, removedName));
            }
            else
            {
                foreach (DirectoryScanOptions scanOptions in ScanOptions)
                {
                    if (scanOptions.IsIncluded(removedName, removedPath, ItemType.Directory))
                    {
                        ItemRemoved?.Invoke(this, new WatchingItemEventArgs(ItemType.Directory, removedPath, removedName));
                        break;
                    }
                }
            }
            index = ExpectingDirectories.IndexOf(addedPath);
            if (index >= 0)
            {
                ExpectingDirectories.RemoveAt(index);
                WatchedDirectories.Add(addedPath);
                ItemAdded?.Invoke(this, new WatchingItemEventArgs(ItemType.Directory, addedPath, addedName));
            }
            else
            {
                foreach (DirectoryScanOptions scanOptions in ScanOptions)
                {
                    if (scanOptions.IsIncluded(addedName, addedPath, ItemType.Directory))
                    {
                        ItemAdded?.Invoke(this, new WatchingItemEventArgs(ItemType.Directory, addedPath, addedName));
                        break;
                    }
                }
            }
            mutex.Set();
        }