Beispiel #1
0
        private void scanDirectory(DirectoryEntry <Metadata> directory)
        {
            _scannedDirectory           = directory;
            _interruptScanningDirectory = false;

            var path = directory.GetPath();

            directory.Data.ResetScanningTime();

            try
            {
                scanDirectory(directory, path);
            }
            catch (DirectoryNotFoundException)
            {
                DirectoryScanNotFound?.Invoke(this, directory);
            }
            catch (SecurityException ex)
            {
                EntryAccessError?.Invoke(this, new EntryAccessError(EntryType.Directory, path, ex));
            }

            _scannedDirectory = null;
        }
Beispiel #2
0
        private void scanDirectory(DirectoryEntry <Metadata> directory, string path)
        {
            var directoryInfo = new DirectoryInfo(path);

            if (!directoryInfo.Exists)
            {
                DirectoryScanNotFound?.Invoke(this, directory);
                return;
            }

            directory.Data.BeginScan();
            DirectoryScanStarted?.Invoke(this, directory);

            // if other process removes the scanned directory, to this process the directory
            // remains existing and files and subdirectories enumeration continues normally

            foreach (var info in directoryInfo.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
            {
                if (_interruptScanningDirectory)
                {
                    break;
                }

                entryFound(new Find(EntryType.File, info.FullName));
            }

            if (_interruptScanningDirectory)
            {
                directory.Data.ResetScanningTime();
                DirectoryScanInterrupted?.Invoke(this, directory);
                return;
            }

            directoryInfo.Refresh();
            if (!directoryInfo.Exists)
            {
                directory.Data.ResetScanningTime();
                DirectoryScanNotFound?.Invoke(this, directory);
                return;
            }

            foreach (var info in directoryInfo.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
            {
                if (_interruptScanningDirectory)
                {
                    break;
                }

                entryFound(new Find(EntryType.Directory, info.FullName));
            }

            if (_interruptScanningDirectory)
            {
                directory.Data.ResetScanningTime();
                DirectoryScanInterrupted?.Invoke(this, directory);
                return;
            }

            directory.Data.EndScan();
            DirectoryScanFinished?.Invoke(this, directory);
        }