Beispiel #1
0
        static async Task DoWork(CommandLineParams args)
        {
            var startTime = DateTime.Now;

            if (!Directory.Exists(args.Output))
            {
                Directory.CreateDirectory(args.Output);
            }

            ChromeDriverFactoryParams auth = null;

            if (args.AuthUrl != null)
            {
                auth = new ChromeDriverFactoryParams {
                    AuthUrl = args.AuthUrl, SubmitSelector = args.SubmitSelector, LoginSelector = args.LoginSelector, PasswordSelector = args.PasswordSelector, IsChromeWindowsRequired = args.IsChromeWindowsRequired
                };
            }

            driverFactory = new DriverFactory(auth);
            downloader    = new ImageDownloader(args.FileNameSegments, args.Output, args.DownloadThreadsCount, args.FileNameConflictPolicy);
            linksFinder   = new LinksFinder(downloader, driverFactory);

            var threads = new List <Task>();

            threads.Add(Task.Run(() => Stats(startTime)));
            threads.Add(Task.Run(async() => await linksFinder.FindLinks(args)));

            await Task.WhenAll(threads);

            Stats(startTime);
            Console.WriteLine("Finished!");
        }
Beispiel #2
0
        public async Task FindLinks(CommandLineParams args)
        {
            var threads = new List <Task>();

            if (args.ContainerSelector != null)
            {
                for (int i = 0; i < args.DownloadThreadsCount; i++)
                {
                    threads.Add(Task.Run(() => ListPagesInContainer(args.NextPageInContainerSeclector, args.PathInContainer.ToArray(), args.LinkSelector)));
                }
            }

            ListPages(args.URI, args.NextPageContainerSelector, args.LinkSelector,
                      page => DoWithLinks(args.ContainerSelector, page,
                                          containerLink => containerLinks.Enqueue(new Uri(containerLink)), "href"));

            IsContainersFindingFinished = true;

            await Task.WhenAll(threads);

            IsFinished = true;
        }