Web farms


List of examples:

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
WebFarmServerInfo.Provider.Set(newServer);

> Back to list of examples

Updating a web farm server



// Gets the web farm server
WebFarmServerInfo updateServer = WebFarmServerInfo.Provider.Get("NewServer");

if (updateServer != null)
{
    // Updates the properties of the server
    updateServer.ServerDisplayName = updateServer.ServerDisplayName.ToLowerCSafe();

    // Saves the changed server to the database
    WebFarmServerInfo.Provider.Set(updateServer);
}

> Back to list of examples

Updating multiple web farm servers



// Gets all enabled web farm servers
var servers = WebFarmServerInfo.Provider.Get().WhereTrue("ServerEnabled");

// Loops through individual servers
foreach (WebFarmServerInfo server in servers)
{
    // Disables the server
    server.ServerEnabled = false;

    // Saves the changed server to the database
    WebFarmServerInfo.Provider.Set(server);
}

> Back to list of examples

Deleting a web farm server



// Gets the web farm server
WebFarmServerInfo deleteServer = WebFarmServerInfo.Provider.Get("NewServer");

if (deleteServer != null)
{
    // Deletes the web farm server
    WebFarmServerInfo.Provider.Delete(deleteServer);
}

> Back to list of examples

Creating a web farm synchronization task



// Sets the properties for the task
string siteName = "destinationSiteName";
int destinationMediaLibraryID = 1;
string origPath = "relative/path/to/source/file";
string newPath = "relative/path/to/destination";

// Creates the web farm task
WebFarmHelper.CreateTask(new CopyFileMediaWebFarmTask
{
    SiteName = siteName,
    DestinationLibraryId = destinationMediaLibraryID,
    SourcePath = origPath,
    DestinationPath = newPath
});

> Back to list of examples