Note
The API described here is available in Syniti Replicate/DBMoto version 7.1 and above. If you have an application that contains code for running replications in earlier releases, you should plan to modify your application to use the new API.
The code below provides a simple example of how to start the Replication Agent for a replication in the default metadata running on the "local" Syniti Replicate server.
The .NET namespace for the Syniti Replicate API is HitSoftware.DBMoto.Application. This namespace includes the class DBMotoApplication, the main singleton object of the DBOM, which can be instantiated through the static singleton method Instance:
using HiTSoftware.DBMoto.ObjectModel; \\APIs
using HiTSoftware.DBMoto.Common; \\ Type Definition for the APIs
...
public void Run(){
try
{
// Static singleton constructor
dbmApp = DBMotoApplication.Instance;
// Retrieving the local server from the list available in the DBMotoApplication instance
dbmServer = dbmApp.Servers["local"];
// Connecting to the server agent using anonymous authentication
dbmServer.Connect();
// Define and load the current metadata
currentMetadata = dbmServer.Metadatas.DefaultMetadata;
// Set synchronization between metadata and Replication Agent (TCP/IP)
currentMetadata.IsSynchronized = true;
currentMetadata.Load();
if (currentMetadata.IsRunning())
{
Console.WriteLine("Data replicator is running on " + currentMetadata.Name);
Console.WriteLine("Stopping now ...");
// Stopping the Replication Agent after a timeout of 10000 milliseconds
currentMetadata.Server.StopReplicationManager(10000);
}
else
{
Console.WriteLine("Data replicator is stopped");
Console.WriteLine("Starting now (as an application) ...");
// Starting the Replication Agent as an application
currentMetadata.Server.StartReplicationManager(false);
}
}
catch(Exception e)
{
if (currentMetadata != null)
currentMetadata.Unload();
if (dbmServer != null)
dbmServer.Disconnect();
Console.WriteLine(e.Message);
}
}...The DBMotoApplication object has access to a list of IServer objects, which is the list of server agents configured in the Management Center and stored in the local dbmoto.config file. DBMoto users typically define at least a "local" server in the Management Center. It is therefore possible to get a pointer of the local server by calling:
dbmServer = dbmApp.Servers["local"];With a pointer to the local server, you can connect to the server:
Using anonymous authentication (if allowed by the server agent):
dbmServer.Connect();Using DBMoto authentication (by passing an application login):
dbmServer.Connect(txtUser.Text.Trim(), txtPassword.Text.Trim(), false);Using Windows authentication (the Windows domain credentials):
dbmServer.Connect(null, null, true);The IServer class also contains the list of metadata defined for the server, and identifies the default metadata, which will be used by the Replication Agent:
currentMetadata = dbmServer.Metadatas.DefaultMetadata;For interaction that involves the Replication Agent and the metadata, the metadata should be 'synchronized' with the Replication Agent, meaning that the application using the DBMoto API should open a TCP/IP connection to the Replication Agent and receive notification from the Replication Agent:
currentMetadata.IsSynchronized = true;should be called before loading the metadata.
The IsSynchronized property also allows you to receive monitor information via the API including how many records have been processed and the current transaction ID in a running replication.
Use the IServer StartReplicationManager and StopReplicationManager methods to start and stop the Replication Agent.
The simple code sample described above provides an introduction to the DBMoto API. Explore the full capabilities of the DBMoto API from Visual Studio, or from the DBMoto API Reference Guide.