Version Differences

2908
7
Jump to solution
01-02-2020 05:03 PM
JimmyBowden
Occasional Contributor II

ArcGIS Pro version is 2.4.3 and SDE for .NET version 2.4.0.19948. A couple of months ago I asked about using ArcGIS Pro sdk to Get all edits in a version.  I'm testing this code against and Oracle 12.1 database and I'm seeing invalid results.  In the image below the OOTB version changes tool is showing 13 edits in the current version. I ran my code with and selected by objectid each layer on the map and I get 8 changes in the version (updates only).  Is there something different that needs to be done to get the objectids of Deletes/Updates?

I tried a second example version this time it OOTB tool shows 1 edit and I get 106,067 changes in the version.  My assumption that a reconcile might help this and it does, after reconcile it correctly shows the one edit.  Question two is it expected that I would add code to reconcile before checking for changes?  The SDK WIKI doesn't mention that it might be necessary to reconcile.

TIA, Jimmy

0 Kudos
1 Solution

Accepted Solutions
JimmyBowden
Occasional Contributor II

Yes I am using traditional versioning and yes currently only working with direct children of default.  

I finally think I see what's happening

 using (DifferenceCursor differenceCursor = defaultFc.Differences(versionFc, differenceType))

As Default "hey version what changes do I have that you don't know about" (everything you haven't reconciled yet plus your updates)

What I want to do is As Version "hey Default what changes do I have that you don't know about" (everything changed in the version but haven't post):

 using (DifferenceCursor differenceCursor = versionFc.Differences(defaultFc, differenceType))

View solution in original post

7 Replies
RichRuh
Esri Regular Contributor

Hi Jimmy,

Could you please share a code snippet showing how you are getting version differences?

Thanks, 

--Rich

0 Kudos
JimmyBowden
Occasional Contributor II

Get the version from the first feature layer in the TOC and feature class names from all feature layers in the TOC

  public List<VersionChanges> GetChanges(Version version, List<string> featureclassnames)
        {
            List<VersionChanges> retval = new List<VersionChanges>();
            
            using (Geodatabase versiongdb = version.Connect())
            {
                var defaultversion = versiongdb.GetVersionManager().GetVersions().First(v => v.GetParent() == null);
                using (Geodatabase g = defaultversion.Connect())
                {
                    foreach (var item in featureclassnames)
                    {
                        var versionchanges = GetVersionChangesByFeatureClass(g, versiongdb, item);
                        if (versionchanges != null)
                            retval.Add(versionchanges);
                    }
                }
            }
            return retval;
        }

        private VersionChanges GetVersionChangesByFeatureClass(Geodatabase g, Geodatabase versiongdb, string featureclassname)
        {
            try
            {
                using (FeatureClass defaultFc = g.OpenDataset<FeatureClass>(featureclassname))
                {
                    using (FeatureClass versionFc = versiongdb.OpenDataset<FeatureClass>(featureclassname))
                    {
                        var rtype = versionFc.GetRegistrationType();
                        if (rtype.Equals(RegistrationType.Nonversioned))
                            return null;
                        List<VersionChange> diffs = GetAllDifferences(defaultFc, versionFc);
                        return new VersionChanges { featureClassName = featureclassname, Changes = diffs };
                    }
                }
            }
            catch (GeodatabaseEnterpriseException)
            {
                //Table is not versioned
                return null;
            }
            catch (GeodatabaseTableException)
            {
                //Table not found 
                return null;
            }

        }

        //https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Geodatabase#versioning
        private List<VersionChange> GetAllDifferences(FeatureClass defaultFc, FeatureClass versionFc)
        {
            List<VersionChange> retval = new List<VersionChange>();
            retval.AddRange(GetDifferences(defaultFc, versionFc, DifferenceType.DeleteNoChange));
            retval.AddRange(GetDifferences(defaultFc, versionFc, DifferenceType.DeleteUpdate));
            retval.AddRange(GetDifferences(defaultFc, versionFc, DifferenceType.Insert));
            retval.AddRange(GetDifferences(defaultFc, versionFc, DifferenceType.UpdateDelete));
            retval.AddRange(GetDifferences(defaultFc, versionFc, DifferenceType.UpdateNoChange));
            retval.AddRange(GetDifferences(defaultFc, versionFc, DifferenceType.UpdateUpdate));

            return retval;
        }

        private List<VersionChange> GetDifferences(FeatureClass defaultFc, FeatureClass versionFc, DifferenceType differenceType)
        {
            List<VersionChange> retval = new List<VersionChange>();
            using (DifferenceCursor differenceCursor = defaultFc.Differences(versionFc, differenceType))
            {
                List<long> diffs = new List<long>();
                while (differenceCursor.MoveNext())
                {
                    diffs.Add(differenceCursor.ObjectID);
                }
                retval.AddRange(diffs.Select(s => new VersionChange { objectId = s, differenceType = differenceType }));
            }
            return retval;
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

public class VersionChange
    {
        public DifferenceType differenceType { get; set; }
        
        public long objectId { get; set; }
    }

    public class VersionChanges
    {
        public string featureClassName { get; set; }
        public List<VersionChange> Changes {get;set;}
    }
0 Kudos
RichRuh
Esri Regular Contributor

Thanks, Jimmy.  I'll dig into this over the next few days.

0 Kudos
JimmyBowden
Occasional Contributor II

I've added this code after line 8:

var rd = new ReconcileDescription
 {
 WithPost = false
 };
 version.Reconcile(rd);

I am now consistently getting the correct updates but not any inserts or deletes.  The primary database is Oracle 12.1.  I have also confirmed that it behaves the same in postgres 11.2

0 Kudos
RichRuh
Esri Regular Contributor

Hi Jimmy,

I've reviewed all of your code and cannot find anything wrong.  You shouldn't have to reconcile to get version differences (and of course, if you do, you'll get a different list).

Some questions:

  • Can I assume you are using traditional versioning, and not branch versioning?
  • Is the version you are trying to get differences for a direct child of Default? (as opposed to a grand-child)

--Rich

p.s. This line of code is going to create, but not dispose, of a large number of Version objects, along with the VersionManager:

var defaultversion = versiongdb.GetVersionManager().GetVersions().First(v => v.GetParent() == null);

It should have no impact whatsoever on your test results, but I recommend using the snippet found here.

Again, this is completely independent from the results you're seeing- just noticed it and thought I would mention it.

0 Kudos
JimmyBowden
Occasional Contributor II

Yes I am using traditional versioning and yes currently only working with direct children of default.  

I finally think I see what's happening

 using (DifferenceCursor differenceCursor = defaultFc.Differences(versionFc, differenceType))

As Default "hey version what changes do I have that you don't know about" (everything you haven't reconciled yet plus your updates)

What I want to do is As Version "hey Default what changes do I have that you don't know about" (everything changed in the version but haven't post):

 using (DifferenceCursor differenceCursor = versionFc.Differences(defaultFc, differenceType))
RichRuh
Esri Regular Contributor

I totally missed that.  Nice catch!

0 Kudos