Exemplo n.º 1
0
        private void OnFileWatcherDeleted(object sender, FileSystemEventArgs e)
        {
            mutex.WaitOne();
            string path  = e.FullPath;
            string name  = System.IO.Path.GetFileName(path);
            int    index = WatchedFiles.IndexOf(path);

            if (index >= 0)
            {
                WatchedFiles.RemoveAt(index);
                ExpectingFiles.Add(path);
                ItemRemoved?.Invoke(this, new WatchingItemEventArgs(ItemType.File, path, name));
            }
            else
            {
                foreach (DirectoryScanOptions scanOptions in ScanOptions)
                {
                    if (scanOptions.IsIncluded(name, path, ItemType.File))
                    {
                        ItemRemoved?.Invoke(this, new WatchingItemEventArgs(ItemType.File, path, name));
                        break;
                    }
                }
            }
            mutex.Set();
        }
Exemplo n.º 2
0
        private void OnFileWatcherRenamed(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)
            {
                WatchedFiles.RemoveAt(index);
                ExpectingFiles.Add(removedPath);
                ItemRemoved?.Invoke(this, new WatchingItemEventArgs(ItemType.File, removedPath, removedName));
            }
            else
            {
                foreach (DirectoryScanOptions scanOptions in ScanOptions)
                {
                    if (scanOptions.IsIncluded(removedName, removedPath, ItemType.File))
                    {
                        ItemRemoved?.Invoke(this, new WatchingItemEventArgs(ItemType.File, removedPath, removedName));
                        break;
                    }
                }
            }
            index = ExpectingFiles.IndexOf(addedPath);
            if (index >= 0)
            {
                ExpectingFiles.RemoveAt(index);
                WatchedFiles.Add(addedPath);
                ItemAdded?.Invoke(this, new WatchingItemEventArgs(ItemType.File, addedPath, addedName));
            }
            else
            {
                foreach (DirectoryScanOptions scanOptions in ScanOptions)
                {
                    if (scanOptions.IsIncluded(addedName, addedPath, ItemType.File))
                    {
                        ItemAdded?.Invoke(this, new WatchingItemEventArgs(ItemType.File, addedPath, addedName));
                        break;
                    }
                }
            }
            mutex.Set();
        }