We know that the distributed database of Geodatabase can be online or offline, while the online and offline interfaces are different because the operations are different. Let's take a look at the differences between the two:
Online
Offline
The four images clearly illustrate the principle (each of which is divided into LAN and Internet)
Important interfaces:
Geodataserver represents a database connection. This sentence may not be easy to understand,Code, You may understand:
Public igeodataserver initgeodataserverfromfile (string path)
{
// Create the geodataserver and cast to the igeodataserverinit interface.
Igeodataserver geodataserver = new geodataserverclass ();
Igeodataserverinit geodataserverinit = (igeodataserverinit) geodataserver;
Geodataserverinit. initfromfile (@ "C: \ ArcGIS \ arctutor \ databaseservers \ hazards. GDB ");
Return geodataserver;
}
In the offline mode, data is synchronized through the import, export, and import and export methods provided by this interface. See the following example:
Public void exportreplicadatachanges (igeodataserver sourcegds, string replicaname,
String outputdirectory)
{
Try
{
// Set the export options.
Gdsexportoptions = new gdsexportoptions ();
Gdsexportoptions. exportformat = esrigdsexportformat. esrigdsexportformatxml;
Gdsexportoptions. Compressed = true;
Gdsexportoptions. binarygeometry = false;
// Export the data changes. Note: The replica must be in a sending data state.
Igdsdata gdsdata = sourcegds. exportreplicadatachanges (replicaname,
Gdsexportoptions, esrigdstransporttype. esrigdstransporttypeurl,
Esriexportgenerationsoption. esriexportgenerationsall, false );
// Force deletion of folder and contents if they exist.
If (directory. exists (outputdirectory ))
{
Directory. Delete (outputdirectory, true );
}
// Create the Output Folder.
Directory. createdirectory (outputdirectory );
// Get the compressed data changes document from the URL to the local output directory.
If (gdsdata. transporttype = esrigdstransporttype. esrigdstransporttypeurl)
{
String filename = system. Io. Path. getfilename (gdsdata. url );
String outputfilename = system. Io. Path. Combine (outputdirectory, filename)
;
WebClient WC = new WebClient ();
WC. downloadfile (gdsdata. url, outputfilename );
WC. Dispose ();
}
Else
{
// The file has been embedded because there is no output directory set on ArcGIS Server.
Console. writeline ("server is not configured with a virtual directory .");
}
}
Catch (comexception comexc)
{
Throw new exception (string. Format (
"Exporting data changes errored: {0}, error code: {1}", comexc. Message,
Comexc. errorcode), comexc );
}
Catch (exception exc)
{
Throw new exception (string. Format ("exporting data changes errored: {0 }",
Exc. Message), exc );
}
}
In the online mode, replicatonagent interface is used.
The replicatonagent interface is used for online synchronization.
Public void synchronizereplica (igeodataserver parentgds, igeodataserver childgds,
String replicaname, esrireplicationagentreconcilepolicy conflictpolicy,
Esrireplicasynchronizedirection syncdirection, Boolean columnlevel)
{
Try
{
// Iterate through the replicas of the parent geodata server.
Igpreplicas gpreplicas = parentgds. Replicas;
Igpreplica parentreplica = NULL;
For (INT I = 0; I <gpreplicas. Count; I ++)
{
// See if the unqualified replica name matches the replicaname parameter.
Igpreplica currentreplica = gpreplicas. get_element (I );
String currentreplicaname = currentreplica. Name;
Int dotindex = currentreplicaname. lastindexof (".") + 1;
String basename = currentreplicaname. substring (dotindex,
Currentreplicaname. Length-dotindex );
If (basename. tolower () = replicaname. tolower ())
{
Parentreplica = currentreplica;
Break;
}
}
// Check to see if the parent replica was found.
If (parentreplica = NULL)
{
Throw new argumentexception (
"The requested replica cocould not be found on the parent GDS .");
}
// Iterate through the replica of the Child geodata server.
Gpreplicas = childgds. Replicas;
Igpreplica childreplica = NULL;
For (INT I = 0; I <gpreplicas. Count; I ++)
{
// See if the unqualified replica name matches the replicaname parameter.
Igpreplica currentreplica = gpreplicas. get_element (I );
String currentreplicaname = currentreplica. Name;
Int dotindex = currentreplicaname. lastindexof (".") + 1;
String basename = currentreplicaname. substring (dotindex,
Currentreplicaname. Length-dotindex );
If (basename. tolower () = replicaname. tolower ())
{
Childreplica = currentreplica;
Break;
}
}
// Check to see if the child replica was found.
If (childreplica = NULL)
{
Throw new argumentexception (
"The requested replica cocould not be found on the Child GDS .");
}
// Synchronize the replica.
Ireplicationagent replicationagent = new replicationagentclass ();
Replicationagent. synchronizereplica (parentgds, childgds, parentreplica,
Childreplica, conflictpolicy, syncdirection, columnlevel );
}
Catch (comexception comexc)
{
Throw new exception (string. Format (
"Create replica errored: {0}, error code: {1}", comexc. Message,
Comexc. errorcode), comexc );
}
Catch (exception exc)
{
Throw new exception (string. Format ("create replica errored: {0}", exc. Message)
, Exc );
}