public void Remove()
        {
            if (Keep || !_componentDirectory.Exists)
            {
                return;
            }

            try
            {
                StaticViewModel.AddDebugMessage($"Removing {_componentDirectory.FullName}");

                foreach (IFileInfo file in _componentDirectory.EnumerateFiles("*", SearchOption.AllDirectories))
                {
                    if (file.IsReadOnly)
                    {
                        file.IsReadOnly = false;
                    }
                }

                _componentDirectory.Delete(true);
            }
            catch (Exception ex)
            {
                StaticViewModel.AddDebugMessage(ex, $"Unable to delete {_componentDirectory.FullName}");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the current start index for indexed DB's
        /// </summary>
        /// <param name="path">Main path to DB directory.</param>
        /// <returns>Current - starting index of DB.</returns>
        private int GetStartingIndex(string path)
        {
            // gets path to non-index DB.
            string         fullPath  = _rocksDbFactory.GetFullDbPath(new RocksDbSettings(string.Empty, path));
            IDirectoryInfo directory = _fileSystem.DirectoryInfo.FromDirectoryName(fullPath);

            if (directory.Exists)
            {
                if (directory.EnumerateFiles().Any())
                {
                    return(-2); // if there are files in the directory, then we have a main DB, marked -2.
                }

                // else we have sub-directories, which should be index based
                // we want to find lowest positive index and return it - 1.
                int minIndex = directory.EnumerateDirectories()
                               .Select(d => int.TryParse(d.Name, out int index) ? index : -1)
                               .Where(i => i >= 0)
                               .OrderBy(i => i)
                               .FirstOrDefault();

                return(minIndex - 1);
            }

            return(-1); // if directory doesn't exist current index is -1.
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns all password files that match a search pattern.
        /// </summary>
        /// <param name="pattern">The pattern against which the files should be matched.</param>
        public IEnumerable <PasswordFile> GetPasswordFiles(string pattern)
        {
            var patternRegex = new Regex(pattern);

            var files         = passwordStore.EnumerateFiles("*", SearchOption.AllDirectories);
            var matchingFiles = files.Where(f => patternRegex.IsMatch(f.Name));
            var passwordFiles = matchingFiles.Select(CreatePasswordFile);

            return(passwordFiles);
        }
Ejemplo n.º 4
0
        private void ExtractArchivesInDir(IDirectoryInfo directory)
        {
            bool workDone = true;

            while (workDone)
            {
                workDone = directory.EnumerateFiles("*", SearchOption.AllDirectories)
                           .Select(fi => archiveHandler.TryExtractAndDelete(fi))
                           .Any(extracted => extracted == true);
            }
        }
Ejemplo n.º 5
0
        public override void SearchForDicomDirectories(string accessionsList)
        {
            Logger.Info("Starting accession directory path listing from: " + accessionsList);
            IsProcessing = true;
            TotalSent    = 0;

            using (StreamReader reader = FileSystem.File.OpenText(accessionsList))
            {
                while (!reader.EndOfStream && !TokenSource.IsCancellationRequested)
                {
                    string accessionDirectory = reader.ReadLine().Replace(",", "");

                    if (!_accDirectoryRegex.IsMatch(accessionDirectory))
                    {
                        Logger.Warn($"This path does not point to an accession directory: ({accessionDirectory}), continuing");
                        continue;
                    }

                    if (!FileSystem.Directory.Exists(accessionDirectory))
                    {
                        Logger.Warn($"Can not find {accessionDirectory}, continuing");
                        continue;
                    }

                    IDirectoryInfo          dirInfo = FileSystem.DirectoryInfo.FromDirectoryName(accessionDirectory);
                    IEnumerable <IFileInfo> fileEnumerator;

                    try
                    {
                        fileEnumerator = dirInfo.EnumerateFiles(SearchPattern);
                    }
                    catch (Exception e)
                    {
                        Logger.Error($"Could not enumerate files: {e.Message}");
                        continue;
                    }

                    if (fileEnumerator.FirstOrDefault() != null)
                    {
                        Logger.Debug("Sending message (" + accessionDirectory + ")");
                        FoundNewDicomDirectory(accessionDirectory.Remove(0, FileSystemRoot.Length));
                    }
                    else
                    {
                        Logger.Warn($"Could not find dicom files in the given accession directory ({accessionDirectory}), skipping");
                    }
                }
            }

            IsProcessing = false;

            Logger.Info("Reading from list finished");
            Logger.Info("Total messages sent: " + TotalSent);
        }
Ejemplo n.º 6
0
        public void TraverseDirectory(string dn, string rw)
        {
            IDirectoryInfo dirInfo = this.fileSystem.DirectoryInfo.FromDirectoryName(dn);

            foreach (IDirectoryInfo di in dirInfo.EnumerateDirectories())
            {
                Redactr r = new Redactr(this.fileSystem);
                r.TraverseDirectory(di.FullName, rw);
            }

            foreach (IFileInfo fi in dirInfo.EnumerateFiles())
            {
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    Redactor.Redact(new RedactData(this.fileSystem, fi.FullName, rw, '*'));
                }));
            }
        }
        private IEnumerable <DisplayComponentModel> GetDisplayComponentFolders(string installerRoot)
        {
            IDirectoryInfo installerRootDirectory = _fileSystem.DirectoryInfo.FromDirectoryName(installerRoot);

            if (!installerRootDirectory.Exists)
            {
                throw new DirectoryNotFoundException("Installer folder does not exist or cannot access.");
            }

            foreach (IFileInfo cccInstallFile in installerRootDirectory.EnumerateFiles("ccc2_install.exe", SearchOption.AllDirectories))
            {
                IDirectoryInfo displayDriverFolder = cccInstallFile.Directory.Parent;

                foreach (IDirectoryInfo componentDirectory in displayDriverFolder.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
                {
                    if (componentDirectory.GetFiles("*.inf", SearchOption.TopDirectoryOnly).Length == 1)
                    {
                        yield return(new DisplayComponentModel(installerRootDirectory, componentDirectory));
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private IFileInfo FindCoredumpOrNull(IDirectoryInfo directory)
 {
     return(directory.EnumerateFiles("*.core", SearchOption.AllDirectories).FirstOrDefault());
 }
        /// <summary>
        /// implementation of post-order traversal of directory tree
        /// it is done this way to guarantee that by the time we finish any directory
        /// all of its subdirectories/files had been visited
        /// Note:
        /// if operaiton is cancelled - not all notifications will be emited,
        /// and namespace information will be partial.
        /// </summary>
        /// <param name="root">directory to scan</param>
        /// <param name="cancelationCallback">function to consult with for cancelation</param>
        /// <exception cref="System.IO.DirectoryNotFoundException">Cannot access directory: {root.FullName}</exception>
        private void EnumeratePostOrderNonRecursive(IDirectoryInfo root, Func <bool> cancelationCallback = null)
        {
            // handle the case than this is actually network share.
            if (!root.Exists())
            {
                throw new System.IO.DirectoryNotFoundException(string.Format(StorageSyncResources.NamespaceEnumeratorErrorFormat, root.FullName));
            }

            _namespaceInfo = new NamespaceInfo
            {
                Path       = root.FullName,
                IsComplete = false
            };

            Stack <IDirectoryInfo> stack1 = new Stack <IDirectoryInfo>(5000);
            Stack <IDirectoryInfo> stack2 = new Stack <IDirectoryInfo>(5000);

            Func <bool> shouldCancel = () =>
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    return(false);
                }

                return(cancelationCallback == null ? false : cancelationCallback.Invoke());
            };

            stack1.Push(root);

            _namespaceInfo.NumberOfDirectories++;

            while (stack1.Count > 0)
            {
                if (shouldCancel())
                {
                    return;
                }

                IDirectoryInfo currentDirectory = stack1.Pop();

                stack2.Push(currentDirectory);

                // notify we have started processing directory
                // processing means accessing subdirectories and files
                NotifyBeginDir(currentDirectory);

                IList <IDirectoryInfo> subdirs = null;

                try
                {
                    subdirs = new List <IDirectoryInfo>(currentDirectory.EnumerateDirectories());
                }
                catch (UnauthorizedAccessException)
                {
                    NotifyUnauthorizedDir(currentDirectory);
                    continue;
                }

                NotifyNamespaceHints(subdirs.Count, 0);

                foreach (IDirectoryInfo subdir in subdirs)
                {
                    stack1.Push(subdir);
                    _namespaceInfo.NumberOfDirectories++;
                }
            }

            while (stack2.Count > 0)
            {
                if (shouldCancel())
                {
                    return;
                }

                IDirectoryInfo currentDirectory = stack2.Pop();

                IList <IFileInfo> files = new List <IFileInfo>(currentDirectory.EnumerateFiles());

                NotifyNamespaceHints(0, files.Count);

                foreach (IFileInfo file in files)
                {
                    _namespaceInfo.NumberOfFiles++;
                    _namespaceInfo.TotalFileSizeInBytes += file.Length;

                    NotifyNextFile(file);
                }

                // notify we have finished processing directory
                NotifyEndDir(currentDirectory);
            }

            _namespaceInfo.IsComplete = true;
        }
Ejemplo n.º 10
0
 protected virtual IEnumerable <IFileInfo> GetEnumerator(IDirectoryInfo dirInfo)
 {
     return(dirInfo.EnumerateFiles(SearchPattern));
 }
 /// <summary>
 /// Checks whether the directory contains the given file.
 /// </summary>
 /// <returns>True if the directory contains the file, false otherwise.</returns>
 internal static bool ContainsFile(this IDirectoryInfo directory, string name)
 {
     return(directory.EnumerateFiles(name).Any());
 }
Ejemplo n.º 12
0
 protected override IEnumerable <IFileInfo> GetEnumerator(IDirectoryInfo dirInfo)
 {
     return(dirInfo.EnumerateFiles().Where(f => f.Extension == ".dcm" || ZipHelper.IsZip(f)));
 }