Select to view content in your preferred language

[.Net] How to find GIS diff after one way replication?

712
3
04-12-2013 11:04 AM
GaryMontgomery
Emerging Contributor
The scenario is I have a one way replication from one ArcSDE to another. I would like to run a daily task that will look into the target ArcSDE with ArcObjects and find what is new since the last sync and then run business logic on that set of data.

My understanding was that replication was bult on versioning and that each sync would create a new version. I already have plenty of sample code on how to get the diff between two versions.  But what I have found is that on the target SDE the default version gets updated inline. There is not a new version created.

After much searching it looks like the ReplicationDataChanges or DataChanges classes might be what I am looking for but I have not been able to find much detail on usage or example data.

1. Am I on the correct path for what I want to do?
2. Can you point me toward any sample code?

Thank you,
Gary
0 Kudos
3 Replies
GaryMontgomery
Emerging Contributor
As I continue to investigate I found the following on Archiving. Possibly this is the way to go?

http://resources.arcgis.com/en/help/main/10.1/index.html#/Geodatabase_archiving/003n000000sr000000/
0 Kudos
DrewDowling
Frequent Contributor
Replication uses versions to control changes but these versions are hidden and the names change continually behind the scenes when replicas are synced. Writing code to compare these can get tricky because you need your code to test for the current hidden replica parent version name.

What way are you replicating? If changes are pushed from child to parent you could make a child version off of SDE.Default in the parent geodatabase (e.g. call it ReplicaSource) . Then make the replica using this version, ReplicaSource, as the parent.

Now when replicas are synced changes will go to the ReplicaSource version in the parent SDE database and not SDE.Default. So you can use the well documented ArcObjects classes to compare versions, ReplicaSource to SDE.Default, instead of having to compare replicas.

Archiving might also work but it will not tell you what version created what feature, it will only tell you when a feature was created or changed.
0 Kudos
GaryMontgomery
Emerging Contributor
Replication uses versions to control changes but these versions are hidden and the names change continually behind the scenes when replicas are synced. Writing code to compare these can get tricky because you need your code to test for the current hidden replica parent version name.

What way are you replicating? If changes are pushed from child to parent you could make a child version off of SDE.Default in the parent geodatabase (e.g. call it ReplicaSource) . Then make the replica using this version, ReplicaSource, as the parent.

Now when replicas are synced changes will go to the ReplicaSource version in the parent SDE database and not SDE.Default. So you can use the well documented ArcObjects classes to compare versions, ReplicaSource to SDE.Default, instead of having to compare replicas.

Archiving might also work but it will not tell you what version created what feature, it will only tell you when a feature was created or changed.


Thank you, Drew.  Replication is from parent to child (one way) and we do not own the parent. I think for our needs, archiving on the child is going to do the trick. Below is the basic idea in case it is helpful to others.

            // Cast to the IHistoricalWorkspace interface and get default version and the version as of the start of the day
            IHistoricalWorkspace historicalWorkspace = (IHistoricalWorkspace)workspace;         
            IHistoricalVersion defaultVersion = historicalWorkspace.FindHistoricalVersionByName(historicalWorkspace.DefaultMarkerName);
            IHistoricalVersion historicalVersion = historicalWorkspace.FindHistoricalVersionByTimeStamp(DateTime.Today);

            // Cast both versions to IFeatureWorkspace and open the table from each.
            IFeatureWorkspace defaultFWS = (IFeatureWorkspace)defaultVersion;
            IFeatureWorkspace historicalFWS = (IFeatureWorkspace)historicalVersion;
            ITable defaultTable = defaultFWS.OpenTable(tableName);
            ITable historicalTable = historicalFWS.OpenTable(tableName);

            // Create a difference cursor to compare what has happened since the start of the day
            IVersionedTable versionedTable = (IVersionedTable)defaultTable;
            IDifferenceCursor differenceCursor = versionedTable.Differences(historicalTable, differenceType, null);
0 Kudos