13. March 2012 17:39
/
Administrator
/
/
Comments (0)
Information about Web Farm Framework API is hard to find, so I think this may help some others like me who are interested in using WFF and web deploy APIs.
In this case, I wanted to get a list of all servers in a particular Web Farm and then push a file to all of them.
First step is to add references to these libreries in your project:
Microsoft.Web.Deployment
Microsoft.web.Farm
The DLLs for these libraries are located in respective folders under C:\Program Files\IIS
I used the following helper methods to do what I needed.
public class DeploymentHelper
{
public static List GetWebFarmServerNames(string WebFarmName)
{
List ServerNames = new List();
using (WebFarmManager manager = new WebFarmManager())
{
// Make sure webfarm is valid
WebFarm webFarm = null;
if (!manager.WebFarms.TryGetWebFarm(WebFarmName, out webFarm))
{
throw new ArgumentException("WebFarm does not exist");
}
foreach (Server server in webFarm.Servers)
{
ServerNames.Add(server.Address);
}
}
return ServerNames;
}
public static void SyncFolder(string SourcePath, string DestinationPath, List DestinationServers)
{
DeploymentWellKnownProvider provider = DeploymentWellKnownProvider.ContentPath;
DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();
DeploymentBaseOptions destinationBaseOptions = new DeploymentBaseOptions();
DeploymentObject deploymentObject = DeploymentManager.CreateObject(provider, SourcePath, sourceBaseOptions);
foreach (string server in DestinationServers)
{
destinationBaseOptions.ComputerName = server;
deploymentObject.SyncTo(provider, DestinationPath, destinationBaseOptions, syncOptions);
}
}
public static void SyncFile(string SourcePath, string DestinationPath, List DestinationServers)
{
DeploymentWellKnownProvider provider = DeploymentWellKnownProvider.FilePath;
DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();
DeploymentBaseOptions destinationBaseOptions = new DeploymentBaseOptions();
DeploymentObject deploymentObject = DeploymentManager.CreateObject(provider, SourcePath, sourceBaseOptions);
foreach (string server in DestinationServers)
{
destinationBaseOptions.ComputerName = server;
deploymentObject.SyncTo(provider, DestinationPath, destinationBaseOptions, syncOptions);
}
}
}
e6b4883e-585d-4fa7-8def-9a7499dec295|0|.0|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags :