Example #1
0
        private async Task <DemoClass> DownloadWebsiteAsync(string websiteURL)
        {
            DemoClass output = new DemoClass();
            WebClient client = new WebClient();

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

            return(output);
        }
Example #2
0
        private DemoClass DownloadWebsite(string websiteURL)
        {
            DemoClass output = new DemoClass();
            WebClient client = new WebClient();

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

            return(output);
        }
Example #3
0
        //Sync Download Methods

        private void RunDownload()
        {
            List <string> websites = PrepData();

            LogTxtBox.Text = "";
            foreach (var site in websites)
            {
                DemoClass results = DownloadWebsite(site);
                ReportWebsiteInfo(results);
            }
        }
Example #4
0
        //Async Download Methods
        private async Task <List <DemoClass> > RunDownloadAsync(IProgress <ProgressReportModel> progress)
        {
            List <string>       websites = PrepData();
            List <DemoClass>    output   = new List <DemoClass>();
            ProgressReportModel report   = new ProgressReportModel();

            LogTxtBox.Text = "";
            foreach (var site in websites)
            {
                DemoClass result = await DownloadWebsiteAsync(site);

                output.Add(result);


                report.WebsitesDownloaded = output;
                report.Percentage         = (output.Count * 100) / websites.Count;
                progress.Report(report);

                // ReportWebsiteInfo(results);
            }

            return(output);
        }
Example #5
0
 //Shared Methods
 private void ReportWebsiteInfo(DemoClass data)
 {
     LogTxtBox.Text += $"{data.WebsiteUrl} downloaded: {data.WebsiteData.Length} characters long. {Environment.NewLine}";
 }