Example #1
0
        /// <summary>
        /// Adds a server to the WebFarm
        /// </summary>
        /// <param name="farm">The name of the WebFarm</param>
        /// <param name="settings">The settings of the server</param>
        /// <returns>If the server was added.</returns>
        public bool AddServer(string farm, WebFarmServerSettings settings)
        {
            ConfigurationElement farmElement = this.GetFarm(farm);

            if (farmElement != null)
            {
                ConfigurationElementCollection servers = farmElement.GetCollection();
                ConfigurationElement           server  = servers.FirstOrDefault(f => f.GetAttributeValue("address").ToString() == settings.Address);

                if (server == null)
                {
                    ConfigurationElement serverElement = servers.CreateElement("server");
                    serverElement["address"] = settings.Address;

                    var serverSettings = serverElement.ChildElements["applicationRequestRouting"];

                    if (settings.HttpPort.HasValue)
                    {
                        serverSettings["httpPort"] = settings.HttpPort.Value;
                    }

                    if (settings.HttpsPort.HasValue)
                    {
                        serverSettings["httpsPort"] = settings.HttpsPort.Value;
                    }

                    if (settings.Weight.HasValue)
                    {
                        serverSettings["weight"] = settings.Weight.Value;
                    }

                    servers.Add(serverElement);
                    _Server.CommitChanges();

                    _Log.Information("Adding server '{0}'.", settings.Address);
                    return(true);
                }
                else
                {
                    _Log.Information("The server '{0}' already exists.", settings.Address);
                    return(false);
                }
            }

            return(false);
        }
Example #2
0
 public static bool AddServer(this ICakeContext context, string server, string farm, WebFarmServerSettings settings)
 {
     using (ServerManager manager = BaseManager.Connect(server))
     {
         return(WebFarmManager
                .Using(context.Environment, context.Log, manager)
                .AddServer(farm, settings));
     }
 }
Example #3
0
 public static bool AddServer(this ICakeContext context, string farm, WebFarmServerSettings settings)
 {
     return(context.AddServer("", farm, settings));
 }