示例#1
0
        private 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 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 RunDownloadParallelAsyncV2()
        {
            List <string>           websites    = PrepData();
            List <WebsiteDataModel> websiteList = new List <WebsiteDataModel>();

            await Task.Run(() =>
            {
                Parallel.ForEach <string>(websites, (site) =>
                {
                    WebsiteDataModel result = DownloadWebsite(site);
                    websiteList.Add(result);
                });
            });

            foreach (var item in websiteList)
            {
                ReportWebsiteInfo(item);
            }
        }
示例#5
0
        private async Task RunDownloadAsync(IProgress <ProgressReport> progress, CancellationToken token)
        {
            List <string>           websites = PrepData();
            List <WebsiteDataModel> sites    = new List <WebsiteDataModel>();

            ProgressReport report = new ProgressReport();

            foreach (string site in websites)
            {
                WebsiteDataModel result = await Task.Run(() => DownloadWebsite(site));

                sites.Add(result);
                ReportWebsiteInfo(result);

                token.ThrowIfCancellationRequested();

                report.SitesDownloaded    = sites;
                report.PercentageComplete = (sites.Count * 100) / websites.Count;
                progress.Report(report);
            }
        }
示例#6
0
 private void ReportWebsiteInfo(WebsiteDataModel data)
 {
     resultsWindow.Text += $"{ data.WebsiteUrl } downloaded: { data.WebsiteData.Length } characters long.{ Environment.NewLine }";
 }