Esempio n. 1
0
        //Execute Websites test in asynchronous mode
        public static async Task StartAsync(IProgress <WebsitesTestReportModel> progress, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            //Create an instance of the report model object which will be later sent in progress report
            WebsitesTestReportModel report   = new WebsitesTestReportModel();
            List <string>           websites = PrepareWebsites();
            int loadedWebsitesCount          = 0;

            foreach (string site in websites)
            {
                //Cretae an instance of the website model which is later passed into the report
                WebsiteDataModel result = new WebsiteDataModel();

                await DownloadWebsiteAsync(site);

                result.URI      = site;
                result.isLoaded = true;
                report.LoadedWebsites.Add(result);
                loadedWebsitesCount++;
                //Multiply by 360 because of arc shape of progress bar
                report.ProgressArcAngle = (loadedWebsitesCount * 360) / websites.Count;
                progress.Report(report);

                cancellationToken.ThrowIfCancellationRequested();
            }
        }
        /// <summary>
        /// Download a list of sites asynchronously and in parallel, and update results in progress bar.
        /// </summary>
        /// <returns>List with information of downloaded sites.</returns>
        public static async Task <List <WebsiteDataModel> > RunDownloadParallelAsyncV2(IProgress <ProgressReport> progress)
        {
            List <string>           websites = GetWebsites();
            List <WebsiteDataModel> output   = new List <WebsiteDataModel>();
            ProgressReport          report   = new ProgressReport();

            try
            {
                await Task.Run(() =>
                {
                    Parallel.ForEach <string>(websites, (site) =>
                    {
                        WebsiteDataModel results = DownloadWebSite(site);
                        output.Add(results);

                        report.SitesDownloaded     = output;
                        report.PercentageCompleted = (output.Count * 100) / websites.Count;
                        progress.Report(report);
                    });
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(output);
        }
Esempio n. 3
0
        //Execute Websites test in parallel mode
        public static void StartParallel(IProgress <WebsitesTestReportModel> progress)
        {
            //Create an instance of the report model object which will be later sent in progress report
            WebsitesTestReportModel report   = new WebsitesTestReportModel();
            List <string>           websites = PrepareWebsites();
            var temp = new object();

            Parallel.ForEach <string>(websites, (site) =>
            {
                //Cretae an instance of the website model which is later passed into the report
                WebsiteDataModel result = new WebsiteDataModel();

                DownloadWebsite(site);

                result.URI      = site;
                result.isLoaded = true;

                //lock around access to shared object for thread safity
                lock (temp)
                {
                    report.LoadedWebsites.Add(result);
                }
            });

            //send the report to update the UI
            report.ProgressArcAngle = 360;
            progress.Report(report);
        }
Esempio n. 4
0
    private static async Task RunDownloadAsync () {
      List<string> websites = PrepData ();

      foreach (string site in websites) {
        WebsiteDataModel results = await Task.Run (() => DownloadWebsite (site));
        ReportWebsiteInfo (results);
      }
    }
Esempio n. 5
0
    private static void RunDownloadSync () {
      List<string> websites = PrepData ();

      foreach (string site in websites) {
        WebsiteDataModel results = DownloadWebsite (site);
        ReportWebsiteInfo (results);
      }
    }
Esempio n. 6
0
        private WebsiteDataModel DownloadWebsite(string websiteURL)
        {
            WebsiteDataModel output = new WebsiteDataModel();
            WebClient        client = new WebClient();

            output.WebsiteURL  = websiteURL;
            output.WebsiteData = client.DownloadString(websiteURL);
            return(output);
        }
Esempio n. 7
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;
    }
Esempio n. 8
0
    private static WebsiteDataModel DownloadWebsite (string websiteURL) {
      WebsiteDataModel output = new WebsiteDataModel ();
      WebClient client = new WebClient ();

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

      return output;
    }
Esempio n. 9
0
        public void RunDownloadSync()
        {
            List <string> websites = PrepData();

            foreach (var item in websites)
            {
                WebsiteDataModel websiteDataModel = DownloadWebsite(item);
                ReportWebsiteInfo(websiteDataModel);
            }
        }
        public async Task <WebsiteDataModel> DownloadWebsiteAsync(string url)
        {
            WebsiteDataModel data   = new WebsiteDataModel();
            WebClient        client = new WebClient();

            data.WebsiteURL  = url;
            data.WebsiteData = await client.DownloadStringTaskAsync(url);

            return(data);
        }
Esempio n. 11
0
        private WebsiteDataModel DownloadWebsite(string url)
        {
            WebsiteDataModel output = new WebsiteDataModel();
            WebClient        client = new WebClient();

            output.websiteURL  = url;
            output.websiteData = client.DownloadString(url);

            return(output);
        }
        public WebsiteDataModel DownloadWebsite(string url)
        {
            WebsiteDataModel data   = new WebsiteDataModel();
            WebClient        client = new WebClient();

            data.WebsiteURL  = url;
            data.WebsiteData = client.DownloadString(url);

            return(data);
        }
Esempio n. 13
0
        public WebsiteDataModel DownloadWebsite(string websiteUrl)
        {
            WebsiteDataModel websiteDataModel = new WebsiteDataModel();
            WebClient        webClient        = new WebClient();

            websiteDataModel.WebsiteUrl  = websiteUrl;
            websiteDataModel.WebsiteData = webClient.DownloadString(websiteUrl);

            return(websiteDataModel);
        }
Esempio n. 14
0
        private void RunDownloadSync()
        {
            List <string> websiteList = GetWebsites();

            foreach (string siteUrl in websiteList)
            {
                WebsiteDataModel result = DownloadWebsiteString(siteUrl);
                Display(result);
            }
        }
Esempio n. 15
0
        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);
        }
        /*FIRE AND FORGET
         * poin to ASYNC is that caller can CONTINUE after call even though RunDwonloadAsync is still doing the TASK on ITS OWN
         * AT VERY LEAST GUI can return control to USER while RUNDOWNLOADASYNC runs int he back
         *
         */
        private async Task RunDownloadAsync() /* void bad, TASK GOOD for RETURN type*/
        {                                     //run all task at once but report individually whichever is done first then continue
            List <string> websites = PrepData();

            foreach (string site in websites)
            {
                WebsiteDataModel results = await /*will wait till this is done*/ Task.Run(() => DownloadWebsite(site)); //will return a TAASK<WEBSITEDATMODEL>

                ReportWebSiteInfo(results);                                                                             /*need "results"*/
            }
        }
Esempio n. 17
0
        public async Task RunDownloadAsync()
        {
            List <string> websites = PrepData();

            foreach (var item in websites)
            {
                WebsiteDataModel websiteDataModel = await Task.Run(() => DownloadWebsite(item));

                ReportWebsiteInfo(websiteDataModel);
            }
        }
Esempio n. 18
0
        private async Task RunDownloadAsync()
        {
            List <string> websiteList = GetWebsites();

            foreach (string siteUrl in websiteList)
            {
                WebsiteDataModel result = await Task.Run(() => DownloadWebsiteString(siteUrl));

                Display(result);
            }
        }
Esempio n. 19
0
        private async Task RunDownloadASync()
        {
            List <string> websites = PrepData();

            foreach (var site in websites)
            {
                WebsiteDataModel res = await Task.Run(() => DownloadWebsiteAsync(site));

                ReportWebsiteInfo(res);
            }
        }
Esempio n. 20
0
        public static void AddWebsite(string websiteName, string websiteId, string userPassword, string websiteAccountNumber, string PIN, string SecurityQuestion, string SecurityAnswer)
        {
            WebsiteDataModel model = new WebsiteDataModel();

            model.WebsiteName          = websiteName;
            model.UserName             = websiteId;
            model.UserPassword         = userPassword;
            model.WebsiteAccountNumber = websiteAccountNumber;
            model.PIN = PIN;
            model.SecurityQuestion = SecurityQuestion;
            model.SecurityAnswer   = SecurityAnswer;
            // IdentityDataModel.GetInstance.AddWebsite(model);
        }
        public List <WebsiteDataModel> DownloadParallelSync()
        {
            List <string>           websites = GetWebsites();
            List <WebsiteDataModel> output   = new List <WebsiteDataModel>();

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

            return(output);
        }
Esempio n. 22
0
        public static List <WebsiteDataModel> RunDownloadSync()
        {
            List <string>           websites = PrepSampleData();
            List <WebsiteDataModel> output   = new List <WebsiteDataModel>();

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

            return(output);
        }
Esempio n. 23
0
        public WebsiteDataModel Download(string url)
        {
            base.CheckValidUrl(url);

            var output = new WebsiteDataModel();
            var client = new WebClient();
            var clock  = Stopwatch.StartNew();

            output.Url  = url;
            output.Data = client.DownloadString(url);
            clock.Stop();
            output.Elapsed = clock.ElapsedMilliseconds;

            return(output);
        }
Esempio n. 24
0
        public async Task <WebsiteDataModel> DownloadAsync(string url)
        {
            base.CheckValidUrl(url);

            var output = new WebsiteDataModel();
            var client = new WebClient();
            var clock  = Stopwatch.StartNew();

            output.Url  = url;
            output.Data = await client.DownloadStringTaskAsync(new Uri(url));

            clock.Stop();
            output.Elapsed = clock.ElapsedMilliseconds;

            return(output);
        }
        /// <summary>
        /// Downloads the requested resource as a System.String. The resource to download is specified as a System.String
        /// containing the URI.
        /// </summary>
        /// <param name="address">A System.String containing the URI to download.</param>
        /// <returns>A instance of <see cref="WebsiteDataModel"/>.</returns>
        private static WebsiteDataModel DownloadWebSite(string address)
        {
            WebsiteDataModel output = new WebsiteDataModel();
            WebClient        client = new WebClient();

            try
            {
                output.WebsiteUrl  = address;
                output.WebsiteData = client.DownloadString(address);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(output);
        }
Esempio n. 26
0
        private WebsiteDataModel DownloadWebsiteString(string websiteUrl)
        {
            WebClient http       = new WebClient();
            var       innerWatch = System.Diagnostics.Stopwatch.StartNew();
            string    data       = http.DownloadString(websiteUrl);

            innerWatch.Stop();

            WebsiteDataModel output = new WebsiteDataModel
            {
                WebsiteData      = data,
                WebsiteUrl       = websiteUrl,
                TimeMilliseconds = innerWatch.ElapsedMilliseconds
            };

            return(output);
        }
        /// <summary>
        /// Downloads the requested resource as a System.String. The resource to download is specified as a System.String
        /// containing the URI.
        /// </summary>
        /// <param name="address">A System.String containing the URI to download.</param>
        /// <returns>A Task of <see cref="WebsiteDataModel"/>.</returns>
        private static async Task <WebsiteDataModel> DownloadWebSiteAsync(string address)
        {
            WebsiteDataModel output = new WebsiteDataModel();
            WebClient        client = new WebClient();

            try
            {
                output.WebsiteUrl  = address;
                output.WebsiteData = await client.DownloadStringTaskAsync(address);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(output);
        }
Esempio n. 28
0
        //Execute Websites test in parallel async mode
        public static async Task StartParallelAsync(IProgress <WebsitesTestReportModel> progress, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            //Create an instance of the report model object which will be later sent in progress report
            WebsitesTestReportModel report   = new WebsitesTestReportModel();
            List <string>           websites = PrepareWebsites();
            var temp = new object();
            int loadedWebsitesCount = 0;

            await Task.Run(() =>
            {
                Parallel.ForEach <string>(websites, (site, loopState) =>
                {
                    //Cretae an instance of the website model which is later passed into the report
                    WebsiteDataModel result = new WebsiteDataModel();

                    DownloadWebsite(site);

                    result.URI      = site;
                    result.isLoaded = true;

                    if (cancellationToken.IsCancellationRequested)
                    {
                        loopState.Stop();
                    }

                    //lock around access to shared objects for thread safity
                    lock (temp)
                    {
                        //Send the progress report only if other iterations did not stop the loop
                        if (!loopState.IsStopped)
                        {
                            report.LoadedWebsites.Add(result);
                            loadedWebsitesCount++;
                            //Multiply by 360 because of arc shape of progress bar
                            report.ProgressArcAngle = (loadedWebsitesCount * 360) / websites.Count;

                            progress.Report(report);
                        }
                    }
                });
            });

            cancellationToken.ThrowIfCancellationRequested();
        }
Esempio n. 29
0
        // działa tak szybko jak metoda Sync() - podobne czasy
        public static async Task <List <WebsiteDataModel> > RunDownloadASync(IProgress <ProgressReportModel> progress, CancellationToken cancellationToken)
        {
            List <string>           websites = PrepSampleData();
            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(); // anulowanie zadania za pomocą cancelationToken i metody ThrowIfCancellationRequested przez klikniecie Cancel.
                report.SitesDownloaded    = output;
                report.PercentageComplete = (output.Count * 100) / websites.Count;
                progress.Report(report);
            }
            return(output);
        }
        /// <summary>
        /// Download a list of sites synchronously and in parallel.
        /// </summary>
        /// <returns>List with information of downloaded sites.</returns>
        public static List <WebsiteDataModel> RunDownloadParallelSync()
        {
            List <string>           websites = GetWebsites();
            List <WebsiteDataModel> output   = new List <WebsiteDataModel>();

            try
            {
                Parallel.ForEach <string>(websites, (site) =>
                {
                    WebsiteDataModel results = DownloadWebSite(site);
                    output.Add(results);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(output);
        }