Пример #1
0
        public void ShouldCorrectlyParseFileNameAndPath()
        {
            var block = FileCreator.GetFileCreatorBlock();

            block.Post(@"C:\TestFolder\TestFile.txt");
            var file = block.ReceiveWithTimeout();

            block.Complete();
            block.EnsureCompleted();
            Assert.AreEqual("TestFile.txt", file.Name);
            Assert.AreEqual(@"C:\TestFolder", file.Path);
        }
Пример #2
0
        public void ShouldRelativePathsMadeAsAbsolute()
        {
            var block = FileCreator.GetFileCreatorBlock();

            block.Post(@"TestFolder\TestFile.txt");
            var file = block.ReceiveWithTimeout();

            block.Complete();
            block.EnsureCompleted();
            Assert.AreEqual("TestFile.txt", file.Name);
            Assert.IsTrue(System.IO.Path.IsPathRooted(file.Path));
            Assert.IsTrue(System.IO.Path.IsPathRooted(file.FullPath));
        }
        public async Task ParseFilesAsync(string folderPath, string searchPattern)
        {
            var repository = repositoryFactory();
            await repository.TruncateDataAsync();

            var filesEnumerator = FilesEnumerator.GetFilesEnumeratorBlock();
            var fileCreator     = FileCreator.GetFileCreatorBlock();

            filesEnumerator.LinkToAndPropagateCompleted(fileCreator);

            var fileLinesEnumerator = FileLinesEnumerator.GetFileLinesEnumeratorBlock();

            fileCreator.LinkToAndPropagateCompleted(fileLinesEnumerator);

            var lineSplitter = LineSplitter.GetLineSplitterBlock();

            fileLinesEnumerator.LinkToAndPropagateCompleted(lineSplitter);

            var fileWordCreator = FileWordCreator.GetFileWordCreatorBlock();

            lineSplitter.LinkToAndPropagateCompleted(fileWordCreator);

            var fileWordSaver = FileWordSaver.GetFileWordSaverBlock(repositoryFactory);

            fileWordCreator.LinkToAndPropagateCompleted(fileWordSaver);

            var nullTarget = DataflowBlock.NullTarget <FileWord>();

            fileWordSaver.LinkTo(nullTarget);

            filesEnumerator.Post(new FilesEnumerator.EnumerateFolderTask
            {
                Folder        = folderPath,
                SearchPattern = searchPattern
            });
            filesEnumerator.Complete();
            await fileWordSaver.Completion;
        }