private WebsiteDataModel DownloadWebsite(string websiteURL) { WebsiteDataModel output = new WebsiteDataModel(); WebClient client = new WebClient(); output.WebsiteUrl = websiteURL; output.WebsiteData = client.DownloadString(websiteURL); return(output); }
private void RunDownloadSync() { List <string> webSites = PrepData(); foreach (string site in webSites) { WebsiteDataModel results = DownloadWebsite(site); ReportWebsiteInfo(results); } }
private void RunDownloadParallelSync(IProgress <ProgresReportModel> progress, CancellationToken ct) { List <string> webSites = PrepData(); ProgresReportModel report = new ProgresReportModel(); List <WebsiteDataModel> output = new List <WebsiteDataModel>(); Parallel.ForEach <string>(webSites, (site) => { WebsiteDataModel results = DownloadWebsite(site); output.Add(results); ct.ThrowIfCancellationRequested(); report.SitesDownloaded = output; report.PercentageComplete = (output.Count * 100) / webSites.Count; progress.Report(report); }); PrintResults(output); }
private async Task RunDownloadAsync(IProgress <ProgresReportModel> progress, CancellationToken ct) { List <string> webSites = PrepData(); ProgresReportModel report = new ProgresReportModel(); List <WebsiteDataModel> output = new List <WebsiteDataModel>(); foreach (string site in webSites) { WebsiteDataModel results = await Task.Run(() => DownloadWebsite(site)); output.Add(results); ct.ThrowIfCancellationRequested(); report.SitesDownloaded = output; report.PercentageComplete = (output.Count * 100) / webSites.Count; progress.Report(report); } }
private void ReportWebsiteInfo(WebsiteDataModel data) { resultsTextBlock.Text += $"{data.WebsiteUrl} downloaded: {data.WebsiteData.Length} characters long: {Environment.NewLine}"; }