Example #1
0
        private void actAdd_Execute(object sender, EventArgs e)
        {
            var dialog = new FarmWizard();

            if (dialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            var item = new ListViewItem(new[]
            {
                dialog.FarmName,
                "Online"
            })
            {
                Tag = dialog.Servers, ImageIndex = 0, StateImageIndex = 0
            };

            listView1.Items.Add(item);
            var config = _server.GetApplicationHostConfiguration();
            ConfigurationSection           webFarmsSection    = config.GetSection("webFarms");
            ConfigurationElementCollection webFarmsCollection = webFarmsSection.GetCollection();
            ConfigurationElement           webFarmElement     = webFarmsCollection.CreateElement("webFarm");

            webFarmElement["name"] = dialog.FarmName;
            ConfigurationElementCollection webFarmCollection = webFarmElement.GetCollection();

            foreach (var server in dialog.Servers)
            {
                ConfigurationElement serverElement = webFarmCollection.CreateElement("server");
                serverElement["address"] = server.Name;
                serverElement["enabled"] = true;

                ConfigurationElement applicationRequestRoutingElement = serverElement.GetChildElement("applicationRequestRouting");
                applicationRequestRoutingElement["weight"]    = server.Weight;
                applicationRequestRoutingElement["httpPort"]  = server.HttpPort;
                applicationRequestRoutingElement["httpsPort"] = server.HttpsPort;
                webFarmCollection.Add(serverElement);
            }

            webFarmsCollection.Add(webFarmElement);
            _form.AddFarmNode(dialog.FarmName, dialog.Servers);
        }