Exemplo n.º 1
0
        //Sets up the URLs to download data and then calls on the data to be outputed to the user
        private void RunDownloadSync()
        {
            List <string> websites = PrepData();

            foreach (string site in websites)
            {
                WebsiteDataModel results = DownloadWebsite(site);
                ReportWebsiteInfo(results);
            }
        }
Exemplo n.º 2
0
        //Similiar to DownloadWebsite() but can be called asynchronously and uses a built-in asynchronous method
        private async Task <WebsiteDataModel> DownloadWebsiteAsync(string url)
        {
            WebsiteDataModel output = new WebsiteDataModel();
            WebClient        client = new WebClient();

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

            return(output);
        }
Exemplo n.º 3
0
        private WebsiteDataModel DownloadWebsite(string websiteURL)
        {
            WebsiteDataModel output = new WebsiteDataModel();
            WebClient        client = new WebClient();

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

            return(output);
        }
Exemplo n.º 4
0
        //Puts the data into the class WebsiteDataModel made for this project
        private WebsiteDataModel DownloadWebsite(string url)
        {
            WebsiteDataModel output = new WebsiteDataModel();
            WebClient        client = new WebClient();

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

            return(output);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        private WebsiteDataModel DownloadWebSiteAsync(string url)
        {
            var output = new WebsiteDataModel();

            System.Net.WebClient client = new System.Net.WebClient();

            output.WebsiteUrl  = url;
            output.WebsiteData = client.DownloadString(url);
            return(output);
        }
Exemplo n.º 7
0
        //Similliar to RunDownloadSync() but can be called to run asynchronously, No real performance gain but other things can be done while it runs
        private async Task RunDownloadAsync()
        {
            List <string> websites = PrepData();

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

                ReportWebsiteInfo(results);
            }
        }
Exemplo n.º 8
0
        //private void RunDownloadAsync()
        private async Task RunDownloadAsync()
        {
            var websites = PrepData();

            foreach (var site in websites)
            {
                //var results = DownloadWebSiteAsync(site);
                WebsiteDataModel results = await Task.Run(() => DownloadWebSiteAsync(site));

                ReportWebsiteInfo(results);
            }
        }
Exemplo n.º 9
0
        public static List <WebsiteDataModel> RunDownloadParallelSync()
        {
            List <string>           websites = PrepData();
            List <WebsiteDataModel> output   = new List <WebsiteDataModel>();

            Parallel.ForEach <string>(websites, (site) =>
            {
                WebsiteDataModel results = DownloadWebsite(site);
                output.Add(results);
            });

            return(output);
        }
Exemplo n.º 10
0
        public static List <WebsiteDataModel> RunDownloadSync()
        {
            List <string>           websites = PrepData();
            List <WebsiteDataModel> output   = new List <WebsiteDataModel>();

            foreach (string site in websites)
            {
                WebsiteDataModel results = DownloadWebsite(site);
                output.Add(results);
            }

            return(output);
        }
Exemplo n.º 11
0
        public static async Task <List <WebsiteDataModel> > RunDownloadParallelAsyncV2(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.SitesDownloaded    = output;
                    report.PercentageComplete = (output.Count * 100) / websites.Count;
                    progress.Report(report);
                });
            });

            return(output);
        }
Exemplo n.º 12
0
        public static 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);
                if (cancellationToken.IsCancellationRequested)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                }

                report.SitesDownloaded    = output;
                report.PercentageComplete = (output.Count * 100) / websites.Count;
                progress.Report(report);
            }

            return(output);
        }
Exemplo n.º 13
0
 //outputs results of the website downloads to the text box in the GUI
 private void ReportWebsiteInfo(WebsiteDataModel data)
 {
     resultsWindow.Text += "" + data.WebsiteUrl +
                           " download: " + data.WebsiteData.Length + " characters long.\n";
 }
Exemplo n.º 14
0
 private void ReportWebsiteInfo(WebsiteDataModel data)
 {
     this.resultsWindow.Text += $"{data.WebsiteUrl} downloaded: {data.WebsiteData.Length} characters long.{Environment.NewLine}";
 }
Exemplo n.º 15
0
 private void ReportWebsiteInfo(WebsiteDataModel data)
 {
     resultTextBox.Text += $"{ data.Url } downloaded: { data.Data.Length } characters long.{ Environment.NewLine }";
 }
Exemplo n.º 16
0
 private void ReportWebsiteInfo(WebsiteDataModel results)
 {
     Output.Text += $"URL: {results.WebsiteUrl} {results.WebsiteData.Length} characters long.\r\n";
 }