Exemplo n.º 1
0
        public void TestDomainExtraction1()
        {
            var input  = "http://www.foo.com";
            var domain = UrlHelpers.ExtractDomainFromUrl(input);

            Assert.AreEqual("www.foo.com", domain);
        }
Exemplo n.º 2
0
        public void TestDomainExtraction3()
        {
            var input  = "https://foo.com:2020";
            var domain = UrlHelpers.ExtractDomainFromUrl(input);

            Assert.AreEqual("foo.com", domain);
        }
Exemplo n.º 3
0
        private static int checkKnownDomains(ViewModel viewModel, string text)
        {
            var result = 0;
            // Yes, a regex for a URL is a beast to behold.
            var regex   = @"(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?";
            var matches = Regex.Matches(text, regex);

            foreach (Match match in matches)
            {
                var url    = match.Value.ToLower();
                var domain = UrlHelpers.ExtractDomainFromUrl(url);
                if (viewModel.KnownDomainScores.TryGetValue(domain, out var score))
                {
                    result += score;
                }
                else
                {
                    try {
                        result += processUrl(viewModel, url);
                    }
                    catch {
                    }
                }
            }

            return(result);
        }