Exemplo n.º 1
0
 public FormMain()
 {
     siteUrl    = string.Empty;
     keyword    = string.Empty;
     collector  = new WebCollector();
     calculator = new WebCalculator();
     InitializeComponent();
 }
Exemplo n.º 2
0
        public int CalculateNumberOfHits(IWebCollector webColl, string keyword)
        {
            if (string.IsNullOrEmpty(webColl.HtmlCode) || string.IsNullOrEmpty(keyword) || webColl == null)
            {
                return(-1);
            }

            return(Regex.Matches(webColl.HtmlCode.ToLower(), keyword).Count);
        }
Exemplo n.º 3
0
        // Test for null WebCollector.
        public void NullObjectTest()
        {
            string keyword = "Trump";

            IWebCalculator calculator = new WebCalculator();
            IWebCollector  collector  = null;

            int numberOfMatches = calculator.CalculateNumberOfHits(collector, keyword);

            Assert.AreEqual(-1, numberOfMatches);
        }
Exemplo n.º 4
0
        public int CalculateNumberOfHits(IWebCollector webColl, string keyword)
        {
            if (string.IsNullOrEmpty(webColl.HtmlCode) || webColl == null || string.IsNullOrEmpty(keyword))
            {
                return(-1);
            }

            MatchCollection collection = Regex.Matches(webColl.HtmlCode, keyword, RegexOptions.IgnoreCase);

            return(collection.Count);
        }
Exemplo n.º 5
0
        public int CalculateNumberOfHits(IWebCollector webColl, string keyword)
        {
            int numberOfMatches = 0;

            if (webColl == null || webColl.HtmlCode == null || webColl.HtmlCode == string.Empty || keyword == null || keyword == string.Empty)
            {
                return(-1); // -1 is the "Fail value".
            }
            else
            {
                //We end up here if we pass all the nullchecks and string.empty checks.
                foreach (Match match in Regex.Matches(webColl.HtmlCode.ToLower(), keyword.ToLower())) //ToLower for case insensetive
                {
                    numberOfMatches++;
                }

                return(numberOfMatches);
            }
        }
Exemplo n.º 6
0
        public int CalculateNumberOfHits(IWebCollector webColl, string keyword)
        {
            if (keyword != null && webColl != null && webColl.HtmlCode != string.Empty)
            {
                try
                {
                    var text   = webColl.HtmlCode;
                    var query  = keyword;
                    int result = Regex.Matches(text, keyword).Count;

                    return(result);
                }
                catch (Exception)
                {
                    return(-1);
                }
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 7
0
 public int CalculateNumberOfHits(IWebCollector webColl, string keyword)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 public Form1()
 {
     InitializeComponent();
     _myWebCalculator = new WebCalculator();
     _myWebCollector  = new WebCollector();
 }
Exemplo n.º 9
0
 public Form1()
 {
     InitializeComponent();
     listBoxMessage.Visible = false;
     myWebCollector         = new WebCollector();
 }