Exporting and importing versions delta changes (ArcSDE, ArcObjects)

1616
4
08-14-2014 05:17 AM
Highlighted
New Contributor II

I am working on ArcObjects code snippet to export the delta
changes in two versions in one ArcSDE environment and then importing the output
file as delta changes in another environment. I am using a modified version of
code from ESRI documentation link ‘http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//00010000019v000000’.
Below is the code snippet that I am calling in my application. It is executing
fine without any error but I am unable to see the imported changes.

Can you kindly provide an insight on where I might be
deviating from the ESRI documentation or if the code is not going through as
per design and expected output? I am using ArcObjects/ArcGIS Desktop 10.2.1 and
the code is based on c# on Windows 7 OS.

public void exportDeltaChanges(IWorkspace sourceWorkspace, IWorkspace targetWorkspace, string outputXMLFilePathName,                IWorkspace newWorkspace)

        {

            try

            {

                // Create the source dataset object.

                IDataset sourceDS = (IDataset)sourceWorkspace;

                IWorkspaceName sourceWorkspaceName = (IWorkspaceName)sourceDS.FullName;

                //Create a name object for the target workspace.

                IDataset dataset = (IDataset)targetWorkspace;

                IWorkspaceName targetWorkspaceName = (IWorkspaceName)dataset.FullName;

                IDataset newDS = (IDataset)newWorkspace;

                IWorkspaceName newWorkspaceName = (IWorkspaceName)newDS.FullName;

                VersionDataChanges vdc = new VersionDataChangesClass();

                IVersionDataChangesInit versionDataChangesInit = (IVersionDataChangesInit)vdc;

                versionDataChangesInit.Init(sourceWorkspaceName, targetWorkspaceName);

                IDataChanges dataChanges = (IDataChanges)vdc;

                //Listing modified feature classes and tables in a version

                IEnumModifiedClassInfo enumModifiedFCsInfo = dataChanges.GetModifiedClassesInfo();

                string modifiedFC = "";

                int modifiedFCCounter = 0;

                updateStatus("\n\n Listing Feature Modified Classes \n", messageImportance.Information);

                var modifedClassInfo = enumModifiedFCsInfo.Next();

                while (modifedClassInfo != null)

                {

                    modifiedFCCounter += 1;

                    modifiedFC = modifedClassInfo.ChildClassName;

                    //Status message. Can be replaced with MessageBox.show("") method

                    updateStatus("\n\t\t " + modifiedFCCounter.ToString() + ": " +                          modifiedFC, messageImportance.Information);

                    modifedClassInfo = enumModifiedFCsInfo.Next();

                }

                if (modifiedFCCounter == 0)

                {

                    updateStatus("No changes found in this version", messageImportance.Warning);

                    return;

                }

                String tempDirectory = "D:\\temp";

                String deltaFile = Path.Combine(tempDirectory, outputXMLFilePathName);

                //Check if file exists and clean

                if(!File.Exists(deltaFile))

                {

                    updateStatus("\nOutput path: " + deltaFile + "\n", messageImportance.Information);

                    IExportDataChanges dataChangesExporter = new DataChangesExporterClass();

                    dataChangesExporter.ExportDataChanges(deltaFile, esriExportDataChangesOption.esriExportToXML,                          dataChanges, true);

                    //Status message. Can be replaced with MessageBox.show("") method

                    updateStatus("\n\tVersion delta exported successfully", messageImportance.Important);

                }

                else

                {

                    bool isFileDeleted = File.Delete(deltaFile);

                    if (isFileDeleted)

                    {

                        updateStatus("\nOutput path: " + deltaFile + "\n", messageImportance.Information);

                        IExportDataChanges dataChangesExporter = new DataChangesExporterClass();

                      
                        dataChangesExporter.ExportDataChanges(deltaFile, esriExportDataChangesOption.esriExportToXML,                               dataChanges, true);

                        //Status message. Can be replaced with MessageBox.show("") method

                        updateStatus("\n\tVersion delta exported successfully", messageImportance.Important);

                    }

                    else

                    {

                        //Status message. Can be replaced with MessageBox.show("") method

                        updateStatus("Output file path name: " + deltaFile + " already exists, please delete or change                               output filename to proceed", messageImportance.Error);

                        return;

                    }

                }

               // Update user about importing the updategram into the target workspace.

               //Status message. Can be replaced with MessageBox.show("") method

                updateStatus("\nImporting data into new environment: '"+ newWorkspaceName.PathName + "'",
                    messageImportance.Important);

                // Import the updategram into the target workspace.

                IDeltaDataChanges deltaDataChanges = new DeltaDataChangesClass();

                IDeltaDataChangesInit2 deltaDataChangesInit2 = (IDeltaDataChangesInit2) deltaDataChanges;


               deltaDataChangesInit2.Init2(deltaFile,
esriExportDataChangesOption.esriExportToXML, false);

                IImportDataChanges importDataChanges = new DataChangesImporterClass();

               importDataChanges.ImportDataChanges(newWorkspaceName, deltaDataChanges, false, true);

                // Update user about operation successful completion.

                //Status message. Can be replaced with MessageBox.show("") method

                updateStatus("\nData import successful into the new environment:'" + newWorkspaceName.PathName +                     "'", messageImportance.Important);

            }

            catch(COMException comExc)

            {

                reportComException(comExc);

            }

            catch (Exception exc)

            {

                reportException(exc);

            }

        }

Reply
0 Kudos
4 Replies
Highlighted
New Contributor II

Hi,

No answer to the post yet... I am still feeling desperate about it.

Vince Angelo‌ and Melita Kennedy‌ your opinion would be heighly appreciated. Thanks in advance for your time and support.

Regards.

Reply
0 Kudos
Highlighted
Esri Notable Contributor

Hi Britt,

I personally don't have enough ArcObjects nor geodatabase knowledge to be able to figure out what's wrong in the code or to suggest another solution. Now that I have some SuperModPowers!, I'm going to try to move the thread into the Developers area where hopefully it will get more eyes on it.

Meanwhile, is there any chance you could try to clean up the code? At least when I look at it, it's wrapped and difficult to read. I tried to edit it, and got weirdly overlapping lines so I quit before I made it worse.

Melita

Reply
0 Kudos
Highlighted
New Contributor II

Thanks Milita for your quick response and tips. I have done some cleanup now and you are right, syntax highlighting feature mixes/double up stuff and it is hard to cleanup.

Vince seems to have worked on this matter as mentioned in one of his threads which unfortunately I am unable to find now. I would wait to see if he has any comments in this regard.

Many thanks again.

Reply
0 Kudos
Highlighted
Esri Esteemed Contributor

Please don't wait for me to comment on subjects outside my domain of expertise. If I don't answer, it's usually because I don't think my answer would contribute to the discussion at hand.

While the GeoNet has the ability to draw my attention to questions, it cannot give me the ability to answer all of them.

- V

Reply
0 Kudos