示例#1
0
 public FileWalkerTests()
 {
     _compareService    = Substitute.For <ICompareService>();
     _configService     = Substitute.For <IConfigService>();
     _fileSystemService = Substitute.For <IFileSystemService>();
     _fileWalker        = new FileWalker(_compareService, _configService, _fileSystemService);
 }
示例#2
0
        private async Task processImageFiles(string rootPath, string outputPath)
        {
            string[] extensionsToMatch = { "*.jpg", "*.jpeg", "*.png", "*.gif", "*.bmp", "*.pdf" };
            await Task.Run(async() => {
                FileAttributes attr = File.GetAttributes(rootPath);

                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (!outputPath.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                    {
                        outputPath += System.IO.Path.DirectorySeparatorChar;
                    }

                    List <string> matchingFiles = FileWalker.WalkDir(rootPath, extensionsToMatch, true);
                    foreach (var filename in matchingFiles)
                    {
                        string nwFilename = filename.Replace(rootPath, outputPath);

                        processSingleImageFile(filename, nwFilename);
                    }
                }
                else
                {
                    string nwFilename = rootPath.Replace(rootPath, outputPath);
                    processSingleImageFile(rootPath, nwFilename);
                }
            });
        }
        private async Task processOfficeFiles(string rootPath, string outputPath, string[] filePatterns)
        {
            // TODO: refactor so all background work is done in one thread instead of multiple async methods-->
            await Task.Run(async() =>
            {
                FileAttributes attr = File.GetAttributes(rootPath);

                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (!outputPath.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                    {
                        outputPath += System.IO.Path.DirectorySeparatorChar;
                    }

                    List <string> matchingFiles = FileWalker.WalkDir(rootPath, filePatterns, true);

                    foreach (var filename in matchingFiles)
                    {
                        Output.AddJournalEntry($"Found matching file: {filename}");

                        string nwFilename = filename.Replace(rootPath, outputPath) + ".pdf";
                        processSingleOfficeFile(filename, nwFilename);
                    }
                }
                else
                {
                    Output.AddJournalEntry($"Processing single file: {rootPath}");
                    string nwFilename = rootPath.Replace(rootPath, outputPath) + ".pdf";
                    processSingleOfficeFile(rootPath, nwFilename);
                }
            });
        }
示例#4
0
        private async Task processMsgFiles(string rootPath, string outputPath)
        {
            await Task.Run(async() => {
                FileAttributes attr = File.GetAttributes(rootPath);

                if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (!outputPath.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
                    {
                        outputPath += System.IO.Path.DirectorySeparatorChar;
                    }

                    List <string> matchingFiles = FileWalker.WalkDir(rootPath, Util.FileExtensions[FileType.OUTLOOK_MSG], true);
                    foreach (var filename in matchingFiles)
                    {
                        string nwFilename = filename.Replace(rootPath, outputPath);

                        processSingleMsgFile(filename, nwFilename);
                    }
                }
                else
                {
                    string nwFilename = rootPath.Replace(rootPath, outputPath);
                    processSingleMsgFile(rootPath, nwFilename);
                }
            });
        }
示例#5
0
        public static void RunWithOptions(CmdOptions options)
        {
            var validator = new CmdOptionsValidator(options);

            validator.Validate();

            var bytesReader = new BytesReader(options.NumberOfBytes);

            var attr = File.GetAttributes(options.Path);

            if (!attr.HasFlag(FileAttributes.Directory))
            {
                RunForSingleFile(bytesReader, options);
                return;
            }

            var fileWalker = new FileWalker(options.Path, options.Recursive, options.MaxDepth);

            var runner = new Runner(
                bytesReader,
                fileWalker,
                options.Separator,
                options.BytesSeparator);

            runner.Run();
        }
示例#6
0
        private IEnumerable <OpenInEditorToggleViewModel> BuildAllViewModelsAsync()
        {
            Log.Info("Loading files.");

            var solutionPath = Configuration.SolutionPath;
            var filters      = new FileWalkerFilter[]
            {
                new HiddenFolderFilter(),
                new SolutionFileFilter(),
                new BuildArtifactsFilter(),
                new NugetFolderFilter(),
            };
            var allFiles          = FileWalker.FromFile(solutionPath, filters);
            var solutionUri       = new Uri(solutionPath, UriKind.Absolute);
            var currentReferences = new HashSet <string>(Configuration.OpenInEditorReferences);
            var viewModels        = allFiles.Select(file =>
            {
                var vm      = new OpenInEditorToggleViewModel(file, solutionUri);
                vm.Included = currentReferences.Contains(vm.RelativePath.OriginalString);
                return(vm);
            });

            Log.Info("Files loaded.");

            return(viewModels);
        }
示例#7
0
 public void Start()
 {
     ctsrc = new CancellationTokenSource();
     Task.Factory.StartNew(() =>
     {
         IsWalking = true;
         var luke  = new FileWalker();
         StartFileWalking(ctsrc.Token);
     }, ctsrc.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current);
 }
        public MainWindow()
        {
            InitializeComponent();

            _hashDb     = new HashDb();
            _fileWalker = new FileWalker(_hashDb);

            _hashDbViewModel = new HashDBViewModel();
            DataContext      = _hashDbViewModel;

            UpdateScan(@"c:\tmp");

            Width  = 1200;
            Height = 600;
        }
示例#9
0
        private static IEnumerable <string> _GetImageFiles(string[] fileNames, int maxFiles)
        {
            var directories = new List <string>();

            foreach (string file in fileNames)
            {
                if (File.Exists(file))
                {
                    if (_IsImageFile(file))
                    {
                        yield return(file);

                        --maxFiles;
                        if (maxFiles == 0)
                        {
                            yield break;
                        }
                    }
                }
                else if (Directory.Exists(file))
                {
                    directories.Add(file);
                }
            }

            // We've processed all the top-level files.
            // If there are still files to be gotten then start walking the directories.
            foreach (string directory in directories)
            {
                DirectoryInfo di = new DirectoryInfo(directory);
                foreach (string imgExt in _ImageExtensions)
                {
                    foreach (FileInfo fi in FileWalker.GetFiles(di, "*" + imgExt, true))
                    {
                        yield return(fi.FullName);

                        --maxFiles;
                        if (maxFiles == 0)
                        {
                            yield break;
                        }
                    }
                }
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            try
            {
                Logger.Info("Starting Tester...");
                var h = new HashDb();
                var w = new FileWalker(h);
                w.WalkDirectory(@"c:\tmp");
                h.SaveToXml(xmlFileName);
                h.LoadFromXml(xmlFileName);

                Console.WriteLine(h);
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
示例#11
0
        public IEnumerable <string> GetAdditiontalDocuments(string projectFilePath)
        {
            var filters = new FileWalkerFilter[]
            {
                new TemplateFileFilter(),
                new ProjectFileFilter(),
                new BuildArtifactsFilter(),
                new HiddenFolderFilter(),
                new SolutionFilter(Solution)
                {
                    FilterDocuments = true
                }
            };

            foreach (var p in FileWalker.FromFile(projectFilePath, filters))
            {
                yield return(p);
            }
        }
        private async Task processChangeDateTimes(string path, string filePattern, DateTime?dtCreated, DateTime?dtModified)
        {
            await Task.Run(async() =>
            {
                List <string> matchingFiles = FileWalker.WalkDir(path, pattern: filePattern);

                foreach (var filename in matchingFiles)
                {
                    if (dtCreated.HasValue)
                    {
                        File.SetCreationTime(filename, dtCreated.Value);
                    }
                    if (dtModified.HasValue)
                    {
                        File.SetLastWriteTime(filename, dtModified.Value);
                    }
                }
            });
        }
示例#13
0
    public async Task RecursePath_FilterFileByExtension(string extensionFilter, string file, bool wanted)
    {
        // Given
        _configService.GetFilterExtension().Returns(new[] { extensionFilter });
        var fileWalker = new FileWalker(_compareService, _configService, _fileSystemService);


        _fileSystemService.GetFiles("/").Returns(new[] { file });
        _configService.GetFilterExtension().Returns(new[] { extensionFilter });

        _fileSystemService.HasAccess(file).Returns(true);
        _fileSystemService.IsLink(file).Returns(false);


        // When
        await fileWalker.RecursePath("/");

        // Then
        _compareService.Received(wanted ? 1 : 0).AddFile(file);
    }
示例#14
0
        internal static IEnumerable <IFileSystemOperation> MoveDirectoryOperations(string src, string dst)
        {
            EnsureDirectoryExists(src);
            EnsureDirectoryNotExists(dst);

            List <IFileSystemOperation> operations = new List <IFileSystemOperation>();

            FileWalker fileWalker = new FileWalker(src);

            operations.Add(Factory.CreateDirectoryCreate(dst));

            VirtualPath srcRootPath = new VirtualPath(src);
            VirtualPath dstRootPath = new VirtualPath(dst);

            EnsurePathExists(dstRootPath.Parent, operations);

            foreach (var dir in fileWalker.Directories.Reverse().Skip(1))
            {
                VirtualPath srcDirPath = new VirtualPath(dir);
                VirtualPath dstDirPath = new VirtualPath(
                    dstRootPath.Parts,
                    srcDirPath.Parts.Skip(srcRootPath.Parts.Count()));

                operations.Add(Factory.CreateDirectoryCreate(dstDirPath.ToString()));
            }
            foreach (var file in fileWalker.Files)
            {
                VirtualPath srcFilePath = new VirtualPath(file);
                VirtualPath dstFilePath = new VirtualPath(
                    dstRootPath.Parts,
                    srcFilePath.Parts.Skip(srcRootPath.Parts.Count()));

                operations.Add(Factory.CreateFileMove(file, dstFilePath.ToString()));
            }
            foreach (var dir in fileWalker.Directories)
            {
                operations.Add(Factory.CreateDirectoryDelete(dir));
            }

            return(operations);
        }
        private MksProjectFile ProjectNameFromPath(string relativePathToSourceProj)
        {
            var match = regex.Match(relativePathToSourceProj);
            var directoryStructure = match.Groups[1].Value.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
            //var indexIfCSextension = fileName.LastIndexOf(@"\.cs", StringComparison.Ordinal);



            var projectName = "";

            projectName = projectName + directoryStructure[0];

            if (directoryStructure.Length == 1 ||
                (directoryStructure.Length == 2 && directoryStructure[1].Contains(".cs")))
            {
                projectName = projectName + "_" +
                              FileWalker.CoreOrDupe(Path.Combine(_rootOfSourceDir, directoryStructure.ConcatToString("\\")),
                                                    _rootOfSourceDir, _rootOfTargetDir);
            }
            else
            {
                projectName = projectName + "_" + directoryStructure[1];
            }

            if (projectName.Contains('_') == false)
            {
            }

            var mksProjectFile = new MksProjectFile();

            mksProjectFile.Name               = projectName;
            mksProjectFile.RelativePath       = _rootOfSource + projectName.Replace("_", "\\").Trim();
            mksProjectFile.FileName           = projectName.Replace("_", "").Trim() + ".csproj";
            mksProjectFile.AbsoluteTargetPath = _rootOfTargetDir + projectName.Replace("_", "\\").Trim() + "\\" + mksProjectFile.FileName;

            return(mksProjectFile);
        }