Beispiel #1
0
        //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;
            }
        }
Beispiel #2
0
        private IEnumerable<Farm> GetWebFarms(string farm, string server, bool useDnsLookup)
        {
            if (_noParams)
            {
                return FindAllWebFarms();
            }

            if (!string.IsNullOrEmpty(farm))
            {
                if (!string.IsNullOrEmpty(server))
                {
                    var f = new Farm { Name = farm };
                    f.Servers.Add(new FarmServer { Name = server, WebFarm = farm });

                    return new[] { f };
                }

                return GetWebFarm(farm);
            }

            return !string.IsNullOrEmpty(server) ? GetWebFarmsByServer(server, useDnsLookup) : FindAllWebFarms();
        }
Beispiel #3
0
        private static IEnumerable<Farm> GetWebFarm(string farmName)
        {
            using (var serverManager = new ServerManager())
            {
                var config = serverManager.GetApplicationHostConfiguration();
                var webFarmsSection = config.GetSection("webFarms");
                var foundFarmServers = new List<Farm>();

                foreach (var webFarm in webFarmsSection.GetCollection())
                {
                    if (farmName.ToLower() != webFarm["name"].ToString().ToLower()) continue;

                    var farm = new Farm { Name = webFarm["name"].ToString() };
                    foreach (var server in webFarm.GetCollection())
                    {
                        farm.Servers.Add(new FarmServer { WebFarm = farm.Name, Name = server["address"].ToString() });
                    }
                    foundFarmServers.Add(farm);
                }
                return foundFarmServers;
            }
        }