コード例 #1
0
ファイル: DemoMethods.cs プロジェクト: qctran/CSharpPractice
        private static WebsiteDataModel DownloadWebsite(string websiteURL)
        {
            WebsiteDataModel output = new WebsiteDataModel();
            WebClient        client = new WebClient();

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

            return(output);
        }
コード例 #2
0
ファイル: DemoMethods.cs プロジェクト: qctran/CSharpPractice
        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);
        }
コード例 #3
0
        public static WebsiteDataModel DownloadWebsite(string websiteURL)
        {
            var output = new WebsiteDataModel();
            var client = new WebClient();

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

            return(output);
        }
コード例 #4
0
ファイル: DemoMethods.cs プロジェクト: qctran/CSharpPractice
        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);
        }
コード例 #5
0
ファイル: DemoMethods.cs プロジェクト: qctran/CSharpPractice
        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);
        }
コード例 #6
0
ファイル: DemoMethods.cs プロジェクト: qctran/CSharpPractice
        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);

                cancellationToken.ThrowIfCancellationRequested();

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

            return(output);
        }
コード例 #7
0
ファイル: DemoMethods.cs プロジェクト: qctran/CSharpPractice
        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);
        }
コード例 #8
0
ファイル: DemoMethods.cs プロジェクト: qctran/CSharpPractice
        public static async Task <List <WebsiteDataModel> > RunDownloadAsync(IProgress <ProgressReportModel> progress)
        {
            List <string>           websites = PrepData();
            List <WebsiteDataModel> output   = new List <WebsiteDataModel>();

            foreach (var site in websites)
            {
                WebsiteDataModel results = await DownloadWebsiteAsync(site);

                output.Add(results);

                var arg = new ProgressReportModel
                {
                    PercentageComplete = (output.Count * 100) / websites.Count,
                    SitesDownloaded    = output
                };
                progress.Report(arg);
            }

            return(output);
        }