Delen via


Creating a Route and Replicating Business Data Sample

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

The following example creates a Commerce Server Staging (CSS) route and then replicates business data over the route.

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. On the source computer, you must create the directory that business data will be exported to. This directory is named c:\source_directory in the example. You must also create a configuration file that is named BusinessDataProjectDefinition.xml in the same location as this script. A sample BusinessDataProjectDefinition.xml file is provided later in this topic.

Option Explicit 
On Error Resume Next 

const SOURCE_MACHINE_NAME = "Source"
const DESTINATION_MACHINE_NAME = "Dest"

dim SourceReplicationServer
dim DestinationReplicationServer
dim ReplicationProject
dim SourceReplicationRoute
dim DestinationReplicationRoute
dim ReplicationInstance
dim ReplicationStatus

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

'Create the route on the source server.
Wscript.Echo "Creating the route on the source server."
set SourceReplicationRoute = SourceReplicationServer.AddRoute("MyRoute")
SourceReplicationRoute.BaseDirectory = "c:\source_directory"
SourceReplicationRoute.AddDestination(DESTINATION_MACHINE_NAME)
SourceReplicationRoute.Commit

'Create the route on the destination server.
Wscript.Echo "Creating the route on the destination server."
set DestinationReplicationRoute = DestinationReplicationServer.AddRoute("MyRoute")
DestinationReplicationRoute.BaseDirectory = "c:\destination_directory"
DestinationReplicationRoute.Commit

dim XmlDoc
set XmlDoc=CreateObject("Microsoft.XMLDOM")
XmlDoc.async="false"
XmlDoc.load("BusinessDataProjectDefinition.xml") 

'Create a project over the route.
WScript.Echo "Creating a project over the route."
set ReplicationProject = SourceReplicationServer.OpenProject("MyBusinessDataProject", 1)
ReplicationProject.LocalDirectory = "c:\source_directory"
ReplicationProject.BusinessDataProject = True
ReplicationProject.BusinessDataProjectXml = XmlDoc.documentElement.xml
ReplicationProject.Flags = 512
ReplicationProject.AddDestination("MyRoute")
ReplicationProject.Commit

'Start the project.
Wscript.Echo "Starting the project."
set ReplicationInstance = ReplicationProject.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 "In progress ..."
WScript.Sleep 2000
Loop

WScript.Echo "The end state of the replication was " & ReplicationInstance.State

'Release the objects.
set SourceReplicationServer = Nothing
set DestinationReplicationServer = Nothing
set ReplicationProject = Nothing
set SourceReplicationRoute = Nothing
set DestinationReplicationRoute = Nothing
set ReplicationInstance = Nothing
set ReplicationStatus = Nothing

Project Configuration File

The following XML code provides the contents of the BusinessDataProjectDefinition.xml file that is used by the example. To run the sample, you must replace CSharpSite with the name of a Commerce Server Web site that exists on the source computer.

<?xml version="1.0" encoding="utf-8" ?> 
<BusinessDataProjectProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" BusinessProjectName="">
<BusinessProjectHeader MajorVersion="1" MinorVersion="1" Revision="1" Build="1" /> 
<Source>CSharpSite</Source> 
<Role>Source</Role> 
<BusinessData BusinessDataID="b9055590-6826-45e6-b4b4-3f76a5bdedf4" BusinessDataTypeName="SiteTerms" /> 
</BusinessDataProjectProperties>

See Also

Other Resources

CSS Business Data XML Configuration File Syntax Elements

CReplicationServer Class

CReplicationProject Class

CReplicationRoute Class

CReplicationInstance Class

COM Staging Examples