How to synchronize an acknowledgement message in a disconnected environment


Summary This article demonstrates 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).

Development licensing Deployment licensing
ArcEditor ArcEditor
ArcInfo ArcInfo
Engine Developer Kit Engine Runtime: Geodatabase Update

To use the code in this article, the following namespaces must be referenced via the using (C#) or Imports (VB.NET) statements. It is also necessary to add the corresponding references to the project in order to gain access to these APIs.

In this topic

 

Exporting 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 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 an application and passing in the following parameters:
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 doesn't exist, it will be created.

[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 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 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

  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 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 an application and passing in the following parameters:
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 which 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.
 

[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 .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 .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