public void Speed_Test()
        {
            var filePath = @"C:\logs\20170914\Service-Error.log";

            var timer = new Stopwatch();

            timer.Restart();

            var search = new SlidingSearch(new string[] { "TimeOut", "Timeout" });

            timer.Stop();
            Console.WriteLine(timer.Elapsed);

            timer.Restart();

            var task = search.Go(filePath);

            task.Wait();

            timer.Stop();
            Console.WriteLine(timer.Elapsed);
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            // -r ".\debug_results.txt" -f "C:\work\original" -s ".\find_keys.txt" -t 16 -l -v

            var options = new Options();

            if (Parser.Default.ParseArguments(args, options))
            {
                // consume Options instance properties
                if (options.Verbose)
                {
                    System.Console.WriteLine($"{nameof(options.ResultFileName)} - {options.ResultFileName}");
                    System.Console.WriteLine($"{nameof(options.SreachInFolder)} - {options.SreachInFolder}");
                    System.Console.WriteLine($"{nameof(options.SreachFilePattern)} - {options.SreachFilePattern}");
                    System.Console.WriteLine($"{nameof(options.SearchablesFileName)} - {options.SearchablesFileName}");
                    System.Console.WriteLine($"{nameof(options.ThreadCount)} - {options.ThreadCount}");
                    System.Console.WriteLine($"{nameof(options.WriteFoundLine)} - {options.WriteFoundLine}");
                    System.Console.WriteLine($"{nameof(options.WriteOrdered)} - {options.WriteOrdered}");
                }
                else
                {
                    System.Console.WriteLine("working ...");
                }
            }
            else
            {
                //// Display the default usage information
                //System.Console.WriteLine(options.GetUsage());

                return;
            }

            var scanFileStorageFolderPath = options.SreachInFolder;

            if (!Directory.Exists(scanFileStorageFolderPath))
            {
                System.Console.WriteLine($"Folder doies not exitst `{scanFileStorageFolderPath}`");

                System.Console.ReadKey();

                return;
            }

            var allSearchables = File.ReadAllLines(options.SearchablesFileName);
            var search         = new SlidingSearch(allSearchables);

            var scanFilePaths = Directory.EnumerateFiles(
                scanFileStorageFolderPath,
                string.IsNullOrEmpty(options.SreachFilePattern) ? "*.*" : options.SreachFilePattern,
                SearchOption.AllDirectories).ToList();
            var tasks = new List <Task <FileSearchResults> >();

            using (IDumper resultWriter =
                       options.WriteOrdered ?
                       (IDumper) new OrderedFileWriteDumper(options.ResultFileName, options.WriteFoundLine) :
                       (IDumper) new DirectFileWriteDumper(options.ResultFileName, options.WriteFoundLine))
            {
                foreach (var scanFilePath in scanFilePaths)
                {
                    System.Console.WriteLine($"Working on: {scanFilePath}");

                    if (tasks.Count > options.ThreadCount)
                    {
                        Task.WaitAny(tasks.ToArray());
                    }

                    var r = CloseTasksGetResult(tasks);
                    resultWriter.WriteRange(r);

                    var runTask = search.Go(scanFilePath);
                    tasks.Add(runTask);
                }

                /// Wait for all tasks to finish
                while (tasks.Any())
                {
                    Task.WaitAny(tasks.ToArray());

                    var r = CloseTasksGetResult(tasks);
                    resultWriter.WriteRange(r);
                }
            }

            System.Console.WriteLine($"Finished");
            System.Console.ReadKey();
        }