次の方法で共有


How to Replicate Individual Files

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 2009 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

  1. 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.

  2. Create a CReplicationClient object.

  3. Initialize the replication client by calling the CReplicationServer.Initialize method. Set the project context to the project you created in step 1.

  4. 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.

  5. Call one of the following methods to send a file, send an array of files, or to delete a file:

  6. 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.

  7. 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

  1. 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.

  2. Create a CReplicationServer object.

  3. Initialize the server object on the source staging server by using the CReplicationServer.Initialize method.

  4. 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.

  5. Call the CReplicationProject.StartReplicationClient method to open a CReplicationClient object.

  6. 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.

  7. Call one of the following methods to send a file, send an array of files, or to delete a file:

  8. 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.

  9. 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

Projects

Individual File Replications

How to Create and Modify a Staging Project

How to Retrieve Individual File Replication Errors

CReplicationClient Class

CReplicationClientError Class

CReplicationProject Class

Replicating Individual Files by Using the Staging API