How to Replicate Individual Files
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
You use the CReplicationClient object to replicate a single file or several files on demand. You can replicate individual files by creating and initializing a CReplicationClient object or by invoking a CReplicationClient object for an open project. Both procedures yield similar results.
Note
You cannot run a CReplicationClient object and a CReplicationServer object at the same time for the same project. If you try to use both, Commerce Server Staging (CSS) issues the error code -1073680670 (Project did not start because the project is already running.).
To replicate individual files by creating a CReplicationClient object
Create a Web content project and define the destination and properties for the project on each server in the staging topology. For information about how to create a staging project, see How to Create and Modify a Staging Project.
Create a CReplicationClient object.
Initialize the replication client by calling the CReplicationServer.Initialize method. Set the project context to the project you created in step 1.
Optional. Establish a connection to all destination servers that are defined in the project by calling the CReplicationClient.Connect method. This step is recommended when you perform several transactions to several destinations.
Call one of the following methods to send a file, send an array of files, or to delete a file:
Optional. To commit the changes on the endpoint servers, call the CReplicationClient.Commit method. This method is only required if transactional processing is enabled on the endpoint servers.
Optional. Close the connections to the destination servers by calling the CReplicationClient.Disconnect method. This step is only required if you opened connections in step 4.
To replicate individual files by invoking a CReplicationClient object for a project
Create a Web content project and define the destination and properties for the project on each server in the staging topology. For information about how to create a staging project, see How to Create and Modify a Staging Project.
Create a CReplicationServer object.
Initialize the server object on the source staging server by using the CReplicationServer.Initialize method.
Call the CReplicationServer.OpenProject method to open the project that you created in step 1. Specify the OPEN_EXISTING_PROJECT flag and the name of an existing project.
Call the CReplicationProject.StartReplicationClient method to open a CReplicationClient object.
Optional. Establish a connection to the destination servers by using the CReplicationClient.Connect method. This step is recommended when you perform several transactions to several destinations.
Call one of the following methods to send a file, send an array of files, or to delete a file:
Optional. To commit the changes on the endpoint servers, call the CReplicationClient.Commit method. This method is only required if transactional processing is enabled on the endpoint servers.
Optional. Close the connections to the destination servers by calling the CReplicationClient.Disconnect method. This step is only required if you opened connections in step 6.
Example
The following example creates a new project named Latest and defines the destination, local directory, and flags for the project. Then it invokes a replication client to send NewFile.html, delete OldFile.html, and send an array of ten files labeled ModifiedFile1.htm through ModifiedFile10.htm.
const int numFiles = 10;
CReplicationServer replicationServer = new CReplicationServer();
replicationServer.Initialize("");
CReplicationProject replicationProject;
replicationProject = (CReplicationProject)replicationServer.OpenProject("Latest", CSS_PROJECT_CREATION.CREATE_NEW_PROJECT);
replicationProject.Put("Destination", @"Mydest");
replicationProject.Put ("LocalDirectory", (@"C:\LocalCopy");
replicationProject.Put ("Flags", "4096");
replicationProject.Commit();
CReplicationClient replicationClient = new CReplicationClient();
replicationClient.Initialize("Latest");
replicationClient.Connect();
replicationClient = (CReplicationClient)replicationProject.StartReplicationClient(0);
replicationClient.SendFile("NewFile.html");
replicationClient.DeleteFile("OldFile.html");
object[] fileList = new object[numFiles];
for (int i = 0; i < numFiles; i++)
{
fileList[i] = string.Format("ModifiedFile {0}.htm", i);
}
object o = fileList;
replicationClient.SendFiles(ref o);
replicationClient.Disconnect();
See Also
Other Resources
How to Create and Modify a Staging Project