Google.SafeBrowsing.API.GenerateCombinations C# (CSharp) Method

GenerateCombinations() public method

Generate valid url combinations that have to be checked againts the database
public GenerateCombinations ( CanonicalURL url ) : IEnumerable
url CanonicalURL Canonical URL
return IEnumerable
        public IEnumerable<string> GenerateCombinations(CanonicalURL url)
        {
            var list = new List<string>();


            var hostnames = new List<string>();

            hostnames.Add(url.Host);

            //split hostname to individual components
            if (!IsIpAddress(url.Host))
            {
                var res = SplitHost(url.Host).Skip(1);
                hostnames.AddRange(res.Take(res.Count() - 1).Skip(Math.Max(0, res.Count() - 5)));
            }


            var multipath = new List<string>();

            //split path to individual components
            multipath.Add(url.Path);

            multipath.AddRange(SplitPath(url.Path).Skip(1).Reverse().Take(4));

            string path = null;
            foreach (var hostname in hostnames)
            {
                path = multipath.First();

                if (!String.IsNullOrEmpty(url.Query))
                    list.Add(hostname + path + url.Query);

                list.Add(hostname + path);

                foreach (var subpath in multipath.Skip(1))
                {
                    list.Add(hostname + subpath);
                }

            }

            return list;
        }

Usage Example

        public void t03()
        {
            string[] addresses = { "1.2.3.4/1/",
                                   "1.2.3.4/" };

            var api = new Google.SafeBrowsing.API("1234");

            var url = Google.SafeBrowsing.CanonicalURL.Get("http://1.2.3.4/1/");

            var res = api.GenerateCombinations(url);

            CollectionAssert.AreEqual(addresses, res.ToArray());
        }
All Usage Examples Of Google.SafeBrowsing.API::GenerateCombinations