Exemple #1
0
        public async Task Generate(List <string> inputFiles, string outputPath)
        {
            var linkOptions = new DataflowLinkOptions();

            linkOptions.PropagateCompletion = true;
            var readOptions = new ExecutionDataflowBlockOptions();

            readOptions.MaxDegreeOfParallelism = config.CountOfReadThreads;
            var processOptions = new ExecutionDataflowBlockOptions();

            processOptions.MaxDegreeOfParallelism = config.CountOfProcessThreads;
            var writeOptions = new ExecutionDataflowBlockOptions();

            writeOptions.MaxDegreeOfParallelism = config.CountOfWriteThreads;

            var readBlock    = new TransformBlock <string, string>(fileName => AsyncReader.Read(fileName), readOptions);
            var processBlock = new TransformBlock <string, List <TestInfo> >(sourceCode => GenerateTests(sourceCode), processOptions);
            var writeBlock   = new ActionBlock <List <TestInfo> >(output => AsyncWriter.Write(outputPath, output).Wait(), writeOptions);

            readBlock.LinkTo(processBlock, linkOptions);
            processBlock.LinkTo(writeBlock, linkOptions);
            foreach (string file in inputFiles)
            {
                readBlock.Post(file);
            }
            readBlock.Complete();
            await writeBlock.Completion;
        }
Exemple #2
0
        public async Task Generate(List <string> pathes, string destination)
        {
            DataflowLinkOptions linkOptions = new DataflowLinkOptions {
                PropagateCompletion = true
            };
            ExecutionDataflowBlockOptions readBlockOptions = new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = config.MaxReadTasksCount
            };
            ExecutionDataflowBlockOptions processingOptions = new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = config.MaxProcessingTasksCount
            };
            ExecutionDataflowBlockOptions writeBlockOptions = new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = config.MaxWriteTasksCount
            };
            TransformBlock <string, string> readBlock = new TransformBlock <string, string>(fileName => AsyncReader.Read(fileName), readBlockOptions);
            TransformBlock <string, List <GeneratedTest> > processBlock = new TransformBlock <string, List <GeneratedTest> >(sourceCode => GenerateTestClasses(sourceCode), processingOptions);
            ActionBlock <List <GeneratedTest> >            writeBlock   = new ActionBlock <List <GeneratedTest> >((generatedClasses => AsyncWriter.Write(destination, generatedClasses)), writeBlockOptions);

            readBlock.LinkTo(processBlock, linkOptions);
            processBlock.LinkTo(writeBlock, linkOptions);

            foreach (string path in pathes)
            {
                await readBlock.SendAsync(path);
            }
            readBlock.Complete();

            await writeBlock.Completion;
        }