Creating and Replicating Web Content Sample

The following example replicates a Commerce Server Staging (CSS) Web content project from a source computer to a destination computer.

To run this sample, you must configure two computers to run CSS and replace the values of the constants SOURCE_MACHINE_NAME and DESTINATION_MACHINE_NAME with the names of the two computers. You must also create the directory that contains the content files to replicate on the source computer. This directory is named c:\source_directory in the example.

Option Explicit 
On Error Resume Next 

const SOURCE_MACHINE_NAME = "Source"
const DESTINTION_MACHINE_NAME = "Dest"

dim SourceReplicationServer
dim DestinationReplicationServer
dim SourceReplicationProject
dim DestinationReplicationProject
dim ReplicationInstance
dim ReplicationStatus

set SourceReplicationServer = CreateObject("CssApi.ReplicationServer")
set DestinationReplicationServer = CreateObject("CssApi.ReplicationServer")
SourceReplicationServer.Initialize(SOURCE_MACHINE_NAME)
DestinationReplicationServer.Initialize(DESTINTION_MACHINE_NAME)

WScript.Echo "Creating a project on the source server."
set SourceReplicationProject = SourceReplicationServer.OpenProject("MyProject", 1)
SourceReplicationProject.LocalDirectory = "c:\source_directory"
SourceReplicationProject.AddDestination(DESTINTION_MACHINE_NAME)
SourceReplicationProject.Commit

Wscript.Echo "Creating a project on the destination server."
set DestinationReplicationProject = DestinationReplicationServer.OpenProject("MyProject", 1)
DestinationReplicationProject.LocalDirectory = "c:\destination_directory"
DestinationReplicationProject.Commit

Wscript.Echo "Starting the replication project."
set ReplicationInstance = SourceReplicationProject.Start(0)
do while True
ReplicationInstance.Query()
if ReplicationInstance.State = 0 Or ReplicationInstance.State = 4 Or ReplicationInstance.State = 5 Or ReplicationInstance.State = 8 Or ReplicationInstance.State = 9 then exit do
WScript.Echo "Replication in progress ..."
WScript.Sleep 2000
Loop

WScript.Echo "Replication end state was " & ReplicationInstance.State

'Release the objects.
set SourceReplicationServer = Nothing
set DestinationReplicationServer = Nothing
set SourceReplicationProject = Nothing
set DestinationReplicationProject = Nothing
set ReplicationInstance = Nothing
set ReplicationStatus = Nothing

See Also

Other Resources

CReplicationServer Class

CReplicationProject Class

CReplicationInstance Class

COM Staging Examples