private void ImportXmlWorkspaceDocument(string inputXmlFile) { IWorkspaceName targetWorkspaceName = getWorkspaceName("esriDataSourcesGDB.SdeWorkspaceFactory", sdePath); IName targetName = (IName)targetWorkspaceName; IWorkspace targetWorkspace = (IWorkspace)targetName.Open(); IGdbXmlImport gdbXmlImport = new GdbImporterClass(); IEnumNameMapping enumNameMapping = null; Boolean conflictsFound = gdbXmlImport.GenerateNameMapping(inputXmlFile, targetWorkspace, out enumNameMapping); // Check for conflicts. if (conflictsFound) { // Iterate through each name mapping. INameMapping nameMapping = null; enumNameMapping.Reset(); while ((nameMapping = enumNameMapping.Next()) != null) { // Resolve the mapping's conflict (if there is one). if (nameMapping.NameConflicts) { nameMapping.TargetName = nameMapping.GetSuggestedName(targetName); } // See if the mapping's children have conflicts. IEnumNameMapping childEnumNameMapping = nameMapping.Children; if (childEnumNameMapping != null) { childEnumNameMapping.Reset(); // Iterate through each child mapping. INameMapping childNameMapping = null; while ((childNameMapping = childEnumNameMapping.Next()) != null) { if (childNameMapping.NameConflicts) { childNameMapping.TargetName = childNameMapping.GetSuggestedName(targetName); } } } } } // Import the workspace document, including both schema and data. gdbXmlImport.ImportWorkspace(inputXmlFile, enumNameMapping, targetWorkspace, false); }
public static void ExportDatabase(IWorkspace theWorkspace) { // Try and make sure the user understands what they're doing MessageBox.Show("You must first browse to a previously generated, empty geodatabase.", "NCGMP Tools"); // Browse for a file, personal or SDE geodatabase IWorkspaceFactory wsFact = null; IWorkspace openedWorkspace = null; IGxObjectFilter objectFilter = new GxFilterWorkspaces(); IGxObject openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an empty database"); if (openedObject == null) { return; } // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory string pathToOpen = null; switch (openedObject.Category) { case "Personal Geodatabase": wsFact = new AccessWorkspaceFactoryClass(); pathToOpen = openedObject.FullName; break; case "File Geodatabase": wsFact = new FileGDBWorkspaceFactoryClass(); pathToOpen = openedObject.FullName; break; case "Spatial Database Connection": wsFact = new SdeWorkspaceFactoryClass(); IGxRemoteDatabaseFolder remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent; pathToOpen = remoteDatabaseFolder.Path + openedObject.Name; break; default: break; } openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0); // Okay, now export the current database to an XML doc string tempFilePath = System.IO.Path.GetTempFileName(); tempFilePath += ".xml"; IGdbXmlExport xmlExporter = new GdbExporterClass(); xmlExporter.ExportWorkspace(theWorkspace, tempFilePath, true, false, false); // Import to the new database // Use the temp file to perform the import IGdbXmlImport xmlImporter = new GdbImporterClass(); IEnumNameMapping enumNameMapping = null; bool conflictsFound = xmlImporter.GenerateNameMapping(tempFilePath, openedWorkspace, out enumNameMapping); try { // Deal with conflicts (lifted wholesale from http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/00010000011m000000.htm) if (conflictsFound) { IName workspaceName = ((IDataset)openedWorkspace).FullName; // Iterate through each name mapping. INameMapping nameMapping = null; enumNameMapping.Reset(); while ((nameMapping = enumNameMapping.Next()) != null) { // Resolve the mapping's conflict (if there is one). if (nameMapping.NameConflicts) { nameMapping.TargetName = nameMapping.GetSuggestedName(workspaceName); } // See if the mapping's children have conflicts. IEnumNameMapping childEnumNameMapping = nameMapping.Children; if (childEnumNameMapping != null) { childEnumNameMapping.Reset(); // Iterate through each child mapping. INameMapping childNameMapping = null; while ((childNameMapping = childEnumNameMapping.Next()) != null) { if (childNameMapping.NameConflicts) { childNameMapping.TargetName = nameMapping.GetSuggestedName (workspaceName); } } } } } // Perform the import xmlImporter.ImportWorkspace(tempFilePath, enumNameMapping, openedWorkspace, false); } catch (Exception ex) { MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine + "XML Workspace Doc written to: " + tempFilePath); } // Perhaps, strip the SysInfo table }
private void method_1() { this.listView1.Items.Clear(); this.ienumNameMapping_0.Reset(); INameMapping mapping = this.ienumNameMapping_0.Next(); string[] items = new string[3]; while (mapping != null) { ListViewItem item; if (mapping.SourceObject is IDomain) { IDomain sourceObject = mapping.SourceObject as IDomain; if (sourceObject.Type == esriDomainType.esriDTCodedValue) { items[0] = "CV域"; } else { items[0] = "范围域"; } items[1] = sourceObject.Name; if (mapping.NameConflicts) { mapping.TargetName = mapping.GetSuggestedName(this.iname_0); } items[2] = mapping.TargetName; item = new ListViewItem(items) { Tag = mapping }; this.listView1.Items.Add(item); } else if (mapping.SourceObject is IName) { IName name = mapping.SourceObject as IName; items[0] = this.method_0(name); items[1] = (name as IDatasetName).Name; if (mapping.NameConflicts) { mapping.TargetName = mapping.GetSuggestedName(this.iname_0); } items[2] = mapping.TargetName; item = new ListViewItem(items) { Tag = mapping }; this.listView1.Items.Add(item); IEnumNameMapping children = mapping.Children; if (children != null) { children.Reset(); for (INameMapping mapping3 = children.Next(); mapping3 != null; mapping3 = children.Next()) { name = mapping3.SourceObject as IName; items[0] = " " + this.method_0(name); items[1] = (name as IDatasetName).Name; if (mapping3.NameConflicts) { mapping3.TargetName = mapping3.GetSuggestedName(this.iname_0); } items[2] = mapping3.TargetName; item = new ListViewItem(items) { Tag = mapping3 }; this.listView1.Items.Add(item); } } } mapping = this.ienumNameMapping_0.Next(); } }
public void TansferFileGDBToSDE(string fileGDBPath, string sourceFCName) { // Create workspace name objects. IWorkspaceName sourceWorkspaceName = getWorkspaceName("esriDataSourcesGDB.FileGDBWorkspaceFactory", fileGDBPath); // Create a name object for the target (SDE) workspace and open it. IWorkspaceName targetWorkspaceName = getWorkspaceName("esriDataSourcesGDB.SdeWorkspaceFactory", sdePath); IName targetName = (IName)targetWorkspaceName; // Create a name object for the source dataset. IFeatureClassName sourceFeatureClassName = getFeatureClassName(sourceWorkspaceName, sourceFCName); IName sourceName = (IName)sourceFeatureClassName; // Create an enumerator for source datasets. IEnumName sourceEnumName = new NamesEnumeratorClass(); IEnumNameEdit sourceEnumNameEdit = (IEnumNameEdit)sourceEnumName; // Add the name object for the source class to the enumerator. sourceEnumNameEdit.Add(sourceName); // Create a GeoDBDataTransfer object and a null name mapping enumerator. IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass(); IEnumNameMapping enumNameMapping = null; // Use the data transfer object to create a name mapping enumerator. Boolean conflictsFound = geoDBDataTransfer.GenerateNameMapping(sourceEnumName, targetName, out enumNameMapping); enumNameMapping.Reset(); // Check for conflicts. if (conflictsFound) { // Iterate through each name mapping. INameMapping nameMapping = null; while ((nameMapping = enumNameMapping.Next()) != null) { // Resolve the mapping's conflict (if there is one). if (nameMapping.NameConflicts) { nameMapping.TargetName = nameMapping.GetSuggestedName(targetName); } // See if the mapping's children have conflicts. IEnumNameMapping childEnumNameMapping = nameMapping.Children; if (childEnumNameMapping != null) { childEnumNameMapping.Reset(); // Iterate through each child mapping. INameMapping childNameMapping = null; while ((childNameMapping = childEnumNameMapping.Next()) != null) { if (childNameMapping.NameConflicts) { childNameMapping.TargetName = childNameMapping.GetSuggestedName(targetName); } } } } } // Start the transfer. geoDBDataTransfer.Transfer(enumNameMapping, targetName); }