Пример #1
0
        public void DnsMappingTest()
        {
            DnsMapping mapping = new DnsMapping("pierre.sdns", "brunet123",
                                                "172.31.0.2", "*****@*****.**");

            mapping.AddResponder("*****@*****.**");
            mapping.AddResponder("*****@*****.**");
            mapping.AddResponder("*****@*****.**");

            Assert.AreEqual(2, mapping.Responders.Count);
            Assert.AreEqual("*****@*****.**", mapping.Responders[0]);
            Assert.AreEqual("*****@*****.**", mapping.Responders[1]);
        }
Пример #2
0
        public List <DnsMapping> SearchLocalCache(string pattern, bool exact,
                                                  bool random)
        {
            List <DnsMapping> searchlist = new List <DnsMapping>();

            if (pattern == "")
            {
                return(searchlist);
            }

            foreach (DnsMapping mapping in _tmappings.Values)
            {
                if (Regex.IsMatch(mapping.Alias, pattern, RegexOptions.IgnoreCase))
                {
                    bool mapping_found = false;
                    foreach (DnsMapping tmp_mapping in searchlist)
                    {
                        if (tmp_mapping.WeakEquals(mapping))
                        {
                            tmp_mapping.Rating++;
                            tmp_mapping.AddResponder(mapping.Source);
                            mapping_found = true;
                            break;
                        }
                    }
                    if (exact && pattern != mapping.Alias)
                    {
                        continue;
                    }
                    if (!mapping_found)
                    {
                        DnsMapping new_mapping = mapping.WeakCopy();
                        new_mapping.AddResponder(mapping.Source);
                        searchlist.Add(new_mapping);
                    }
                }
            }
            if (random)
            {
                searchlist.Sort(new RandomMappingComparer());
            }
            else
            {
                searchlist.Sort(new MappingComparer());
            }
            return(searchlist);
        }