Пример #1
0
        private static async Task <WebSiteDataModel> DownloadWebsiteAsync(string websiteURL)
        {
            WebSiteDataModel output = new WebSiteDataModel();
            WebClient        client = new WebClient();

            output.WebsiteUrl  = websiteURL;
            output.WebsiteData = await client.DownloadStringTaskAsync(websiteURL);

            return(output);
        }
Пример #2
0
        private static WebSiteDataModel DownloadWebsite(string websiteURL)
        {
            WebSiteDataModel output = new WebSiteDataModel();
            WebClient        client = new WebClient();

            output.WebsiteUrl  = websiteURL;
            output.WebsiteData = client.DownloadString(websiteURL);

            return(output);
        }
Пример #3
0
        private void RunDownloadSync()
        {
            List <string> websites = PrepData();

            foreach (string site in websites)
            {
                WebSiteDataModel results = DownloadWebsite(site);
                ReportWebsiteInfo(results);
            }
        }
Пример #4
0
        private async Task <List <WebSiteDataModel> > RunDownloadParallelAsync2(IProgress <ProgressReportModel> progress)
        {
            List <string>           websites = PrepData();
            List <WebSiteDataModel> output   = new List <WebSiteDataModel>();
            ProgressReportModel     report   = new ProgressReportModel();

            await Task.Run(() =>
            {
                Parallel.ForEach <string>(websites, (site) =>
                {
                    WebSiteDataModel results = DownloadWebsite(site);
                    output.Add(results);

                    report.SiteDownloaded     = output;
                    report.PercentageComplete = (output.Count * 100) / websites.Count;
                    progress.Report(report);
                });
            });

            return(output);
        }
Пример #5
0
        private async Task <List <WebSiteDataModel> > RunDownloadAsync(IProgress <ProgressReportModel> progress, CancellationToken cancellationToken)
        {
            List <string>           websites = PrepData();
            List <WebSiteDataModel> output   = new List <WebSiteDataModel>();
            ProgressReportModel     report   = new ProgressReportModel();

            foreach (string site in websites)
            {
                WebSiteDataModel results = await DownloadWebsiteAsync(site);

                output.Add(results);

                cancellationToken.ThrowIfCancellationRequested();

                report.SiteDownloaded     = output;
                report.PercentageComplete = (output.Count * 100) / websites.Count;
                progress.Report(report);
            }

            return(output);
        }
Пример #6
0
 private void ReportWebsiteInfo(WebSiteDataModel data)
 {
     TextBoxResult.AppendLine($"{data.WebsiteUrl} downloaded: {data.WebsiteData.Length} characters long.");
 }