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); }
private static 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 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); }
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); }
private void ReportWebsiteInfo(WebSiteDataModel data) { TextBoxResult.AppendLine($"{data.WebsiteUrl} downloaded: {data.WebsiteData.Length} characters long."); }