Condividi tramite


How to Start and Stop Project Replication

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

After you define a project on all the servers in the staging topology, you can initiate project replication. You always start project replication on the source staging server. You can stop project replication on any server in the staging topology as needed. The CReplicationProject.Start and CReplicationProject.Cancel methods are used to start and stop project replication, respectively.

Before you start the replication, make sure that you have completed the following:

  • You have created a project for the replication on all waypoint and endpoint servers. For information about how to create a project, see How to Create and Modify a Staging Project.

  • You have created a route on each server in the route path for each route that serves as a destination for the project. For information about how to create a route, see How to Manage Routes.

  • For business data projects, you have created the required business data XML configuration files and copied them to the source and destination servers. For more information about the business data XML configuration file, see CSS Business Data XML Configuration File Syntax Elements.

Note

You must have Commerce Server Staging (CSS) user rights to administer the project. You have the necessary rights if you are a member of the CSS Operators or CSS Administrators group or if you have project-level user rights. For more information about CSS user rights, see How Are Permissions Granted to CSS Authentication Accounts?

To start a project replication

  1. Create a CReplicationServer object.

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

  3. Call the CReplicationServer.OpenProject method, specifying the OPEN_EXISTING_PROJECT flag and the name of the project to start.

  4. Call the CReplicationProject.Start method to start the project replication. Specify a flag value to set the parameters for project replication. Specify 0 to run the project with the default flags, Incremental and Route. This value can be used for all project types. For more information about the replication flags, see CSS API Flags.

    The project replication starts immediately and returns a CReplicationInstance object. When you start a Web content project, you can decide to specify a bit-mask flag to set parameters for the replication.

    If you have not defined a project before you call this method, the Start method fails, setting the error code to -1073680687 (Could not find the project).

To stop a project replication

  1. Create a CReplicationServer object.

  2. Initialize the object on the specified server by using the CReplicationServer.Initialize method.

    You can stop a project that is running on any server. Stopping a project replication on one server, cancels the project from running on all servers that are downstream from that server according to the project's staging topology.

  3. Call the CReplicationServer.OpenProject method to open the project that is running and is to be stopped. Specify the OPEN_EXISTING_PROJECT flag and the name of the project to start.

  4. Call the CReplicationProject.Cancel method to stop the project replication.

Example

The following example indicates to start replication of Project1 on the local server by using the default flags for Web content projects.

CReplicationServer replicationServer = new CReplicationServer();
replicationServer.Initialize("");
CReplicationProject replicationProject;
replicationProject = (CReplicationProject)replicationServer.OpenProject("Project1", CSS_PROJECT_CREATION.OPEN_EXISTING_PROJECT);
CReplicationInstance replicationInstance;
replicationInstance = (CReplicationInstance)replicationProject.Start(0);

The following example cancels Project1 running on the local server if the replication is in the aborted state.

CReplicationServer replicationServer = new CReplicationServer();
replicationServer.Initialize("");
CReplicationProject replicationProject;
replicationProject = (CReplicationProject)replicationServer.OpenProject("Project1", CSS_PROJECT_CREATION.OPEN_EXISTING_PROJECT);
CReplicationInstance replicationInstance;
replicationInstance = (CReplicationInstance)replicationProject.Start(0);
  int i = 0;
  int sleepTime = 2000;
  int maxNumberOfPolls = 100;
    while (true)
    {
      replicationInstance.Query();
      // if replication is at one of the terminal states exit
      if ((int)replicationInstance.State == 0 || // Empty
         (int)replicationInstance.State == 9 || // Done
         (int)replicationInstance.State == 4 || // Aborted
         (int)replicationInstance.State == 5 || // Canceled
         (int)replicationInstance.State == 8) // Partial
          {
            if ((int)replicationInstance.State == 4)
              replicationProject.Cancel();
            break;
          }
             else
             {
               System.Threading.Thread.Sleep(sleepTime);
                if (i++ > maxNumberOfPolls)
               {
             Console.WriteLine("Replication took longer than expected ... Canceling project");
              replicationProject.Cancel();
               }
          }
    }

See Also

Other Resources

Projects

Schedules

Individual File Replications

What are the Staging API Concepts?

Managing Staging Projects

CReplicationProject Class

CReplicationSchedule Class

CReplicationServer Class

Managing Projects and Routes by using the Staging API