[GIS] ArcObjects IConflictsWindow3 not seeing version reconciliation conflicts

arcobjectscversioning

We are working on a reconcile and post add-in for one of our departments. I'm able to successfully complete the task if there are no conflicts or if I specify which version 'wins'. We would like to utilize the integrated ArcMap functionality for conflict display and resolution.

Unfortunately, when trying to display the conflict window, I'm having issues. First of all, the conflict window does not specify that there are any conflict classes even though the IVersionEdit4 object specifies there are and the reconcile result is 'true'. Secondly, if I try to display the conflict window anyway, the window opens and ArcMap crashes–even if I surround the code in a try block.

I'm open to suggestions. I am not particularly interested in manually finding the sources of the conflict when the functionality is there to accomplish the task in ArcMap natively and the code is exposed in ArcObjects to accomplish the task.

Am I missing something? Do I need to somehow assign which class the conflict is to the window?

Here's the code in question:

    bool ReconcileToDefault(Version ToReconcile, out bool? hadConflicts)
    {
        ChangeDataSourceToDefault(ToReconcile); //changes datasources in map document to default version to prevent lock issues
        hadConflicts = null;
        IVersionedWorkspace wkspc = (IVersionedWorkspace)DBConnect.ConnectToDB("sde.DEFAULT", true);
        if (wkspc == null) return false;
        IVersion Reconcile = wkspc.FindVersion(ToReconcile.name);
        //EventListener evtListener = new EventListener(Reconcile);
        IMultiuserWorkspaceEdit muWorkspaceEdit = (IMultiuserWorkspaceEdit)Reconcile;
        IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)Reconcile;
        IVersionEdit4 versionEdit = (IVersionEdit4)muWorkspaceEdit;
        muWorkspaceEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned);
        workspaceEdit.StartEditOperation();
        //Open the conflict resolution window. (ArcMap bombs out here, so I'm trying a different way)
        //if (cWin == null)
        //{
        //    IEditor editor = (IEditor)ArcMap.Application.FindExtensionByCLSID(new UID() { Value = "esriEditor.Editor" });
        //    cWin = (IConflictsWindow3)editor.FindExtension(new UID() { Value = "esriEditor.ConflictsWindow" });
        //    cWin.Reset();
        //    cWin.Visible = true;
        //}
        hadConflicts = versionEdit.Reconcile4("sde.DEFAULT", false, false, false, true); //I set acquire locks to true if I'm actually posting.
        if (hadConflicts == true)
        {
            versionEdit.ConflictClasses.Reset();
            var cl = ConflictResolutionDialog.CurrentClass; //variable is null with current database state
            IConflictClass first = versionEdit.ConflictClasses.Next(); //variable is a valid IConflictClass with current database state
            //MessageBox.Show(ConflictResolutionDialog.HasConflicts().ToString()); //displays false
            //MessageBox.Show(String.Format("Had {0} Conflicts.",ConflictResolutionDialog.ClassCount)); //conflict count = 0
            //ConflictResolutionDialog.Visible = true; //causes arcmap to crash
        }
        //versionEdit.Post("sde.DEFAULT"); //works just fine
        workspaceEdit.StopEditOperation();
        workspaceEdit.StopEditing(false);//generally set this to true if I post
        return true;
    }

Thanks for your attention,

Best Answer

It took me longer than desired to leverage the OP along with the answer from @Ragi to get the conflicts window to populate, probably due to my obtuseness. For others in the same boat, here is a code sample that checks for version conflicts in a reconcile, and then displays the conflicts window when conflicts were found.

// get editor reference
ESRI.ArcGIS.esriSystem.UID editorUid = new ESRI.ArcGIS.esriSystem.UID() { Value = "esriEditor.Editor" };
ESRI.ArcGIS.Editor.IEditor editor = (ESRI.ArcGIS.Editor.IEditor)_application.FindExtensionByCLSID(editorUid);

// get reference to current edit workspace
ESRI.ArcGIS.Geodatabase.IWorkspace editWorkspace = editor.EditWorkspace;
ESRI.ArcGIS.Geodatabase.IVersionEdit4 versionEdit = (ESRI.ArcGIS.Geodatabase.IVersionEdit4)editWorkspace;

// get parent version name
string parentVersionName = ((ESRI.ArcGIS.Geodatabase.IVersion)editWorkspace).VersionInfo.Parent.VersionName;
// reconcile to parent, with locks, not aborting on conflict to allow for conflict resolution
bool hadConflicts = versionEdit.Reconcile3(parentVersionName, true, false);
if (hadConflicts)
{
    // get conflicts window reference
    ESRI.ArcGIS.esriSystem.UID conflictsUid = new ESRI.ArcGIS.esriSystem.UID() { Value = "esriEditor.ConflictsWindow" };
    ESRI.ArcGIS.Editor.IConflictsWindow3 conflictsWindow = (ESRI.ArcGIS.Editor.IConflictsWindow3)editor.FindExtension(conflictsUid);
    // reset appears to load the conflicts into the window
    conflictsWindow.Reset();
    // show conflicts window
    conflictsWindow.Visible = true;
}
Related Question