public bool? CompressFileGeoDB(string FileGeodatabase) { System.Collections.Generic.IEnumerable<ESRI.ArcGIS.RuntimeInfo> runtimeInfo = null; ESRI.ArcGIS.esriSystem.IVariantArray geoprocessorVariantArray = null; ESRI.ArcGIS.Geoprocessing.GeoProcessor compressGeoprocessor = null; try { // Make sure the File Geodatabase exists before attempting to uncompress it. if (!System.IO.Directory.Exists(FileGeodatabase)) { // Let the user know that the File Geodatabase does not exist. if (ErrorMessage != null) { ErrorMessage("The File Geodatabase - " + FileGeodatabase.ToUpper() + " does not exist and thus was not compressed..."); } // Return FALSE to the calling routine to indicate that this process failed. return false; } // Let the user know what is happening. if (ProcessMessage != null) { ProcessMessage(" - Attempting to compress the File Geodatabase - " + FileGeodatabase.ToUpper() + "..."); } // Determine the Install Path for the ArcGIS Software. runtimeInfo = ESRI.ArcGIS.RuntimeManager.InstalledRuntimes; string arcToolboxPath = null; foreach (ESRI.ArcGIS.RuntimeInfo currentRuntimeItem in runtimeInfo) { // Retrieve the Install Path for the ArcGIS Desktop Runtime (ArcGIS Toolbox Items // are found in this path). if (currentRuntimeItem.Product == ESRI.ArcGIS.ProductCode.Desktop) { arcToolboxPath = currentRuntimeItem.Path; } } // If the ArcToolBox Directory Exists, add it to the Path. if (System.IO.Directory.Exists(System.IO.Path.Combine(arcToolboxPath, @"ArcToolbox"))) { arcToolboxPath = System.IO.Path.Combine(arcToolboxPath, @"ArcToolbox"); } // If the Toolboxes Directory Exists, add it to the Path. if (System.IO.Directory.Exists(System.IO.Path.Combine(arcToolboxPath, @"Toolboxes"))) { arcToolboxPath = System.IO.Path.Combine(arcToolboxPath, @"Toolboxes"); } // If the Toolbox File Exists, add it to the Toolbox path. if (System.IO.File.Exists(System.IO.Path.Combine(arcToolboxPath, "Data Management Tools.tbx"))) { // Add the File Name to the path. arcToolboxPath = System.IO.Path.Combine(arcToolboxPath, "Data Management Tools.tbx"); } // Build the Geoprocessor Variant Array that will pass the arguments to the Geoprocessing Tool. geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass(); geoprocessorVariantArray.Add(FileGeodatabase); // Initialize the Geoprocessing Object that will be used to compress the Geodatabase. compressGeoprocessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessor(); compressGeoprocessor.AddToolbox(arcToolboxPath); try { // Perform the export. compressGeoprocessor.Execute("CompressFileGeodatabaseData_management", geoprocessorVariantArray, null); // Write the messages from the Compress Tool to the log file. if (ProcessMessage != null) { int toolMessageCount = compressGeoprocessor.MessageCount; int currentToolMessageIndex = 0; ProcessMessage(""); ProcessMessage(" - Successfully Compressed the File Geodatabase..."); ProcessMessage(" - Compress File Geodatabase Operation Messages..."); while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. ProcessMessage(" + " + compressGeoprocessor.GetMessage(currentToolMessageIndex)); // Increment the Tool Message Index Counter. currentToolMessageIndex++; } } } catch (System.IO.IOException ioException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(ioException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Compress Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Compress File Geodatabase Operation in the FeatureClassUtilities.CompressFileGeoDB() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line: " + lineNumber.ToString() + ")!"); if (ProcessMessage != null) { int toolMessageCount = compressGeoprocessor.MessageCount; int currentToolMessageIndex = 0; ProcessMessage("The information from the Geoprocessor is:"); while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. ProcessMessage(" + " + compressGeoprocessor.GetMessage(currentToolMessageIndex)); // Increment to Toold Message Index Counter. currentToolMessageIndex++; } } } // Return FALSE to the calling routine ito indicate that this process failed. return false; } catch (System.Runtime.InteropServices.COMException comException) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(comException, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that the Compress Operation Failed. if (ErrorMessage != null) { ErrorMessage("The Compress File Geodatabase Operation in the CompressFileGeoDB() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line: " + lineNumber.ToString() + ")!"); if (ProcessMessage != null) { int toolMessageCount = compressGeoprocessor.MessageCount; int currentToolMessageIndex = 0; ProcessMessage("The information from the Geoprocessor is:"); while (currentToolMessageIndex < toolMessageCount) { // Write the current message to the log file. ProcessMessage(" + " + compressGeoprocessor.GetMessage(currentToolMessageIndex)); // Increment to Toold Message Index Counter. currentToolMessageIndex++; } } } // Return FALSE to the calling routine ito indicate that this process failed. return false; } // If the process made it to here, it was successful so return TRUE to the calling // method. return true; } catch (System.Exception caught) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(caught, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that this process failed. if (ErrorMessage != null) { ErrorMessage("The MaintTools.FeatureClassUtilities.CompressFileGeoDB() Method failed with error message: " + caught.Message + " (Line: " + lineNumber.ToString() + ")!"); } // Return NULL to the calling routine to indicate that this process failed. return null; } finally { // If the Installed Runtimes List has been instantiated, close it. if (runtimeInfo != null) { runtimeInfo = null; } // If the Geoprocessor Parameters Array has been instantiated, close it. if (geoprocessorVariantArray != null) { geoprocessorVariantArray = null; } // If the Uncompress Geoprocessor Object has been instantiated, close it. if (compressGeoprocessor != null) { compressGeoprocessor = null; } } }
/// <summary> /// Updates any locators in the specified File Geodatabase that use the specified Feature Class as Primary Reference Table. Any Alternate Names Tables that exist for the /// specified Feature Class will be copied from the specified Enterprise Geodatabase (InputWorkspace) to the File Geodatabase. /// </summary> /// <param name="OutputFileGeodatabasePathName"> /// The Full Path to the Output File Geodatabase that contains the Locators that are to be rebuilt. /// </param> /// <param name="FeatureClassName"> /// The Name of the Feature Class that has been updated in the Output File Geodatabase. /// </param> /// <param name="InputWorkspace"> /// An ESRI ArcGIS Workspace Object that points to the Enterprise Geodatabase that is being used as the source for updating the Output File Geodatabase datasets. /// </param> /// <param name="InputWorkspaceDBSchemaOwnerName"> /// The Name of the Schema Owner in the source Enterprise Geodatabase. /// </param> /// <returns> /// TRUE if all locators in which the udpated feature class participates have been rebuilt successfully. /// FALSE if the locators were not successfully rebuilt. /// </returns> public bool UpdateFileGeodatabaseLocators(string OutputFileGeodatabasePathName, string FeatureClassName, ESRI.ArcGIS.Geodatabase.IWorkspace InputWorkspace, string InputWorkspaceDBSchemaOwnerName) { ESRI.ArcGIS.Geodatabase.IWorkspace geodatabaseWorkspace = null; ESRI.ArcGIS.Location.ILocatorManager locatorManager = null; ESRI.ArcGIS.Geodatabase.ILocatorWorkspace2 locatorWorkspace = null; ESRI.ArcGIS.Geodatabase.IEnumLocatorName locatorNamesEnum = null; System.Collections.Specialized.StringCollection copiedReferenceTables = null; ESRI.ArcGIS.Geodatabase.ILocatorName currentLocatorName = null; ESRI.ArcGIS.Geodatabase.ILocator currentLocator = null; ESRI.ArcGIS.Location.IReferenceDataTables locatorReferenceTables = null; ESRI.ArcGIS.Location.IEnumReferenceDataTable locatorReferenceTablesEnum = null; ESRI.ArcGIS.Location.IReferenceDataTable2 currentLocatorReferenceTable = null; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace geodatabaseFeatureWorkspace = null; ESRI.ArcGIS.Geodatabase.ITable deleteTable = null; ESRI.ArcGIS.Geodatabase.IDataset deleteDataset = null; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace inputFeatureWorkspace = null; ESRI.ArcGIS.Geodatabase.ITable inputAlternateNameTable = null; ESRI.ArcGIS.Geodatabase.IDataset inputTableDataset = null; ESRI.ArcGIS.Geodatabase.IWorkspaceFactory inputWorkspaceFactory = null; ESRI.ArcGIS.Geoprocessing.GeoProcessor geoProcessorObject = null; ESRI.ArcGIS.esriSystem.IVariantArray tableToTableParams = null; ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult geoprocessorResult = null; ESRI.ArcGIS.Geoprocessing.GeoProcessor rebuildGeoprocessorObject = null; ESRI.ArcGIS.esriSystem.IVariantArray rebuildLocatorParams = null; ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult rebuildGeoprocessorResult = null; try { // Let the user know what is happening. if (ProcessMessage != null) { ProcessMessage(" - Initializing the process to rebuild any locators and determining if the specified Feature Class is a reference dataset for any locators in the File Geodatabase..."); } // Open the Locator Workspace. geodatabaseWorkspace = EstablishFileGeodatabaseConnection(OutputFileGeodatabasePathName); // Make sure the Output File Geodatabase Workspace Connection was established successfully before moving on. if (geodatabaseWorkspace == null) { // Let the user know that the connection could not be established. if (ErrorMessage != null) { ErrorMessage("Failed to open the Output File Geodatabase Workspace - " + OutputFileGeodatabasePathName + ". Aborting the Locator Rebuild!"); } // Return FALSE to the calling method to indicate that this method failed. return false; } locatorManager = new ESRI.ArcGIS.Location.LocatorManagerClass(); locatorWorkspace = (ESRI.ArcGIS.Geodatabase.ILocatorWorkspace2)locatorManager.GetLocatorWorkspace(geodatabaseWorkspace); // Get the list of Address Locator Names from the File Geodatabase. locatorNamesEnum = locatorWorkspace.get_LocatorNames(ESRI.ArcGIS.Geodatabase.esriLocatorQuery.esriLocator, "Address"); // Create a List of Reference Tables that are copied by this process so that they will not be copied multiple times if it is used by multiple locators. copiedReferenceTables = new System.Collections.Specialized.StringCollection(); // Go through the list of associated locators and rebuild them. currentLocatorName = locatorNamesEnum.Next(); while (currentLocatorName != null) { // If there is a valid Locator Name, rebuild the locator. if (currentLocatorName.Name.Length > 1) { // Let the User know that the locator is being rebuilt. if (ProcessMessage != null) { ProcessMessage(" + Determining if the " + FeatureClassName + " Feature Class participates in the " + currentLocatorName.Name.ToString() + " Locator..."); } // Open the Current Locator. currentLocator = locatorWorkspace.GetLocator(currentLocatorName.Name); // If the Current Locator is a composite Locator, skip it. if (!(currentLocator is ESRI.ArcGIS.Location.ICompositeLocator)) { // Determine if the specified Feature Class is a reference Dataset for the locator. locatorReferenceTables = (ESRI.ArcGIS.Location.IReferenceDataTables)currentLocator; locatorReferenceTablesEnum = locatorReferenceTables.Tables; locatorReferenceTablesEnum.Reset(); // Retrieve the First Table from the Locator. currentLocatorReferenceTable = (ESRI.ArcGIS.Location.IReferenceDataTable2)locatorReferenceTablesEnum.Next(); // Default the Found the Locator Indicator to FALSE. bool foundIt = false; // If the Updated Feature Class is the Primary Table for this locator, the locator needs to be rebuilt so default the 'FoundIt' indicator to true. while (currentLocatorReferenceTable != null) { // Determine if the current table is the specified Feature Class Business Table. if (currentLocatorReferenceTable.DisplayName.ToUpper() == "PRIMARY TABLE") { ESRI.ArcGIS.Geodatabase.IDatasetName currentFeatureClassName = null; currentFeatureClassName = (ESRI.ArcGIS.Geodatabase.IDatasetName)currentLocatorReferenceTable.Name; if (currentFeatureClassName.Name.ToString().ToUpper() == FeatureClassName.ToUpper()) { // Set the found the locator indicator to TRUE. foundIt = true; } } // Retrieve the Next Table from the Locator. currentLocatorReferenceTable = (ESRI.ArcGIS.Location.IReferenceDataTable2)locatorReferenceTablesEnum.Next(); } // If the specified Feature Class does participate in the current Locator, rebuild the Locator. if (foundIt) { // Let the User know that the locator is being rebuilt. if (ProcessMessage != null) { ProcessMessage(" + Starting the rebuild of the " + currentLocatorName.Name.ToString() + " Locator..."); } // Reset the Locator Reference Tables enumerator. locatorReferenceTablesEnum.Reset(); // Retrieve the First Table from the Locator. currentLocatorReferenceTable = (ESRI.ArcGIS.Location.IReferenceDataTable2)locatorReferenceTablesEnum.Next(); // Go through the Locator Reference Tables and rebuild any Alternate Name Tables that are associated with the locator. while (currentLocatorReferenceTable != null) { if (currentLocatorReferenceTable.DisplayName.ToUpper() == "ALTERNATE NAME TABLE") { ESRI.ArcGIS.Geodatabase.IDatasetName currentTableName = null; currentTableName = (ESRI.ArcGIS.Geodatabase.IDatasetName)currentLocatorReferenceTable.Name; // Alternate Name Tables have the string "_ALT" inserted in the name before the "_PDX" so, remove the "_PDX" from the Feature Class Name so that it can be // found in the Alternate Table Name. string searchName = FeatureClassName; if (searchName.Substring(searchName.Length - 3).ToUpper() == "PDX") { searchName = searchName.Substring(0, searchName.Length - 4); } // If the current Alternate Name Table is associated with this locator, delete it and copy the most current version from the source Geodatabase. if (currentTableName.Name.ToString().ToUpper().IndexOf(searchName.ToUpper()) != -1) { // If the Table Name includes some prefix information (Database Name and Table Owner Name), drop it for attempting to find the table in the search Geodatabase. string tableSearchName = currentTableName.Name.ToString(); if (tableSearchName.ToUpper().IndexOf(searchName.ToUpper()) > 0) { // Drop the prefix from the Table Name. tableSearchName = tableSearchName.Substring(tableSearchName.IndexOf(searchName.ToUpper())); } // If the Table has not already been updated by this process, update it. if (!copiedReferenceTables.Contains(tableSearchName)) { // Let the user know which locator is being rebuilt. if (ProcessMessage != null) { ProcessMessage(" < Deleting the - " + tableSearchName + " Alternate Name Table for the " + currentLocatorName.Name + " locator..."); } geodatabaseFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)geodatabaseWorkspace; deleteTable = geodatabaseFeatureWorkspace.OpenTable(currentTableName.Name.ToString()); deleteDataset = (ESRI.ArcGIS.Geodatabase.IDataset)deleteTable; deleteDataset.Delete(); // Release the Delete Objects to remove locks on the reference table. if (deleteDataset != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(deleteDataset); } if (deleteTable != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(deleteTable); } // Attempt to open the Source Table in the Input Geodatabase. inputFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)InputWorkspace; inputAlternateNameTable = (ESRI.ArcGIS.Geodatabase.ITable)inputFeatureWorkspace.OpenTable(InputWorkspaceDBSchemaOwnerName + "." + tableSearchName); inputTableDataset = (ESRI.ArcGIS.Geodatabase.IDataset)inputAlternateNameTable; // If the Table was opened successfully, Attempt to Copy it to the File Geodatabase. string temporaryDirectory = null; if (inputAlternateNameTable != null) { // Determine in which directory the Temporary SDE Connection File should // be created. if (System.IO.Directory.Exists(@"D:\Temp")) { // Set the Temporary Directory to 'D:\TEMP\'. temporaryDirectory = @"D:\Temp\"; } else { // Check to see if there is a 'C:\TEMP' Directory. if (System.IO.Directory.Exists(@"C:\Temp")) { // Set the Temporary Directory to 'C:\Temp\' temporaryDirectory = @"C:\Temp\"; } else { // Set the Temporary Directory to 'C:\'. temporaryDirectory = @"C:\"; } } // Create a Connection File for the Input Enterprise Geodatabase Connection. inputWorkspaceFactory = InputWorkspace.WorkspaceFactory; inputWorkspaceFactory.Create(temporaryDirectory, "inputConnection.sde", InputWorkspace.ConnectionProperties, 0); string connectionFile = temporaryDirectory + "\\inputConnection.sde"; // Let the user know which locator is being rebuilt. if (ProcessMessage != null) { ProcessMessage(" < Copying the - " + tableSearchName + " Alternate Name Table for the " + currentLocatorName.Name + " locator from the Source Geodatabase..."); } // Establish a Table Copy Geoprocessing Object to Copy the Enterprise // Enterprise Geodatabase Alternate Name Table to the File Geodatabase. geoProcessorObject = new ESRI.ArcGIS.Geoprocessing.GeoProcessor(); tableToTableParams = new ESRI.ArcGIS.esriSystem.VarArray(); tableToTableParams.Add(connectionFile + @"\" + inputTableDataset.Name); tableToTableParams.Add(OutputFileGeodatabasePathName); tableToTableParams.Add(tableSearchName); // Copy the Enterprise Geodatabase Alternate Name table to the File // Geodatabase. geoprocessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)geoProcessorObject.Execute("TableToTable_conversion", tableToTableParams, null); // Delete the Connection File since it is no longer needed. if (System.IO.File.Exists(temporaryDirectory + "\\inputConnection.sde")) { // Delete the file. System.IO.File.Delete(temporaryDirectory + "\\inputConnection.sde"); } if (geoProcessorObject != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(geoProcessorObject); } if (tableToTableParams != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(tableToTableParams); } if (geoprocessorResult != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(geoprocessorResult); } // Add the current table to the list of Tables that have been copied. copiedReferenceTables.Add(tableSearchName); } } } } // Get the next Reference Table from the enumerator. currentLocatorReferenceTable = (ESRI.ArcGIS.Location.IReferenceDataTable2)locatorReferenceTablesEnum.Next(); } // Let the user know which locator is being rebuilt. if (ProcessMessage != null) { ProcessMessage(" < Rebuilding the - " + currentLocatorName.Name + " locator..."); } // Build the Parameter Set necessary to Rebuild the Locator. rebuildLocatorParams = new ESRI.ArcGIS.esriSystem.VarArray(); rebuildLocatorParams.Add(OutputFileGeodatabasePathName + "\\" + currentLocatorName.Name); System.Runtime.InteropServices.Marshal.ReleaseComObject(currentLocatorName); if (currentLocatorReferenceTable != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(currentLocatorReferenceTable); } if (currentLocator != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(currentLocator); } // Attempt to rebuild the Locator. rebuildGeoprocessorObject = new ESRI.ArcGIS.Geoprocessing.GeoProcessor(); rebuildGeoprocessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)rebuildGeoprocessorObject.Execute("RebuildAddressLocator_geocoding", rebuildLocatorParams, null); // Present the results of the process to the user. if (rebuildGeoprocessorResult.Status == ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) { // Let the user know that the Locator was rebuilt successfully. if (ProcessMessage != null) { ProcessMessage(" + Successfully rebuilt the - " + currentLocatorName.Name + " locator..."); if (rebuildGeoprocessorObject.MessageCount > 0) { ProcessMessage(" + The messages from the process were -"); for (int i = 0; i <= rebuildGeoprocessorObject.MessageCount - 1; i++) { ProcessMessage(" - " + rebuildGeoprocessorObject.GetMessage(i)); } } } } else { // Let the user know that the Locator Failed to Rebuild. if (ProcessMessage != null) { ProcessMessage(""); ProcessMessage("FAILED to rebuild the - " + currentLocatorName.Name + " locator..."); if (rebuildGeoprocessorObject.MessageCount > 0) { ProcessMessage(" + The messages from the process were -"); for (int i = 0; i <= rebuildGeoprocessorObject.MessageCount - 1; i++) { ProcessMessage(" - " + rebuildGeoprocessorObject.GetMessage(i)); } } } // Return FALSE to the calling method to indicate that this process failed. return false; } } } else { // Retrieve the list of locators that exist in the Composite Locator. ESRI.ArcGIS.Location.ICompositeLocator currentCompositeLocator = (ESRI.ArcGIS.Location.ICompositeLocator)currentLocator; string[] locatorNames = currentCompositeLocator.LocatorNames as string[]; ESRI.ArcGIS.Geodatabase.ILocator[] locators = new ESRI.ArcGIS.Geodatabase.ILocator[locatorNames.Length]; int i = 0; foreach (string currentSubLocatorName in locatorNames) { locators[i] = currentCompositeLocator.get_Locator(currentSubLocatorName); i++; } // Determine if the Updated Feature Class participates in any of the locators in the Composite Locator. bool foundIt = false; foreach (ESRI.ArcGIS.Geodatabase.ILocator currentSubLocator in locators) { // If the Current Locator is a Composite Locator, ignore it. if (!(currentSubLocator is ESRI.ArcGIS.Location.ICompositeLocator)) { // Determine if the specified Feature Class is a reference Dataset for the locator. locatorReferenceTables = (ESRI.ArcGIS.Location.IReferenceDataTables)currentSubLocator; locatorReferenceTablesEnum = locatorReferenceTables.Tables; locatorReferenceTablesEnum.Reset(); // Retrieve the First Table from the Locator. currentLocatorReferenceTable = (ESRI.ArcGIS.Location.IReferenceDataTable2)locatorReferenceTablesEnum.Next(); // Go through the Primary Tables participating in the Locator and determine if the Updated Feature Class Table is one of them. while ((currentLocatorReferenceTable != null) && (!foundIt)) { // Determine if the current table is the specified Feature Class Business Table. if (currentLocatorReferenceTable.DisplayName.ToUpper() == "PRIMARY TABLE") { ESRI.ArcGIS.Geodatabase.IDatasetName currentFeatureClassName = null; currentFeatureClassName = (ESRI.ArcGIS.Geodatabase.IDatasetName)currentLocatorReferenceTable.Name; if (currentFeatureClassName.Name.ToString().ToUpper() == FeatureClassName.ToUpper()) { // Set the found the locator indicator to TRUE. foundIt = true; } } // Retrieve the Next Table from the Locator. currentLocatorReferenceTable = (ESRI.ArcGIS.Location.IReferenceDataTable2)locatorReferenceTablesEnum.Next(); } } } // If the Updated Feature Class is a member of the Composite Locator, rebuild it. if (foundIt) { // Let the user know which locator is being rebuilt. if (ProcessMessage != null) { ProcessMessage(" < Rebuilding the - " + currentLocatorName.Name + " locator..."); } // Build the Parameter Set necessary to Rebuild the Locator. rebuildLocatorParams = new ESRI.ArcGIS.esriSystem.VarArray(); rebuildLocatorParams.Add(OutputFileGeodatabasePathName + "\\" + currentLocatorName.Name); // Attempt to rebuild the Locator. rebuildGeoprocessorObject = new ESRI.ArcGIS.Geoprocessing.GeoProcessor(); rebuildGeoprocessorResult = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)rebuildGeoprocessorObject.Execute("RebuildAddressLocator_geocoding", rebuildLocatorParams, null); // Present the results of the process to the user. if (rebuildGeoprocessorResult.Status == ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded) { // Let the user know that the Locator was rebuilt successfully. if (ProcessMessage != null) { ProcessMessage(" + Successfully rebuilt the - " + currentLocatorName.Name + " locator..."); if (rebuildGeoprocessorObject.MessageCount > 0) { ProcessMessage(" + The messages from the process were -"); for (int y = 0; y <= rebuildGeoprocessorObject.MessageCount - 1; y++) { ProcessMessage(" - " + rebuildGeoprocessorObject.GetMessage(y)); } } } } else { // Let the user know that the Locator Failed to Rebuild. if (ProcessMessage != null) { ProcessMessage(""); ProcessMessage("FAILED to rebuild the - " + currentLocatorName.Name + " locator..."); if (rebuildGeoprocessorObject.MessageCount > 0) { ProcessMessage(" + The messages from the process were -"); for (int y = 0; y <= rebuildGeoprocessorObject.MessageCount - 1; y++) { ProcessMessage(" - " + rebuildGeoprocessorObject.GetMessage(y)); } } } // Return FALSE to the calling method to indicate that this process failed. return false; } } } } // Retrieve the next Locator Name Object from the Locator Names Enumerator. currentLocatorName = locatorNamesEnum.Next(); } // If the process made it to here, it was successful so return TRUE to the calling routine. return true; } catch (System.Runtime.InteropServices.COMException comCaught) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(comCaught, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that this process failed. if (ErrorMessage != null) { ErrorMessage("The FeatureClassUtilities.UpdateFileGeodatabaseLocators() Method failed with error message: " + comCaught.Message + "(" + comCaught.ErrorCode + " Line: " + lineNumber.ToString() + ")!"); } // Return FALSE to the calling routine to indicate that this process failed. return false; } catch (System.Exception caught) { // Determine the Line Number from which the exception was thrown. System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(caught, true); System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1); int lineNumber = stackFrame.GetFileLineNumber(); // Let the User know that this process failed. if (ErrorMessage != null) { ErrorMessage("The FeatureClassUtilities.UpdateFileGeodatabaseLocators() Method failed with error message: " + caught.Message + " (Line: " + lineNumber.ToString() + ")!"); } // Return FALSE to the calling routine to indicate that this process failed. return false; } finally { // If the Geoprocessor Result Object was instantiated, close it. if (geoprocessorResult != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(geoprocessorResult); } // If the Table to Table Variant Array was instantiated, close it. if (tableToTableParams != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(tableToTableParams); } // If the Geoprocessor Object was instantiated, close it. if (geoProcessorObject != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(geoProcessorObject); } // If the InputWorkspace Factory Object was instantiated, close it. if (inputWorkspaceFactory != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(inputWorkspaceFactory); } // If the Input Table Dataset Object was instantiated, close it. if (inputTableDataset != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(inputTableDataset); } // If the Input Alternate Name Table Object was instantiated, close it. if (inputAlternateNameTable != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(inputAlternateNameTable); } // If the Input Feature Workspace Object was instantiated, close it. if (inputFeatureWorkspace != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(inputFeatureWorkspace); } // If the Delete Dataset Object was instantiated, close it. if (deleteDataset != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(deleteDataset); } // If the Delete Table Object was instantiated, close it. if (deleteTable != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(deleteTable); } // If the Geodatabase Feature Workspace Object was instantiated, close it. if (geodatabaseFeatureWorkspace != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(geodatabaseFeatureWorkspace); } // If the Current Locator Reference Table Object was instantiated, close it. if (currentLocatorReferenceTable != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(currentLocatorReferenceTable); } // If the Locator Reference Tables Enumerator was instantiated, close it. if (locatorReferenceTablesEnum != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(locatorReferenceTablesEnum); } // If the Locator Reference Tables Object was instantiated, close it. if (locatorReferenceTables != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(locatorReferenceTables); } // If the Current Locator Object was instantiated, close it. if (currentLocator != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(currentLocator); } // If the Current Locator Name Object was instantiated, close it. if (currentLocatorName != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(currentLocatorName); } // If the Locatore Names Enumerator Object was instantiated, close it. if (locatorNamesEnum != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(locatorNamesEnum); } // If the Locator Workspace Object was instantiated, close it. if (locatorWorkspace != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(locatorWorkspace); } // If the Locator Manager Object was instantiated, close it. if (locatorManager != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(locatorManager); } // If the Geodatabase Workspace Object was instantiated, close it. if (geodatabaseWorkspace != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(geodatabaseWorkspace); } } }