Extending the replication synchronization process


Purpose
Developers might want to extend the core replica behavior during synchronization. The synchronization process can be extended by implementing a workspace extension that supports IWorkspaceReplicaSyncEvents. By implementing this interface in an extension, custom behavior can be executed before and after any replica synchronization process executed on a geodatabase.
  • This sample describes the process using the example of a developer wanting to copy new raster datasets from a raster catalog during the synchronization. In this example, when synchronization is executed, the extension identifies and copies the new raster datasets from the source geodatabase to the target geodatabase.
  • This sample is for connected synchronization where connections are made to local geodatabases.
  • This sample can be used as a reference for developers needing to extend synchronization for any reason.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

Preparing the data
  1. This sample requires that the raster catalog has a long integer column named "gen." If the replica has been created and has that column, proceed with Step 7 in this section.
  2. Open the parent raster catalog to be synchronized in ArcMap.
  3. Add the gen column to the raster catalog using the Add Field option in the attribute table.
  4. Set the value of the gen column for any existing raster datasets in the raster catalog to 0. The field calculator can be used to do this quickly.
  5. Repeat Steps 2-4 for the child raster catalog.
  6. Create a replica of the raster catalog. For more information, see "How to create a replica in a connected environment" in the See Also section in this topic. The creation process copies the raster catalog and the raster datasets that intersect the replica geometry by default. To create the replica, at least one versioned feature class with edit permission must also be included in the replica. It is not possible to create a replica consisting only of the raster dataset.
  7. Once the replica exists, make sure that the raster catalog exists in the parent and the child replica geodatabases, and that each has a long integer column named gen.
  8. If there are common raster datasets, set the value in the gen column to 0 for the common datasets in the parent and child replica geodatabases.

Building the extension
  1. Once the data is prepared, build the extension and register it with the replica geodatabases by doing the following steps.
  2. Copy the solution locally and open the solution.
  3. Open the RasterSyncWorkspaceExtension.cs (if working in C#) or RasterSyncWorkspaceExtension.vb (if working in VB .NET) source file.
  4. There are two member variables in the extension that can be adjusted. The rasterCatalog variable (a private constant string, currently set to "ras_cat") is the name of the raster catalog to involve in the synchronization. By changing this value before building the assembly, the synchronized raster catalog can be changed.
  5. The other variable is the replica variable (a private constant string, currently set to "myreplicaras"), which is the name of the replica whose synchronization event triggers this behavior. By changing this value before building the assembly, the replica with extended behavior can be changed.
  6. Right-click the project and choose build. This creates the assembly in the project's debug or release directory (depending on the selected option).

Applying the extension to one or more geodatabases
  1. Which geodatabase or geodatabases require the workspace extension depends on the type of replica being used. For one-way parent-to-child replication, both geodatabases involved with the replica requires the extension. For two-way replication, both geodatabases involved with the replica requires the extension. The RasterSynchExtensionReg* project compiles to an executable that registers the workspace extension with a geodatabase.
  2. Right-click the RasterSyncExtensionReg* project and choose Set as StartUp Project.
  3. Open RegisterExtension.cs.
  4. Change the RegisterExtension.workspacePath value to the path of an SDE connection file or local geodatabase that has the extension applied to it.
  5. Change the RegisterExtension.geodatabaseType value to reflect the type of geodatabase that the extension is being registered on.
  6. Right-click the project and choose build.
  7. Press F5 to run the project.
  8. Doing Steps 2-7 in this section registers the extension with one of the replica geodatabases. If two-way replication is being used, repeat these steps for the other replica geodatabase. Once this is completed, synchronizing the replica identified in the previous steps executes the extension.

Using the extension
  1. Synchronizing the replica associated with the extension using the wizards, or the geoprocessing tools in ArcCatalog or ArcMap triggers the extension's behavior. To test this, assuming that a two-way replica is being used, do the following steps.
  2. Load one or more new raster datasets into the raster catalog in the parent geodatabase. When this is done, the gen column has a null value for the new raster datasets.
  3. In the same way, load one or more new raster datasets into the raster catalog in the child.
  4. In ArcCatalog, connect to the parent replica geodatabase and synchronize from the parent to the child. Notice that a value is assigned to the gen column of the new raster datasets. This is the generation number of the synchronization in which the raster datasets were sent.
  5. In ArcCatalog, connect to the child replica geodatabase and preview the raster catalog. Notice that the raster datasets from the parent have been applied and have a gen value of –1. The –1 value indicates that these have been received from the parent.
  6. In ArcCatalog, synchronize from the child to the parent. Notice that the raster datasets that were added to the child in Step 3 were applied to the parent and the values in the gen column for these datasets were adjusted.
  7. As raster datasets are added and synchronized, the parent and child are kept up to date with the new raster datasets. The extension also supports cases where (for any reason) synchronization fails. Here, the generation information in the gen column is used to determine if rasters need to be resent.

Additional information

Expanding the sample

The main goal of the sample is to show how to extend replica synchronization. There are a number of enhancements that can be added to support your specific requirements. Some of these include the following:
  • Disconnected replication—The sample does not work in cases where you are performing disconnected synchronization where changes are synchronized using delta files. If you use disconnected synchronization, the raster catalog is ignored.
    • To extend the sample to cover this case, you can implement the AfterExportingDataChanges event in the extension. This event is called when you run the export data changes command. Here, you can use the same logic from the AfterSynchronizingDataChanges event handler to copy the raster datasets to a local file geodatabase. This can then be copied with the delta file to a location accessible by the target replica geodatabase. When the data file is imported, you can add code to the AfterSynchronizingDataChanges event, which is also called with the import message command. This code can import the raster datasets from the local file geodatabase.
  • Multiple replicas—This sample is for a single replica. Implementing it for several replicas involves creating a gen column per replica.
  • Multiple raster catalogs—This sample is for a single raster catalog. Implementing it for several raster catalogs involves adding enhancements to keep track of which raster catalogs to synchronize.
  • Replication using geodata services and ArcGIS Server—This sample does not work in this environment. Synchronizing using geodata services and ArcGIS Server ignores the raster catalog. In this case, you can use similar techniques as previously described for disconnected replication since the server uses delta files to synchronize changes.
  • Creating a workspace property page—To avoid hard coding the values, such as the replica and raster dataset name, a property page can be created that gets and sets the values from a private table.


RasterSyncExtension/RasterSyncWorkspaceExtension.cs A workspace extension that extends the synchronization process.
RasterSyncExtensionReg/RegisterExtension.cs A console application that registers the extension with a geodatabase.
Download the C# files
RasterSyncExtension/RasterSyncWorkspaceExtension.vb A workspace extension that extends the synchronization process.
RasterSyncExtensionReg/RegisterExtension.vb A console application that registers the extension with a geodatabase.
Download the VB.NET files

Download the files for all languages

See Also:

How to create a replica in a connected environment




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