Example #1
0
        public static async Task FileCountPipelineBasic()
        {
            allowedExtensions = new HashSet <string>()
            {
                ".ts", ".js", ".cs",
            };
            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(5));
            var fileLineCounter = new FileLineCounter();

            var fileGen = fileLineCounter
                          .GetFilesRecursively(@"C:\Users\JimmyMsk\source\repos\MATS\Monitor\", cts.Token);
            var sourceCodeFiles = fileLineCounter
                                  .FilterByExtension(fileGen, allowedExtensions);

            var(counter, errors) = fileLineCounter
                                   .GetLineCount(sourceCodeFiles);
            var totalLines = 0;

            await foreach (var item in counter.ReadAllAsync().ConfigureAwait(false))
            {
                //  Console.WriteLine($"{item.file.FullName}: {item.lines}");
                totalLines += item.lines;
            }

            Console.WriteLine($"Total: {totalLines}");
        }
Example #2
0
        public void TestCreateFile(string fileName, int numBlankLines, int numNonblankLines)
        {
            var testFile = new TestFile(fileName, numBlankLines, numNonblankLines);

            testFile.Create(Directory.GetCurrentDirectory());

            var myCounter = new FileLineCounter();
            int nLines    = myCounter.GetNumberLines(fileName);

            Assert.Equal(numNonblankLines, nLines);
        }
Example #3
0
        static async Task Main(string[] args)
        {
            allowedExtensions = new HashSet <string>()
            {
                ".ts", ".js", ".cs",
            };
            var cts = new CancellationTokenSource();

            cts.CancelAfter(TimeSpan.FromSeconds(2));
            var fileLineCounter = new FileLineCounter();
            var sw = new Stopwatch();

            sw.Start();
            var fileGen = fileLineCounter
                          .GetFilesRecursively(@"C:\Users\JimmyMsk\source\repos\MATS\Monitor\"
                                               , cts.Token
                                               );
            var sourceCodeFiles = fileLineCounter
                                  .FilterByExtension(fileGen, allowedExtensions);
            var split   = fileLineCounter.Split(sourceCodeFiles, 5);
            var counter = fileLineCounter
                          .CountLinesAndMerge(split);
            var totalLines = 0;

            await foreach (var item in counter.ReadAllAsync().ConfigureAwait(false))
            {
                //  Console.WriteLine($"{item.file.FullName}: {item.lines}");
                totalLines += item.lines;
            }


            sw.Stop();
            Console.WriteLine($"{totalLines} counted in {sw.Elapsed}");
            // await foreach (var err in errors.ReadAllAsync())
            // {
            //     Console.WriteLine(err);
            // }
            // var msger = PipelinesTest.CreateMessenger("Joe", 5);
            // var msger2 = PipelinesTest.CreateMessenger("ann", 10);
            //
            // var chMergeAny = PipelinesTest.Merge(msger, msger2);
            // await foreach (var item in chMergeAny.ReadAllAsync())
            // {
            //     Console.WriteLine(item);
            // }
            // var chMerge = PipelinesTest.Merge(msger, msger2);
            // await foreach (var item in chMerge.ReadAllAsync())
            // {
            //     Console.WriteLine(item);
            // }

            //conventional way will exception when msger.Count != msger.Count
            //because one will finish befor the other
            // while (await msger.WaitToReadAsync() || await msger2.WaitToReadAsync())
            // {
            //     Console.WriteLine(await msger.ReadAsync());
            //     Console.WriteLine(await msger2.ReadAsync());
            // }
            // await foreach (var item in msger.ReadAllAsync())
            // {
            //     Console.WriteLine(item);
            // }
            //await ch.RunProducerConsumerChannel();
        }