//Todo: Needs refactoring together with FindAllWebFarms, GetWebFarm and GetWebFarms private static IEnumerable<Farm> GetWebFarmsByServer(string serverName, bool useDnsLookup) { using (var serverManager = new ServerManager()) { var config = serverManager.GetApplicationHostConfiguration(); var webFarmsSection = config.GetSection("webFarms"); var foundFarms = new List<Farm>(); var servers = new List<string>(); if(useDnsLookup) { var ips = Dns.GetHostAddresses(serverName); foreach(var ip in ips) { servers.Add(ip.ToString()); } } else { servers.Add(serverName.ToLower()); } foreach (var webFarm in webFarmsSection.GetCollection()) { foreach (var server in webFarm.GetCollection()) { var webFarmServerAddress = server["address"].ToString(); if (WildcardPattern.ContainsWildcard(serverName)) { var serverAddress = server["address"].ToString(); var wildcardPattern = new WildcardPattern(serverName); if(wildcardPattern.IsMatch(serverAddress)) { var farm = new Farm { Name = webFarm["name"].ToString() }; farm.Servers.Add(new FarmServer { Name = server["address"].ToString(), WebFarm = webFarm["name"].ToString() }); foundFarms.Add(farm); } } else if (servers.Contains(webFarmServerAddress.ToLower())) { var farm = new Farm {Name = webFarm["name"].ToString()}; farm.Servers.Add(new FarmServer { Name = server["address"].ToString(), WebFarm = webFarm["name"].ToString() }); foundFarms.Add(farm); if(servers.Count == 1) { break; } } } } return foundFarms; } }