/// <summary> /// Download website /// </summary> /// <param name="site"></param> /// <returns></returns> private WebsiteDataModel DownloadWebsite(string site) { WebsiteDataModel output = new WebsiteDataModel(); WebClient client = new WebClient(); output.WebsiteUrl = site; output.WebsiteData = client.DownloadString(site); return(output); }
/// <summary> /// Download website /// </summary> /// <param name="site"></param> /// <returns></returns> private async Task <WebsiteDataModel> DownloadWebsiteAsync(string site) { WebsiteDataModel output = new WebsiteDataModel(); WebClient client = new WebClient(); output.WebsiteUrl = site; output.WebsiteData = await client.DownloadStringTaskAsync(site); return(output); }
/// <summary> /// Download websites synchronously /// </summary> private void RunDownloadSync() { List <string> websiteList = GetPrepDataList(); foreach (var site in websiteList) { WebsiteDataModel results = DownloadWebsite(site); ReportWebsiteInfo(results); } }
private WebsiteDataModel DownloadWebsite(string websiteURL) { WebsiteDataModel output = new WebsiteDataModel(); WebClient client = new WebClient(); output.WebsiteURL = websiteURL; output.WebsiteData = client.DownloadString(websiteURL); //donwloading index page return(output); }
private void RunDownloadSync() { List <string> webistes = PrepData(); foreach (string item in webistes) { WebsiteDataModel results = DownloadWebsite(item); ReportWebsiteInfo(results); } }
/// <summary> /// Download websites async but in sequence - not locking up UI but they run in order from first to last. /// </summary> /// <returns></returns> private async Task RunDownloadAsync() { List <string> websiteList = GetPrepDataList(); foreach (var site in websiteList) { WebsiteDataModel results = await Task.Run(() => DownloadWebsite(site)); ReportWebsiteInfo(results); } }
private async Task RunDownloadAsync() { List <string> webistes = PrepData(); foreach (string item in webistes) { WebsiteDataModel results = await Task.Run(() => DownloadWebsite(item)); ReportWebsiteInfo(results); } }
/// <summary> /// Write our results to UI /// </summary> /// <param name="results"></param> private void ReportWebsiteInfo(WebsiteDataModel results) { resultsWindow.Text += $"{results.WebsiteUrl} downloaded {results.WebsiteData.Length} characters. \n"; }
private void ReportWebsiteInfo(WebsiteDataModel data) { resultsWindow.Text += $"{data.WebsiteURL} downloaded: {data.WebsiteData.Length} characters long {Environment.NewLine}"; }