|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example demonstrates how a staging server can be created.
private bool CreateStagingServer() { // Create new staging server object ServerInfo newServer = new ServerInfo();
// Set the properties newServer.ServerDisplayName = "My new server"; newServer.ServerName = "MyNewServer"; newServer.ServerEnabled = true; newServer.ServerSiteID = CMSContext.CurrentSiteID; newServer.ServerURL = "http://localhost/KenticoCMS/CMSPages/SyncServer.asmx"; newServer.ServerAuthentication = ServerAuthenticationEnum.UserName; newServer.ServerUsername = "admin"; newServer.ServerPassword = "pass";
// Save the staging server ServerInfoProvider.SetServerInfo(newServer);
return true; } |
The following example gets and updates the staging server created by the code example above.
private bool GetAndUpdateStagingServer() { // Get the staging server ServerInfo updateServer = ServerInfoProvider.GetServerInfo("MyNewServer", CMSContext.CurrentSiteID); if (updateServer != null) { // Update the properties updateServer.ServerDisplayName = updateServer.ServerDisplayName.ToLower();
// Save the changes ServerInfoProvider.SetServerInfo(updateServer);
return true; }
return false; } |
The following example demonstrates how to get multiple staging servers based on a WHERE condition and bulk update them.
private bool GetAndBulkUpdateStagingServers() { // Prepare the parameters string where = "ServerName LIKE N'MyNewServer%'";
// Get the data for the current site DataSet servers = ServerInfoProvider.GetSiteServers(CMSContext.CurrentSiteID, where, null, -1, null, false); if (!DataHelper.DataSourceIsEmpty(servers)) { // Loop through the individual items foreach (DataRow serverDr in servers.Tables[0].Rows) { // Create object from DataRow ServerInfo modifyServer = new ServerInfo(serverDr);
// Update the properties modifyServer.ServerDisplayName = modifyServer.ServerDisplayName.ToUpper();
// Save the changes ServerInfoProvider.SetServerInfo(modifyServer); }
return true; }
return false; } |
The following example deletes the staging server created by the first code example on this page.
private bool DeleteStagingServer() { // Get the staging server ServerInfo deleteServer = ServerInfoProvider.GetServerInfo("MyNewServer", CMSContext.CurrentSiteID);
// Delete the staging server ServerInfoProvider.DeleteServerInfo(deleteServer);
return (deleteServer != null); } |