Web farms
List of examples:
- Creating a web farm server
- Updating a web farm server
- Updating multiple web farm servers
- Deleting a web farm server
- Creating a web farm synchronization task
Creating a web farm server
// Creates a new web farm server object
WebFarmServerInfo newServer = new WebFarmServerInfo();
// Sets the properties for the server
newServer.ServerDisplayName = "New server";
newServer.ServerName = "NewServer";
newServer.ServerEnabled = true;
// Saves the web farm server to the database
WebFarmServerInfoProvider.SetWebFarmServerInfo(newServer);
Updating a web farm server
// Gets the web farm server
WebFarmServerInfo updateServer = WebFarmServerInfoProvider.GetWebFarmServerInfo("NewServer");
if (updateServer != null)
{
// Updates the properties of the server
updateServer.ServerDisplayName = updateServer.ServerDisplayName.ToLowerCSafe();
// Saves the changed server to the database
WebFarmServerInfoProvider.SetWebFarmServerInfo(updateServer);
}
Updating multiple web farm servers
// Gets all enabled web farm servers
var servers = WebFarmServerInfoProvider.GetWebFarmServers().WhereTrue("ServerEnabled");
// Loops through individual servers
foreach (WebFarmServerInfo server in servers)
{
// Disables the server
server.ServerEnabled = false;
// Saves the changed server to the database
WebFarmServerInfoProvider.SetWebFarmServerInfo(server);
}
Deleting a web farm server
// Gets the web farm server
WebFarmServerInfo deleteServer = WebFarmServerInfoProvider.GetWebFarmServerInfo("NewServer");
if (deleteServer != null)
{
// Deletes the web farm server
WebFarmServerInfoProvider.DeleteWebFarmServerInfo(deleteServer);
}
Creating a web farm synchronization task
// Sets the properties for the task
string taskTarget = "";
string taskTextData = "WebFarmTask";
// Creates the web farm task
WebFarmHelper.CreateTask(DataTaskType.ClearHashtables, taskTarget, taskTextData);