コード例 #1
0
 static WebsiteDownloader AddHandlers(WebsiteDownloader downloader)
 {
     downloader.WebpageDownloadStarted += (object o, DownloadArgs arg) =>
                                          Console.WriteLine($"\nDownload started\nLink: {arg.Link.OriginalString}\nTime: {arg.Time}\nDepth:{arg.Depth}");
     downloader.WebpageDownloadCompleted += (object o, DownloadArgs arg) =>
                                            Console.WriteLine($"\nDownload ended\nLink: {arg.Link.OriginalString}\nTime: {arg.Time}\n");
     downloader.Error += (object o, DownloaderErrorArgs arg) =>
                         Console.WriteLine($"\nError - '{arg.ExceptionMessage}' occured during downloading from:\n {arg.Link}");
     return(downloader);
 }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.Clear();
            Console.CursorVisible = false;

            Program         p       = new Program();
            DownloadOptions options = p.ParseArgs(args);

            WebsiteDownloader websiteDownloader = new WebsiteDownloader(options);

            websiteDownloader.Start();

            Console.Clear();
            Console.WriteLine("Download completed, press any key to exit.");
            Console.ReadLine();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            const string defaultPath = @"D:\CDP\.net_tasks\Week_10\Downloads\";

            Uri[] resources =
            {
                new Uri("https://www.epam.com/"),
                new Uri("https://www.epam.com/what-we-do/"),
                new Uri("https://habr.com/company/goto/blog/345978/"),
            };

            Console.ForegroundColor = ConsoleColor.DarkYellow;

            HtmlLinkManager       linkManager      = new HtmlLinkManager(domainSwitchParameter: DomainSwitchParameter.WithoutRestrictions);
            FileSystemWebsiteSave resourceRecorder = new FileSystemWebsiteSave(defaultPath + "test_1\\");
            WebsiteDownloader     downloader       = new WebsiteDownloader(linkManager, resourceRecorder);

            downloader = AddHandlers(downloader);

            downloader.DownloadWebResourceAsync(resources[0], 0).Wait();

            Console.ForegroundColor = ConsoleColor.DarkCyan;

            linkManager = new HtmlLinkManager(domainSwitchParameter: DomainSwitchParameter.BelowSourceUrlPath);

            resourceRecorder.DestinationPath = defaultPath + "test_2\\";
            downloader = new WebsiteDownloader(linkManager, resourceRecorder);
            downloader = AddHandlers(downloader);

            downloader.DownloadWebResourceAsync(resources[1], 1).Wait();

            Console.ForegroundColor = ConsoleColor.DarkGreen;

            string[] excludedFormats = { ".jpg" };
            resourceRecorder.DestinationPath = defaultPath + "test_3\\";
            linkManager = new HtmlLinkManager(excludedFormats, DomainSwitchParameter.CurrentDomain);
            downloader  = new WebsiteDownloader(linkManager, resourceRecorder);
            downloader  = AddHandlers(downloader);

            downloader.DownloadWebResourceAsync(resources[2], 0).Wait();

            Console.ReadLine();
        }