How to synchronize a data change message in a disconnected environment


Summary
This article demonstrates how to synchronize data changes between replicas in a disconnected environment using ArcObjects. A disconnected environment is one in which the parent and child replica geodatabases are not connected by a local area network (LAN) or a wide area network (WAN).

In this topic

Exporting a data change message from a replica

  1. Connect to a geodatabase to host the replica from which you want to export the data changes (see the previous note). This requires initializing a geodataserver object. Geodataserver objects allow you to access a geodatabase on a LAN or WAN through ArcGIS Server. To see how to initialize a geodataserver, refer to How to initialize a geodataserver object.
  2. Call the following procedure by pasting it into your application and passing in the following parameters:
sourceGDS
The GeoDataServer that you initialized in Step 1.  This hosts the replica geodatabase that is the source of the data changes.
replicaName
The replicaName parameter takes the name of the replica.
outputDirectory
The outputDirectory parameter specifies the output location for the data changes file. This location should point to a directory on your local drive. If this folder exists, it will be replaced. If it doesn't exist, it will be created. The delta XML file created by this function is written in a compressed ZIP file format. This ZIP file will be written to the outputDirectory passed to the function.
To export data changes, a replica must be in a Sending Data State.
[Java]
static void exportReplicaDataChanges(IGeoDataServer sourceGDS, String replicaName,
    String outputDirectory)throws Exception{
    // Set the export options.
    GDSExportOptions pGDSExportOptions = new GDSExportOptions();
    pGDSExportOptions.setExportFormat(esriGDSExportFormat.esriGDSExportFormatXml);
    pGDSExportOptions.setCompressed(true);
    pGDSExportOptions.setBinaryGeometry(false);
    // Export the data changes. Note: The replica must be in a Sending Data State.
    IGDSData gdsData = sourceGDS.exportReplicaDataChanges(replicaName,
        pGDSExportOptions, esriGDSTransportType.esriGDSTransportTypeUrl,
        esriExportGenerationsOption.esriExportGenerationsAll, false);
    // Replace or create the output directory.
    // If the directory already exists, delete it and create again by copying.
    // Force deletion of folder and contents, if they exist.
    initializeDirectory(outputDirectory);
    // Get the compressed data changes document from the URL to the local output directory.
    if (gdsData.getTransportType() == esriGDSTransportType.esriGDSTransportTypeUrl){
        String fileURL = gdsData.getURL();
        URLConnection connection = new URL(fileURL).openConnection();
        String fileName = fileURL.substring(fileURL.lastIndexOf('/') + 1);
        connection.connect();
        InputStream input = connection.getInputStream();
        FileOutputStream output = new FileOutputStream(new File(outputDirectory +
            File.separator + fileName));
        byte[] bytes = new byte[10000];
        int actuallyRead = input.read(bytes);
        while (actuallyRead !=  - 1){
            output.write(bytes, 0, actuallyRead);
            actuallyRead = input.read(bytes);
        }
        input.close();
        output.flush();
        output.close();
    }
    else{
        System.out.println("Server is not configured with a virtual directory");
        gdsData.getEmbeddedData(); 
            //The file has been embedded because there is no output directory set on ArcGIS Server.
    }
}

private static void initializeDirectory(String outputDirectory){
    File directory = new File(outputDirectory);
    if (!directory.exists()){
        directory.mkdir();
        return ;
    }
    else{
        deleteContents(directory);
        directory.delete();
        directory.mkdir();
    }
}

private static void deleteContents(File directory){
    File[] contents = directory.listFiles();
    for (File file: contents){
        if (file.isDirectory())
            deleteContents(file);
        file.delete();
    }
}

Importing a data change message into the relative replica

  1. Connect to a geodatabase to host the replica in which you want to import the data changes. This requires initializing a geodataserver object. Geodataserver objects allow you to access a geodatabase on a LAN or WAN through ArcGIS Server. To see how to initialize a geodataserver, refer to How to initialize a geodataserver object.
  2. Call the following procedure by pasting it into your application and passing in the following parameters:
targetGDS
The geodataserver that you initialized in Step 1. This hosts the replica geodatabase into which you want to import the data changes.
inputDirectory
The inputDirectory specifies the location of the data changes file. This location should point to a directory, which holds the data changes file. The function expects that the data changes document is written in a compressed ZIP file format.
The ZIP file must have the same name as the delta file contained within it. The function can easily be modified to import an uncompressed file by setting the gdsData.Compressed property to false. The function also assumes that there is only one file in this directory. If there is more than one file in the inputDirectory, only the first file will be read.
[Java]
static void importReplicaDataChanges(IGeoDataServer targetGDS, String inputDirectory)
    throws Exception{
    /* Get the replica data changes document from the input directory.
    It is assumed that the first file in the directory is the replica workspace document. */
    File zipFile = new File(inputDirectory).listFiles()[0];
    long size = zipFile.length();
    if (size > Integer.MAX_VALUE){
        System.out.println("File is larger than anticipated. Aborting.");
        return ;
    }
    byte[] bytes = new byte[(int)size];
    FileInputStream inputStream = new FileInputStream(zipFile);
    inputStream.reset();
    int actuallyRead = inputStream.read(bytes);
    while (actuallyRead !=  - 1){
        actuallyRead += inputStream.read(bytes, actuallyRead, bytes.length -
            actuallyRead);
    }
    // Embed the GDSData object.
    IGDSData gdsData = new GDSData();
    gdsData.setTransportType(esriGDSTransportType.esriGDSTransportTypeEmbedded);
    gdsData.setCompressed(true);
    gdsData.setEmbeddedData(bytes);
    // Import the data changes.
    targetGDS.importReplicaDataChanges
        (esriGDSReplicaImportSource.esriGDSReplicaImportSourceDeltaXmlFile,
        esriReplicaReconcilePolicyType.esriReplicaDetectConflicts, true, gdsData);
}






Development licensingDeployment licensing
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine: Geodatabase Update