| Development licensing | Deployment licensing |
|---|---|
| ArcEditor | ArcEditor |
| ArcInfo | ArcInfo |
| Engine Developer Kit | Engine Runtime: Geodatabase Update |
|
sourceGDS
|
The GeoDataServer 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 a 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.
|
public void ExportReplicaDataChanges(IGeoDataServer sourceGDS, String
replicaName, String outputDirectory)
{
try
{
// Set the export options.
GDSExportOptions 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);
}
}
Public Sub ExportReplicaDataChanges(ByVal sourceGDS As IGeoDataServer, ByVal replicaName As String, ByVal outputDirectory As String)
Try
' Set the export options.
Dim gdsExportOptions As 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.
Dim gdsData As IGDSData = sourceGDS.ExportReplicaDataChanges(replicaName, gdsExportOptions, esriGDSTransportType.esriGDSTransportTypeUrl, esriExportGenerationsOption.esriExportGenerationsAll, False)
' 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 data changes errored: {0}, Error Code: {1}", comExc.Message, comExc.ErrorCode), comExc)
Catch exc As Exception
Throw New Exception(String.Format("Exporting data changes errored: {0}", exc.Message), exc)
End Try
End Sub
|
targetGDS
|
The geodataserver initialized in Step 1. This hosts the replica geodatabase that will store 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.
|
public void ImportReplicaDataChanges(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 = true;
gdsData.set_EmbeddedData(ref fileBytes);
// Import the data changes.
targetGDS.ImportReplicaDataChanges
(esriGDSReplicaImportSource.esriGDSReplicaImportSourceDeltaXmlFile,
esriReplicaReconcilePolicyType.esriReplicaDetectConflicts, true, gdsData);
}
catch (COMException comExc)
{
throw new Exception(String.Format(
"Importing data changes errored: {0}, Error Code: {1}", comExc.Message,
comExc.ErrorCode), comExc);
}
catch (Exception exc)
{
throw new Exception(String.Format("Importing data changes errored: {0}",
exc.Message), exc);
}
}
Public Sub ImportReplicaDataChanges(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 = True
gdsData.EmbeddedData = fileBytes
' Import the data changes.
targetGDS.ImportReplicaDataChanges(esriGDSReplicaImportSource.esriGDSReplicaImportSourceDeltaXmlFile, esriReplicaReconcilePolicyType.esriReplicaDetectConflicts, True, gdsData)
Catch comExc As COMException
Throw New Exception(String.Format("Importing data changes errored: {0}, Error Code: {1}", comExc.Message, comExc.ErrorCode), comExc)
Catch exc As Exception
Throw New Exception(String.Format("Importing data changes errored: {0}", exc.Message), exc)
End Try
End Sub