AnsweredAssumed Answered

Exporting and importing versions delta changes (ArcSDE, ArcObjects)

Question asked by northpole on Aug 14, 2014
Latest reply on Aug 29, 2014 by vangelo-esristaff

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);
            }
        }

Outcomes