This document is archived and information here might be outdated.  Recommended version.


How to synchronize an acknowledgement message in a disconnected environment (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with feature data > Distributed geodatabases > Replication > How to synchronize an acknowledgement message in a disconnected environment

How to synchronize an acknowledgement message in a disconnected environment


Summary
This topic shows how to send acknowledgement messages between replicas in a disconnected environment. Acknowledgement messages are exchanged between replicas in a disconnected environment to acknowledge receipt of data changes. A disconnected environment means that 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 an acknowledgement message from a replica

Complete the following steps to export an acknowledgement message from a replica:
  1. Connect to a geodatabase to host the replica from which the acknowledgement message should be exported. This requires initializing a GeoDataServer object. GeoDataServer objects allow access to a geodatabase on a LAN or WAN through ArcGIS for Server. For more information on how to initialize a GeoDataServer, see How to initialize a GeoDataServer object.
  2. Call the following procedure by pasting it into an application and passing in the following parameters:
Parameter
Description
sourceGDS
The GeoDataServer initialized in Step 1. This hosts the replica geodatabase that is the source of the acknowledgement file.
replicaName
The replicaName parameter takes the name of the replica.
outputDirectory
The outputDirectory parameter specifies the output location for the acknowledgement file. This location should point to a directory on a local drive. If this folder exists, it will be replaced. If it does not exist, it will be created.

See the following code example:
[C#]
public void ExportAcknowledgement(IGeoDataServer sourceGDS, String replicaName,
    String outputDirectory)
{
    try
    {
        // Export the acknowledgement file.
        IGDSData gdsData=sourceGDS.ExportAcknowledgement(replicaName,
            esriGDSTransportType.esriGDSTransportTypeUrl);

        // 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 uniform resource locator (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 the acknowledgement errored: {0}, Error Code: {1}",
            comExc.Message, comExc.ErrorCode), comExc);
    }
    catch (Exception exc)
    {
        throw new Exception(String.Format(
            "Exporting the acknowledgement errored: {0}", exc.Message), exc);
    }
}
[VB.NET]
Public Sub ExportAcknowledgement(ByVal sourceGDS As IGeoDataServer, ByVal replicaName As String, ByVal outputDirectory As String)
    
    Try
    ' Export the acknowledgement file.
    Dim gdsData As IGDSData=sourceGDS.ExportAcknowledgement(replicaName, esriGDSTransportType.esriGDSTransportTypeUrl)
    
    ' Force deletion of folder and contents if they exist.
    If Directory.Exists(outputDirectory) Then
        Directory.Delete(outputDirectory, True)
    End If
    
    ' Create the output folder.
    Directory.CreateDirectory(outputDirectory)
    
    ' Get the compressed data changes document from the uniform resource locatior (URL)
    ' to the local output directory.
    If gdsData.TransportType=esriGDSTransportType.esriGDSTransportTypeUrl Then
        Dim fileName As String=System.IO.Path.GetFileName(gdsData.URL)
        Dim outputFileName As String=System.IO.Path.Combine(outputDirectory, fileName)
        Dim wc As WebClient=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.")
    End If
    Catch comExc As COMException
    Throw New Exception(String.Format("Exporting the acknowledgement errored: {0}, Error Code: {1}", comExc.Message, comExc.ErrorCode), comExc)
    Catch exc As Exception
    Throw New Exception(String.Format("Exporting the acknowledgement errored: {0}", exc.Message), exc)
    End Try
    
End Sub

Importing an acknowledgement message into the relative replica

Complete the following steps to import an acknowledgement message into the relative replica:
  1. Connect to the geodatabase that hosts the replica that the acknowledgement message will be imported to. This requires initializing a GeoDataServer object. GeoDataServer objects allow access to a geodatabase on a LAN or WAN through ArcGIS for Server. 
  2. Call the following procedure by pasting it into an application and passing in the following parameters:
Parameter
Description
targetGDS
The GeoDataServer initialized in Step 1. This hosts the replica geodatabase into which the acknowledgement file will be imported.
inputDirectory
The inputDirectory specifies the location of the acknowledgement file. This location should point to the directory that holds the acknowledgement file. The function assumes that there is only one file in this directory. If there are more than one file in the input directory, only the first file will be read.

See the following code example:
[C#]
public void ImportAcknowledgement(IGeoDataServer targetGDS, String inputDirectory)
{
    try
    {
        // Make sure the input directory exists.
        if (!Directory.Exists(inputDirectory))
        {
            throw new DirectoryNotFoundException(String.Format(
                "Input directory could not be found: {0}", inputDirectory));
        }

        // Get the first file from the input directory.
        DirectoryInfo directoryInfo=new DirectoryInfo(inputDirectory);
        FileInfo[] fileInfoArray=directoryInfo.GetFiles();
        if (fileInfoArray.Length == 0)
        {
            throw new FileNotFoundException("No input files could be found.");
        }
        String inputFile=System.IO.Path.Combine(inputDirectory,
            fileInfoArray[0].Name);

        // Read the .xml file into a byte array to pass to the gdsData object.
        FileInfo fileInfo=new FileInfo(inputFile);
        long fileLength=fileInfo.Length;
        byte[] fileBytes=new Byte[fileLength];

        System.IO.FileStream fileStream=File.Open(inputFile, FileMode.Open,
            FileAccess.Read);
        BinaryReader binaryReader=new BinaryReader(fileStream);
        binaryReader.Read(fileBytes, 0, (int)fileLength);
        binaryReader.Close();
        fileStream.Close();

        // Embed the GDSData object.
        IGDSData gdsData=new GDSDataClass();
        gdsData.TransportType=esriGDSTransportType.esriGDSTransportTypeEmbedded;
        gdsData.Compressed=false;
        gdsData.set_EmbeddedData(ref fileBytes);

        // Import the acknowledgement file.
        targetGDS.ImportAcknowledgement(gdsData);
    }
    catch (COMException comExc)
    {
        throw new Exception(String.Format(
            "Importing the acknowledgement errored: {0}, Error Code: {1}",
            comExc.Message, comExc.ErrorCode), comExc);
    }
    catch (Exception exc)
    {
        throw new Exception(String.Format(
            "Importing the acknowledgement errored: {0}", exc.Message), exc);
    }
}
[VB.NET]
Public Sub ImportAcknowledgement(ByVal targetGDS As IGeoDataServer, ByVal inputDirectory As String)
    
    Try
    ' Make sure the input directory exists.
    If (Not Directory.Exists(inputDirectory)) Then
        Throw New DirectoryNotFoundException(String.Format("Input directory could not be found: {0}", inputDirectory))
    End If
    
    ' Get the first file from the input directory.
    Dim directoryInfo As DirectoryInfo=New DirectoryInfo(inputDirectory)
    Dim fileInfoArray As FileInfo()=directoryInfo.GetFiles()
    If fileInfoArray.Length=0 Then
        Throw New FileNotFoundException("No input files could be found.")
    End If
    Dim inputFile As String=System.IO.Path.Combine(inputDirectory, fileInfoArray(0).Name)
    
    ' Read the .xml file into a byte array to pass to the gdsData object.
    Dim fileInfo As FileInfo=New FileInfo(inputFile)
    Dim fileLength As Long=fileInfo.Length
    Dim fileBytes As Byte()=New Byte(CInt(fileLength - 1)) {}
    Dim fileStream As System.IO.FileStream=File.Open(inputFile, FileMode.Open, FileAccess.Read)
    Dim binaryReader As BinaryReader=New BinaryReader(fileStream)
    binaryReader.Read(fileBytes, 0, CInt(Fix(fileLength)))
    binaryReader.Close()
    fileStream.Close()
    
    ' Embed the GDSData object.
    Dim gdsData As IGDSData=New GDSDataClass()
    gdsData.TransportType=esriGDSTransportType.esriGDSTransportTypeEmbedded
    gdsData.Compressed=False
    gdsData.EmbeddedData=fileBytes
    
    ' Import the acknowledgement file.
    targetGDS.ImportAcknowledgement(gdsData)
    Catch comExc As COMException
    Throw New Exception(String.Format("Importing the acknowledgement errored: {0}, Error Code: {1}", comExc.Message, comExc.ErrorCode), comExc)
    Catch exc As Exception
    Throw New Exception(String.Format("Importing the acknowledgement errored: {0}", exc.Message), exc)
    End Try
    
End Sub






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine: Geodatabase Update