Beispiel #1
0
        private async void btnGetStatistics_Click(object sender, EventArgs e)
        {
            // -1 is the "Fail value".
            int totalMatches = -1;

            tbResult.Text = "Please wait";

            CheckSite();
            CheckKeyword();

            try
            {
                await Task.Run(() => collector.GetHTMLFromUrl(siteUrl));
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (collector != null || collector.HtmlCode != null)
            {
                if (collector.HtmlCode != string.Empty)
                {
                    // We end up here if we have a valid url.
                    try
                    {
                        totalMatches = await Task.Run(() => calculator.CalculateNumberOfHits(collector, keyword));
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Unable to fetch HTML code. Make sure you are connected to the internet and that the websites are accessible");
                }
            }
            else
            {
                MessageBox.Show("Unable to fetch HTML code. Make sure you are connected to the internet and that the websites are accessible");
            }

            // If total matches are a different nr than -1 we print it out cause then we have valid data.
            if (totalMatches != -1)
            {
                tbResult.Text = totalMatches.ToString();
            }

            else
            {
                tbResult.Text = "!?Error?!";
            }
        }
Beispiel #2
0
        private async void RadioButtonNews()
        {
            try
            {
                if (groupBoxKeyWords.SelectedRadioButton().Checked)
                {
                    textBoxCount.Text = "Loading...";
                    await Task.Delay(1000);

                    await Task.Run(() => _myWebCollector.GetHtmlFromUrl(LogicRadioButton()));
                }
            }
            finally
            {
                textBoxCount.Text = _myWebCalculator.CalculateNumberOfHits(_myWebCollector,
                                                                           groupBoxKeyWords.SelectedRadioButton().Text.ToLower()).ToString();
            }
        }
        private async void _btnGetStas_Click(object sender, EventArgs e)
        {
            bool isAnySearchWordRadioButtonChecked = false;

            foreach (RadioButton rdo in grpBxSearchWords.Controls.OfType <RadioButton>())
            {
                if (rdo.Checked)
                {
                    isAnySearchWordRadioButtonChecked = true;
                    break;
                }
            }

            bool isAnySiteRadioButtonChecked = false;

            foreach (RadioButton rdo in grpBxSites.Controls.OfType <RadioButton>())
            {
                if (rdo.Checked)
                {
                    isAnySiteRadioButtonChecked = true;
                    break;
                }
            }

            if (isAnySearchWordRadioButtonChecked)
            {
                if (isAnySiteRadioButtonChecked)
                {
                    if (rdbAftonbladet.Checked)
                    {
                        switch (grpBxSearchWords.SelectedRadioButton().Text)
                        {
                        case "Korea":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_aftonbladet));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbKorea.Text.ToLower()).ToString();
                            return;

                        case "Bostad":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_aftonbladet));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbBostad.Text.ToLower()).ToString();
                            return;

                        case "Ekonomi":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_aftonbladet));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbEkonomi.Text.ToLower()).ToString();
                            return;

                        case "Polis":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_aftonbladet));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbPolis.Text.ToLower()).ToString();
                            return;
                        }
                    }
                }

                else
                {
                    NositeSelected();
                }

                if (rdbEpressen.Checked)
                {
                    if (isAnySiteRadioButtonChecked)
                    {
                        switch (grpBxSearchWords.SelectedRadioButton().Text)
                        {
                        case "Korea":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_expressen));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbKorea.Text.ToLower()).ToString();
                            return;

                        case "Bostad":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_expressen));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbBostad.Text.ToLower()).ToString();
                            return;

                        case "Ekonomi":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_expressen));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbEkonomi.Text.ToLower()).ToString();
                            return;

                        case "Polis":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_expressen));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbPolis.Text.ToLower()).ToString();
                            return;
                        }
                    }
                    else
                    {
                        NositeSelected();
                    }
                }

                if (rdbDN.Checked)
                {
                    if (isAnySiteRadioButtonChecked)
                    {
                        switch (grpBxSearchWords.SelectedRadioButton().Text)
                        {
                        case "Korea":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_dN));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbKorea.Text.ToLower()).ToString();
                            return;

                        case "Bostad":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_dN));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbBostad.Text.ToLower()).ToString();
                            return;

                        case "Ekonomi":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_dN));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbEkonomi.Text.ToLower()).ToString();
                            return;

                        case "Polis":
                            await ResultsLoading();

                            await Task.Run(() => _myIWebCollector.GetHTMLFromUrl(_dN));

                            txBxResult.Text = _myIWebCalculator
                                              .CalculateNumberOfHits(_myIWebCollector, rdbPolis.Text.ToLower()).ToString();
                            return;
                        }
                    }
                }

                else
                {
                    NositeSelected();
                }
            }

            else if (isAnySearchWordRadioButtonChecked == false && isAnySiteRadioButtonChecked == false)
            {
                //if (txBxKeyWord.Text == "")
                //{

                lblProgress.ForeColor = Color.Red;
                lblProgress.Text      = "No radio button selected";
                // }
            }

            else
            {
                //if (txBxKeyWord.Text == "")
                //{
                lblProgress.ForeColor = Color.Red;
                lblProgress.Text      = "No keyword button selected";

                // }
            }
        }