コード例 #1
0
        private bool ProjectFeatureClassHARNtoWGS(string SourceFeatures, string OutputFeatures, string OutputProjectionDefinitionFile)
        {
            ESRI.ArcGIS.esriSystem.IVariantArray                geoprocessorVariantArray = null;
              PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities         = null;
              ESRI.ArcGIS.Geoprocessing.GeoProcessor              projectDataGeoProcessor  = null;

              try
              {
            //  Let the user know what is happening.
            if (ProcessMessage != null)
            {
              ProcessMessage("              + Initializing the Projection Operation...");
            }

            //  Specify the parameters for the export of this Feature Class to the Output File Geodatabase.
            geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass();
            geoprocessorVariantArray.Add(SourceFeatures);
            geoprocessorVariantArray.Add(OutputFeatures);
            geoprocessorVariantArray.Add(OutputProjectionDefinitionFile);
            geoprocessorVariantArray.Add("NAD_1983_HARN_To_WGS_1984");

            //  Determine the ArcGIS Install Path so that the Projector Toolbox can be opened to be used.
            generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();
            string installPath = generalUtilities.DetermineArcGISDesktopInstallPath();

            //  Make sure the Install Path was determined successfully before moving on.
            if (System.String.IsNullOrEmpty(installPath))
            {
              //  Let the user know that the ArcGIS Desktop Install Path could not be determined.
              if (ErrorMessage != null)
              {
            ErrorMessage("Could not Determine the ArcGIS Desktop Install Path to Initialize the Projection Toolbox.  The MaintTools.FeatureClassUtilities.ProjectFeatureClassHARNtoWGS() Method failed!");
              }

              //  Return FALSE to the calling method to indicate that this method failed.
              return false;

            }

            //  Instantiate the Geoprocessing Object that will be used to export this Annotatioin Feature Class to the Output File Geodatabase.
            projectDataGeoProcessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass();
            projectDataGeoProcessor.AddToolbox(System.IO.Path.Combine(installPath, @"ArcToolbox\Toolboxes\Data Management Tools.tbx"));

            //  Let the user know what is happening.
            if (ProcessMessage != null)
            {
              ProcessMessage("              + Performing the Projection Operation...");
            }

            //  Perform the Projection in a TRY Block so that any COM or IO Errors can be identified and handled.
            try
            {
              //  Perform the export.
              projectDataGeoProcessor.Execute("Project_Management", geoprocessorVariantArray, null);

              //  Write the messages from the Projection Tool to the process log file.
              if (ProcessMessage != null)
              {
            int toolMessageCount = projectDataGeoProcessor.MessageCount;
            int currentToolMessageIndex = 0;
            ProcessMessage("");
            ProcessMessage("              + Project Feature Class Operation Messages...");
            while (currentToolMessageIndex < toolMessageCount)
            {
              //  Write the current message to the log file.
              ProcessMessage("                 >> " + projectDataGeoProcessor.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 Dissolve Operation Failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("The Project Feature Class Operation in the ProjectFeatureClassHARNtoWGS() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line:  " + lineNumber.ToString() + ")!");
              }

              //  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 Dissolve Operation Failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("The Project Feature Class Operation in the ProjectFeatureClassHARNtoWGS() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line:  " + lineNumber.ToString() + ")!");
              }

              //  Return FALSE to the calling routine ito 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 MaintTools.FeatureClassUtilities.ProjectFeatureClassHARNtoWGS() 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 process made it to here it was successful so return TRUE to the calling method.
              return true;
        }
コード例 #2
0
        public bool ExportGeodatabaseAnnotationFeatureClassToFileGeoDB(ESRI.ArcGIS.Geodatabase.IFeatureWorkspace InputFeatureWorkspace,
                                          ESRI.ArcGIS.Geodatabase.IFeatureClass InputFeatureClass, string OutputFeatureClassName, string OutputFileGeoDBPath,
                                          string OutputFileGeoDBName)
        {
            ESRI.ArcGIS.Geodatabase.IWorkspace                  inputWorkspace           = null;
              ESRI.ArcGIS.esriSystem.IPropertySet                 inputPropertySet         = null;
              System.Type                                         inputFactoryType         = null;
              System.Object                                       inputFactoryObject       = null;
              ESRI.ArcGIS.Geodatabase.IWorkspaceFactory           inputWorkspaceFactory    = null;
              ESRI.ArcGIS.Geodatabase.IWorkspaceName              inputWorkspaceName       = null;
              ESRI.ArcGIS.Geodatabase.IDataset                    inputDataset             = null;
              ESRI.ArcGIS.esriSystem.VarArray                     geoprocessorVariantArray = null;
              PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities         = null;
              ESRI.ArcGIS.Geoprocessing.GeoProcessor              geoProcessor             = null;

              try
              {
            //  QI to the Input Workspace.
            inputWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)InputFeatureWorkspace;

            //  Build a Property Set for the Current Workspace.
            inputPropertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
            inputPropertySet = inputWorkspace.ConnectionProperties;

            //  The Folks at ESRI were not smart enough to handle a Property Set that did not include a Server Name so if there is not one in this propertyset dummy one in.
            if (inputPropertySet.GetProperty("Instance").ToString().ToUpper().IndexOf("SDE:SQLSERVER:") != -1)
            {
              //  Determine the server name from the "Instance" Property of the Property Set.
              string inputServerName = inputPropertySet.GetProperty("Instance").ToString();
              while (inputServerName.IndexOf(@":") != -1)
              {
            //  Strip the first character from the Input Server Name.
            inputServerName = inputServerName.Substring(1);
              }

              //  If the Server Name Includes an Instance Value, strip that from the server name.
              while (inputServerName.IndexOf(@"\") != -1)
              {
            //  Strip the last character from the Input Server Name.
            inputServerName = inputServerName.Substring(0, (inputServerName.Length - 1));
              }

              //  Add a Server Property to the Property Set.
              inputPropertySet.SetProperty("Server", inputServerName);

            }

            //  Determine which directory the Temporary SDE Connection File should be created in.
            string temporaryDirectory = null;
            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:\";
              }

            }

            //  Make sure the Output Temporary Connection File does not already exist before attempting to create a new one.
            if (System.IO.File.Exists(temporaryDirectory + OutputFeatureClassName + "SDEConn.sde"))
            {
              //  Delete the existing File.
              System.IO.File.Delete(temporaryDirectory + OutputFeatureClassName + "SDEConn.sde");

            }

            //  Create the Temporary SDE Connection File that will be used to specify the Input Annotation Features for this export operation.
            inputFactoryType = System.Type.GetTypeFromProgID("esriDataSourcesGDB.SDEWorkspaceFactory");
            inputFactoryObject = System.Activator.CreateInstance(inputFactoryType);
            inputWorkspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory)inputFactoryObject;
            inputWorkspaceName = inputWorkspaceFactory.Create(temporaryDirectory, OutputFeatureClassName + "SDEConn.sde", inputPropertySet, 0);

            //  Specify the parameters for the export of this Feature Class to the Output File Geodatabase.
            inputDataset = (ESRI.ArcGIS.Geodatabase.IDataset)InputFeatureClass;
            string processDatasetName = null;
            if (inputDataset.Name.IndexOf(inputWorkspaceName.ConnectionProperties.GetProperty("Database").ToString()) > -1)
            {
              //  Drop the Server name from the Name before using it.
              processDatasetName = inputDataset.Name.Substring(inputWorkspaceName.ConnectionProperties.GetProperty("Database").ToString().Length + 1);
            }
            else
            {
              //  Use the Name as is.
              processDatasetName = inputDataset.Name.ToString();
            }

            //  Create a Field Mapping for this export.
            string inputAnnotationFeatures = inputWorkspaceName.PathName.ToString() + @"\" + processDatasetName;
            ESRI.ArcGIS.Geoprocessing.IGPUtilities geoprocessingUtilities = new ESRI.ArcGIS.Geoprocessing.GPUtilitiesClass();
            ESRI.ArcGIS.Geodatabase.IDETable inputTable = (ESRI.ArcGIS.Geodatabase.IDETable)geoprocessingUtilities.MakeDataElement(inputAnnotationFeatures, null, null);
            ESRI.ArcGIS.esriSystem.IArray inputTables = new ESRI.ArcGIS.esriSystem.ArrayClass();
            inputTables.Add(inputTable);
            ESRI.ArcGIS.Geoprocessing.IGPFieldMapping fieldMapping = new ESRI.ArcGIS.Geoprocessing.GPFieldMappingClass();

            //  Go through the fields in the Input Table and add them to the Field Mapping.
            object missing = Type.Missing;
            for (int i = 0; i < inputTable.Fields.FieldCount; i++)
            {
              if ((inputTable.Fields.get_Field(i).Type != ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeOID) &&
              (inputTable.Fields.get_Field(i).Type != ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry))
              {
            ESRI.ArcGIS.Geoprocessing.IGPFieldMap currentFieldMap = new ESRI.ArcGIS.Geoprocessing.GPFieldMapClass();
            currentFieldMap.AddInputField(inputTable, inputTable.Fields.get_Field(i), -1, -1);
            fieldMapping.AddFieldMap(currentFieldMap);
            currentFieldMap = null;

              }

            }

            //  Build the Variant Array that will be used to pass the parameters necessary for the export to the toolbox object.
            geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass();
            geoprocessorVariantArray.Add(inputAnnotationFeatures);
            geoprocessorVariantArray.Add(System.IO.Path.Combine(OutputFileGeoDBPath, OutputFileGeoDBName + ".gdb"));
            geoprocessorVariantArray.Add(OutputFeatureClassName);
            geoprocessorVariantArray.Add(null);
            geoprocessorVariantArray.Add(fieldMapping);
            geoprocessorVariantArray.Add(null);

            //  Determine the ArcGIS Install Path so that the Projector Toolbox can be opened to be used.
            generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();
            string installPath = generalUtilities.DetermineArcGISDesktopInstallPath();

            //  Make sure the Install Path was determined successfully before moving on.
            if (System.String.IsNullOrEmpty(installPath))
            {
              //  Let the user know that the ArcGIS Desktop Install Path could not be determined.
              if (ErrorMessage != null)
              {
            ErrorMessage("Could not Determine the ArcGIS Desktop Install Path to Initialize the Projection Toolbox.  The MaintTools.FeatureClassUtilities.ProjectFeatureClassHARNtoWGS() Method failed!");
              }

              //  Return FALSE to the calling method to indicate that this method failed.
              return false;

            }

            //  Instantiate the Geoprocessing Object that will be used to export this Annotatioin Feature Class to the Output File Geodatabase.
            geoProcessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass();
            geoProcessor.AddToolbox(System.IO.Path.Combine(installPath, @"ArcToolbox\Toolboxes\Conversion Tools.tbx"));

            //  Perform the Export in a TRY Block so that any COM or IO Errors can be identified and handled.
            try
            {
              //  Perform the export.
              geoProcessor.Execute("FeatureClassToFeatureClass_Conversion", geoprocessorVariantArray, null);
              //  Write the messages from the Feature Class to Feature Class tool log file.
              int toolMessageCount = geoProcessor.MessageCount;
              int currentToolMessageIndex = 0;
              if (ProcessMessage != null)
              {
            ProcessMessage("         - Feature Class to Feature Class Operation Messages...");
              }
              while (currentToolMessageIndex < toolMessageCount)
              {
            //  Write the current message to the log file.
            if (ProcessMessage != null)
            {
              ProcessMessage("           + " + geoProcessor.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 Dissolve Operation Failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("The Feature Class to Feature Class Operation in the MaintTools.FeatureClassUtilities.ExportGeodatabaseAnnotationFeatureClassToFileGeoDB() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line:  " + lineNumber.ToString() + ")!");
              }
              int toolMessageCount = geoProcessor.MessageCount;
              int currentToolMessageIndex = 0;
              if (ProcessMessage != null)
              {
            ProcessMessage("The information from the Geoprocessor is:");
              }
              while (currentToolMessageIndex < toolMessageCount)
              {
            //  Write the current message to the log file.
            if (ProcessMessage != null)
            {
              ProcessMessage("   + " + geoProcessor.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 Dissolve Operation Failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("The Feature Class to Feature Class Operation in the MaintTools.FeatureClassUtilities.ExportGeodatabaseAnnotationFeatureClassToFileGeoDB() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line:  " + lineNumber.ToString() + ")!");
              }
              int toolMessageCount = geoProcessor.MessageCount;
              int currentToolMessageIndex = 0;
              if (ProcessMessage != null)
              {
            ProcessMessage("The information from the Geoprocessor is:");
              }
              while (currentToolMessageIndex < toolMessageCount)
              {
            //  Write the current message to the log file.
            if (ProcessMessage != null)
            {
              ProcessMessage("   + " + geoProcessor.GetMessage(currentToolMessageIndex));
            }
            //  Increment to Toold Message Index Counter.
            currentToolMessageIndex++;
              }
              //  Return FALSE to the calling routine ito indicate that this process failed.
              return false;
            }

            //  Delete the SDE Connection File since it is no longer needed.
            if (System.IO.File.Exists(temporaryDirectory + OutputFeatureClassName + "SDEConn.sde"))
            {
              //  Delete the existing File.
              System.IO.File.Delete(temporaryDirectory + OutputFeatureClassName + "SDEConn.sde");
            }

              }
              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.ExportGeodatabaseAnnotationFeatureClassToFileGeoDB() 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 Input Workspace Object has been Instantiated, close it.
            if (inputWorkspace != null)
            {
              //  Close the Input Workspace Object.
              inputWorkspace = null;
            }
            //  If the Input Property Set Object was instantiated, close it.
            if (inputPropertySet != null)
            {
              inputPropertySet = null;
            }
            //  If the Input Factory Type Object was instantiated, close it.
            if (inputFactoryType != null)
            {
              inputFactoryType = null;
            }
            //  If the Input Factory Object was instantiated, close it.
            if (inputFactoryObject != null)
            {
              inputFactoryObject = null;
            }
            //  If the Input Workspace Factory Object was instantiated, close it.
            if (inputWorkspaceFactory != null)
            {
              inputWorkspaceFactory = null;
            }
            //  If the Input Workspace Name Object was instantiated, close it.
            if (inputWorkspaceName != null)
            {
              inputWorkspaceName = null;
            }
            //  If the Input Dataset name Object was instantiated, close it.
            if (inputDataset != null)
            {
              inputDataset = null;
            }
            //  If the Geoprocessor Variant Array Object was instantiated, close it.
            if (geoprocessorVariantArray != null)
            {
              geoprocessorVariantArray.RemoveAll();
              geoprocessorVariantArray = null;
            }
            //  If the General Utilities Object was instantiated, close it.
            if (generalUtilities != null)
            {
              generalUtilities = null;
            }
            //  If the Geoprocessor Object was instantiated, close it.
            if (geoProcessor != null)
            {
              geoProcessor = null;
            }

              }

              //  If the process made it to here it was successful so return TRUE to the calling method.
              return true;
        }
コード例 #3
0
        /// <summary>
        /// Indexes the specified Field in the Feature Class.
        /// </summary>
        /// <param name="IndexFeatureClass">
        /// An ESRI Geodatabase Feature Class Object for the Feature Class that contains the Field that is to be indexed.
        /// </param>
        /// <param name="IndexFieldName">
        /// The Name of the Field in the Class that is to be indexed.
        /// </param>
        /// <returns>
        /// TRUE if the Field was successfully indexed.
        /// FALSE if the Field was not successfully indexed.
        /// </returns>
        public bool IndexedFieldInFeatureClass(ESRI.ArcGIS.Geodatabase.IFeatureClass IndexFeatureClass, string IndexFieldName)
        {
            PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities         = null;
              ESRI.ArcGIS.Geodatabase.ITable                      inputTable               = null;
              ESRI.ArcGIS.esriSystem.VarArray                     geoprocessorVariantArray = null;
              ESRI.ArcGIS.Geoprocessing.IGeoProcessor             geoprocessor             = null;

              try
              {
             //  If the specified Field exists in the Feature Class, index it.
            if (IndexFeatureClass.Fields.FindField(IndexFieldName) != -1)
            {
              //  Instantiate the CGIS General Utilities Object that will be used to determine the ArcGIS Install Path on the server.
              generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();

              //  Determine the ArcGIS Install Path so that the Projector Toolbox can be opened to be used.
              generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();
              string installPath = generalUtilities.DetermineArcGISDesktopInstallPath();
              //  Make sure the Install Path was determined successfully before moving on.
              if (System.String.IsNullOrEmpty(installPath))
              {
            //  Let the user know that the ArcGIS Desktop Install Path could not be determined.
            if (ErrorMessage != null)
            {
              ErrorMessage("Could not Determine the ArcGIS Desktop Install Path to Initialize the Projection Toolbox.  The MaintTools.FeatureClassUtilities.IndexedFieldInFeatureClass() Method failed!");
            }
            //  Return FALSE to the calling method to indicate that this method failed.
            return false;
              }

              //QI to the Input Table.
              inputTable = (ESRI.ArcGIS.Geodatabase.ITable)IndexFeatureClass;

              //  Build the Variant Array that will hold the parameters to be passed to the Geoprocessing Tool.
              geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass();
              geoprocessorVariantArray.Add(inputTable);
              geoprocessorVariantArray.Add(IndexFieldName);
              //geoprocessorVariantArray.Add(indexFeatureClassIndexField);
              geoprocessorVariantArray.Add(IndexFieldName + @"_idx");
              geoprocessorVariantArray.Add("NON_UNIQUE");
              geoprocessorVariantArray.Add("NON_ASCENDING");

              //  Instantiate the Geoprocessing Object that will be used to Index the Specified Field in the Feature Class.
              geoprocessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass();
              geoprocessor.AddToolbox(System.IO.Path.Combine(installPath, @"ArcToolbox\Toolboxes\Data Management Tools.tbx"));

              //  Perform the Index Field Operation in a TRY Block so that any COM or IO Errors can be identified and handled.
              try
              {
            //  Perform the Add Index Operation.
            geoprocessor.Execute("AddIndex_Management", geoprocessorVariantArray, null);
            //  Write the messages from the Add Index tool log file.
            int toolMessageCount = geoprocessor.MessageCount;
            int currentToolMessageIndex = 0;
            if (ProcessMessage != null)
            {
              ProcessMessage("         - Add Index Operation Messages...");
            }
            while (currentToolMessageIndex < toolMessageCount)
            {
              //  Write the current message to the log file.
              if (ProcessMessage != null)
              {
                ProcessMessage("           + " + geoprocessor.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 Add Index Operation Failed.
            if (ErrorMessage != null)
            {
              ErrorMessage("The Add Attribute Index Operation in the MaintTools.FeatureClassUtilities.IndexedFieldInFeatureClass() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line:  " + lineNumber.ToString() + ")!");
            }
            int toolMessageCount = geoprocessor.MessageCount;
            int currentToolMessageIndex = 0;
            if (ProcessMessage != null)
            {
              ProcessMessage("The information from the Geoprocessor is:");
            }
            while (currentToolMessageIndex < toolMessageCount)
            {
              //  Write the current message to the log file.
              if (ProcessMessage != null)
              {
                ProcessMessage("   + " + geoprocessor.GetMessage(currentToolMessageIndex));
              }
              //  Increment to Tool 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 Dissolve Operation Failed.
            if (ErrorMessage != null)
            {
              ErrorMessage("The Add Attribute Index Operation in the MaintTools.FeatureClassUtilities.IndexedFieldInFeatureClass() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line:  " + lineNumber.ToString() + ")!");
            }
            int toolMessageCount = geoprocessor.MessageCount;
            int currentToolMessageIndex = 0;
            if (ProcessMessage != null)
            {
              ProcessMessage("The information from the Geoprocessor is:");
            }
            while (currentToolMessageIndex < toolMessageCount)
            {
              //  Write the current message to the log file.
              if (ProcessMessage != null)
              {
                ProcessMessage("   + " + geoprocessor.GetMessage(currentToolMessageIndex));
              }
              //  Increment to Tool Message Index Counter.
              currentToolMessageIndex++;
            }
            //  Return FALSE to the calling routine ito indicate that this process failed.
            return false;
              }

            }
            else
            {
              //  Let the user know that the Field does not exist in the Feature Class and will not be indexed.
              if (ProcessMessage != null)
              {
            ProcessMessage("               -  The field - " + IndexFieldName.ToUpper() + " could not be found in the " + IndexFeatureClass.AliasName + " Feature Class and will not be indexed...");
              }

            }

              }
              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 method failed.
            if (ErrorMessage != null)
            {
              ErrorMessage("The MaintTools.FeatureClassUtilities.IndexedFieldInFeatureClass() Method failed with error message - " + caught.Message + " (Line:  " + lineNumber.ToString() + ")!");
            }

            //  Return FALSE to the calling Method to indicate that this Method failed.
            return false;

              }
              finally
              {
            //  If the Geoprocessor Object was instantiated, close it.
            if (geoprocessor != null)
            {
              geoprocessor = null;
            }
            //  If the Geoprocessor Variant Array Object was instantiated, close it.
            if (geoprocessorVariantArray != null)
            {
              geoprocessorVariantArray = null;
            }
            //  If the Input Table Object was instantiated, close it.
            if (inputTable != null)
            {
              inputTable = null;
            }
            //  If the CGIS Data Maintenance General Utilities Object was instantiated, close it.
            if (generalUtilities != null)
            {
              generalUtilities = null;
            }

              }

              //  If the process made it to here, it was successful so return a "TRUE" to the calling method.
              return true;
        }
コード例 #4
0
        /// <summary>
        /// Deletes all features from the specified feature class.
        /// </summary>
        /// <param name="DeleteFeatureClass">
        /// An Object Pointer to the Feature Class that is to be emptied.
        /// </param>
        /// <returns>
        /// TRUE if the features were successfully deleted.
        /// FALSE if the process failed to delete the features from the dataset.
        /// </returns>
        public bool EmptyGeodatabaseFeatureClass(ESRI.ArcGIS.Geodatabase.IFeatureClass DeleteFeatureClass)
        {
            PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities         = null;
              ESRI.ArcGIS.esriSystem.IVariantArray                geoprocessorVariantArray = null;
              ESRI.ArcGIS.Geoprocessing.IGeoProcessor             geoProcessor             = null;

              try
              {
            //  Determine the ArcGIS Install Path so that the Data Management Toolbox can be opened to be used.
            generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();
            string installPath = generalUtilities.DetermineArcGISDesktopInstallPath();

            //  Make sure the Install Path was determined successfully before moving on.
            if (System.String.IsNullOrEmpty(installPath))
            {
              //  Let the user know that the ArcGIS Desktop Install Path could not be determined.
              if (ErrorMessage != null)
              {
            ErrorMessage("Could not Determine the ArcGIS Desktop Install Path to Initialize the Data Management Toolbox.  The MaintTools.FeatureClassUtilities.EmptyGeodatabaseFeatureClass() Method failed!");
              }

              //  Return FALSE to the calling method to indicate that this method failed.
              return false;

            }

            //  Build the Variant Array that will be used to pass the parameters necessary for the delete to the toolbox object.
            geoprocessorVariantArray = new ESRI.ArcGIS.esriSystem.VarArrayClass();
            geoprocessorVariantArray.Add(DeleteFeatureClass);

            //  Instantiate the Geoprocessing Object that will be used to delete the features from the feature class.
            geoProcessor = new ESRI.ArcGIS.Geoprocessing.GeoProcessorClass();
            geoProcessor.AddToolbox(System.IO.Path.Combine(installPath, @"ArcToolbox\Toolboxes\Data Management Tools.tbx"));

            //  Perform the Export in a TRY Block so that any COM or IO Errors can be identified and handled.
            try
            {
              //  Perform the export.
              geoProcessor.Execute("DeleteFeatures_management", geoprocessorVariantArray, null);
              //  Write the messages from the Delete Features tool log file.
              int toolMessageCount = geoProcessor.MessageCount;
              int currentToolMessageIndex = 0;
              if (ProcessMessage != null)
              {
            ProcessMessage("         - Delete Features Operation Messages...");
              }
              while (currentToolMessageIndex < toolMessageCount)
              {
            //  Write the current message to the log file.
            if (ProcessMessage != null)
            {
              ProcessMessage("           + " + geoProcessor.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 Delete Features Operation Failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("The Delete Features Operation in the MaintTools.FeatureClassUtilities.EmptyGeodatabaseFeatureClass() Method Failed with error message - " + ioException.Message + " (" + ioException.Source + " Line:  " + lineNumber.ToString() + ")!");
              }
              int toolMessageCount = geoProcessor.MessageCount;
              int currentToolMessageIndex = 0;
              if (ProcessMessage != null)
              {
            ProcessMessage("The information from the Geoprocessor is:");
              }
              while (currentToolMessageIndex < toolMessageCount)
              {
            //  Write the current message to the log file.
            if (ProcessMessage != null)
            {
              ProcessMessage("   + " + geoProcessor.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 Delete Features Operation Failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("The Delete Features Operation in the MaintTools.FeatureClassUtilities.EmptyGeodatabaseFeatureClass() Method Failed with error message - " + comException.Message + " (" + comException.ErrorCode + " Line:  " + lineNumber.ToString() + ")!");
              }
              int toolMessageCount = geoProcessor.MessageCount;
              int currentToolMessageIndex = 0;
              if (ProcessMessage != null)
              {
            ProcessMessage("The information from the Geoprocessor is:");
              }
              while (currentToolMessageIndex < toolMessageCount)
              {
            //  Write the current message to the log file.
            if (ProcessMessage != null)
            {
              ProcessMessage("   + " + geoProcessor.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.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.EmptyGeodatabaseFeatureClass() 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 Object was instantiated, close it.
            if (geoProcessor != null)
            {
              geoProcessor = null;
            }
            //  If the Geoprocessor Variant Array Object was instantiated, close it.
            if (geoprocessorVariantArray != null)
            {
              geoprocessorVariantArray = null;
            }
            //  If the BTS General Utilities Object was instantiated, close it.
            if (generalUtilities != null)
            {
              generalUtilities = null;
            }

              }

              //  If the process made it to here, it was successful so return TRUE to the calling method.
              return true;
        }
コード例 #5
0
        } //  RUNFMEWorkbenchJob

        /// <summary>
        /// Runs an FME Workbench Job and returns an indicator of whether or not the job completed successfully.
        /// </summary>
        /// <param name="FMEJobName">
        /// The Path and Name of the FME Workbench Job that is to be run.
        /// </param>
        /// <param name="FMEJobParameters">
        /// The parameters necessary to run the FME JOb (String Format).  The parameters will be passed to the FME Workspace Runner Object.
        /// </param>
        /// <param name="ReRunOnError">
        /// Indicator of whether or not the FME Job should be re-run a number of times (3) if it fails the to complete before the re-run
        /// limit has been reached.
        /// </param>
        /// <param name="FMELogFile">
        /// The Path and Name of the FME Session Log File that should be written by this process if one is desired.
        /// </param>
        /// <returns>
        /// TRUE - If the FME Job completed successfully.
        /// FALSE - If the FME Job failed to complete.
        /// </returns>
        public bool RUNFMEWorkbenchJob(string FMEJobName, System.Collections.Specialized.StringCollection FMEJobParameters, bool ReRunOnError = true, string FMELogFile = "")
        {
            PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities = null;
            Safe.FMEObjects.IFMEOWorkspaceRunner fmeWorkspaceRunner = null;

            try
            {
                //  Set the ReTry Attempts Counter to 0.
                int retryAttempts = 0;


                //  Instantiate a Data Maintenance Utilities General Utilities Object.
                generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();
                generalUtilities.ErrorMessage += new SendErrorMessage(HandleErrorMessage);


                //  If a parameter includes a directory path, make sure that path exists.
                string previousValue = "";
                foreach (string currentParameterString in FMEJobParameters)
                {
                    try
                    {
                        //  Determine if the Current Parameter String is a directory Path.
                        if ((System.IO.Path.GetFullPath(currentParameterString).Length > 0) && (System.IO.Path.IsPathRooted(currentParameterString)))
                        {
                            //  Make sure the path exists or can be created.
                            if (!generalUtilities.ConfirmDirectoryPath(System.IO.Path.GetDirectoryName(currentParameterString), true))
                            {
                                //  Let the user know what happened.
                                if (ErrorMessage != null)
                                {
                                    ErrorMessage("Could not confirm the path - " + currentParameterString + " for parameter -" + previousValue + "!  Aborting the Maintools.FMEJobManager.RUNFMEWorkbenchJob() Method.");
                                }
                                //  Return FALSE to the calling method to indicate that this method failed.
                                return(false);
                            }
                        }
                    }
                    catch (System.ArgumentException)
                    {
                        //  This is not a Path so do nothing.
                    }
                    catch (System.NotSupportedException)
                    {
                        //  This is not a Path so do nothing.
                    }
                    catch
                    {
                        //  This is not a Path so do nothing.
                    }

                    //  Set the Current Parameter Value to be the Previous Value for the next value.
                    previousValue = currentParameterString;
                }


                //  This Label will be used when the job run attempt is retryed.
attemptFMEJobReRun:


                //  Default the ReRun Job Indicator Variable to FALSE.
                bool rerunJob = false;


                //  Attempt to run the FME Job in a "TRY" Block so that it can be "re-run" if it fails for a recoverable
                //  reason.  If the failure is not recoverable, do not attempt to re-run the job.
                bool successfullyRanFMEWorkspace = false;
                try
                {
                    //  Let the User know what is happening.
                    if (ProcessMessage != null)
                    {
                        ProcessMessage("      - Preparing the FME Workspace Runner Object that will run the FME Job...");
                    }

                    //  Make sure there is a valid FME Session Object available before attempting to create
                    //  Workspace Runner in it.
                    if (_fmeSession == null)
                    {
                        //  Let the User know what is happening.
                        if (ProcessMessage != null)
                        {
                            ProcessMessage("        + There is not a current valid FME Session, Instantiating one...");
                        }

                        //  Instantiate an FME Session Object.
                        _fmeSession = Safe.FMEObjects.FMEObjects.CreateSession();
                        _fmeSession.Init(null);
                    }


                    //  Create the Workspace Runner in a try block so that any errors can be trapped.
                    try
                    {
                        //  Instantiate the FME Workspace Runner Object.
                        Safe.FMEObjects.IFMEOWorkspaceRunner createFMEWorkspaceRunner = _fmeSession.CreateWorkspaceRunner();
                        fmeWorkspaceRunner = createFMEWorkspaceRunner;
                    }
                    catch (Safe.FMEObjects.FMEOException fmeException)
                    {
                        //  Determine the Line Number from which the exception was thrown.
                        System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(fmeException, true);
                        System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1);
                        int lineNumber = stackFrame.GetFileLineNumber();

                        //  Let the user know what happened.
                        if (ErrorMessage != null)
                        {
                            ErrorMessage("The Process to Create the FME Workspace Runner Object Failed with error - " + fmeException.FmeErrorMessage + " (FME Error Number:  " + fmeException.FmeErrorNumber + " Line:  " + lineNumber.ToString() + ")!");
                        }
                        //  Return FALSE to the calling method to indicate that this method failed.
                        return(false);
                    }
                    catch (System.NullReferenceException nullReferenceException)
                    {
                        //  Determine the Line Number from which the exception was thrown.
                        System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(nullReferenceException, true);
                        System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1);
                        int lineNumber = stackFrame.GetFileLineNumber();

                        //  Let the user know what happened.
                        if (ErrorMessage != null)
                        {
                            ErrorMessage("The Process to Create the FME Workspace Runner Object Failed with error - " + nullReferenceException.Message + " (Line:  " + lineNumber.ToString() + ")!");
                        }
                        //  Return FALSE to the calling method to indicate that this method 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 what happened.
                        if (ErrorMessage != null)
                        {
                            ErrorMessage("The Process to Create the FME Workspace Runner Object Failed with error - " + caught.Message + " (Line:  " + lineNumber.ToString() + ")!");
                        }
                        //  Return FALSE to the calling method to indicate that this method failed.
                        return(false);
                    }


                    //  Let the User know what is happening.
                    if (ProcessMessage != null)
                    {
                        ProcessMessage("      - Running the specified FME Job...");
                    }


                    //  Run the specified FME Workbench Job using the specified parameters.
                    successfullyRanFMEWorkspace = fmeWorkspaceRunner.RunWithParameters(FMEJobName, FMEJobParameters);

                    //  Make sure the job finished successfully before moving on.
                    if (!successfullyRanFMEWorkspace)
                    {
                        //  Determine if the job should be retried.
                        if ((retryAttempts <= 2) && (ReRunOnError))
                        {
                            //  Increment the Retry Attempts Counter.
                            retryAttempts++;
                            //  Let the user know that the job is being re-run.
                            if (ProcessMessage != null)
                            {
                                ProcessMessage("");
                                ProcessMessage("      - The FME Job did not complete successfully!");
                                ProcessMessage("      - Attempting to re-run the FME Job.  Retry attempt - " + retryAttempts.ToString() + "...");
                                ProcessMessage("");
                            }
                            //  Set the ReRun Job Indicator Variable to TRUE.
                            rerunJob = true;
                        }
                    }
                }
                catch (System.IO.IOException ioException)
                {
                    //  Dispose of the current FME Workspace Runner Object since it is no longer needed.
                    fmeWorkspaceRunner.Dispose();

                    //  Determine if the job should be retried.
                    if ((retryAttempts <= 2) && (ReRunOnError))
                    {
                        //  Increment the Retry Attempts Counter.
                        retryAttempts++;
                        //  Let the user know that the job is being re-run.
                        if (ProcessMessage != null)
                        {
                            ProcessMessage("");
                            ProcessMessage("      - The FME failed with exception - " + ioException.Message + "!");
                            ProcessMessage("      - Attempting to re-run the FME Job Due to an exception (" + ioException.Message + ").  Retry attempt - " + retryAttempts.ToString() + "...");
                            ProcessMessage("");
                        }
                        //  Set the ReRun Job Indicator Variable to TRUEM
                        rerunJob = true;
                    }
                    else
                    {
                        //  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 this process failed.
                        if (ErrorMessage != null)
                        {
                            ErrorMessage("The RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with error message:  " + ioException.Message + " (Line:  " + lineNumber.ToString() + ")!");
                        }
                    }
                }
                catch (Safe.FMEObjects.FMEOException fmeException)
                {
                    //  Dispose of the current FME Workspace Runner Object since it is no longer needed.
                    fmeWorkspaceRunner.Dispose();

                    //  If this
                    if (fmeException.FmeErrorMessage.ToUpper().IndexOf("OBJECT INPUT PARAMETER HAS NOT") > -1)
                    {
                        //  Determine if the job should be retried.
                        if ((retryAttempts <= 2) && (ReRunOnError))
                        {
                            //  Increment the Retry Attempts Counter.
                            retryAttempts++;
                            //  Let the user know that the job is being re-run.
                            if (ProcessMessage != null)
                            {
                                ProcessMessage("");
                                ProcessMessage("      - The FME Job failed with FME Exception - " + fmeException.FmeErrorMessage + "(" + fmeException.FmeErrorNumber + ")!");
                                ProcessMessage("      - Attempting to re-run the FME Job.  Retry attempt - " + retryAttempts.ToString() + "...");
                                ProcessMessage("");
                            }
                            //  Set the ReRun Job Indicator Variable to TRUEM
                            rerunJob = true;
                        }
                    }
                    else
                    {
                        //  Determine the Line Number from which the exception was thrown.
                        System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(fmeException, 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 RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with FME error message:  " + fmeException.FmeErrorMessage + " (Line:  " + lineNumber.ToString() + ")!");
                        }
                    }
                }
                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();

                    //  Le the user know that this process failed.
                    if (ErrorMessage != null)
                    {
                        ErrorMessage("The RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with error message:  " + caught.Message + " (Line:  " + lineNumber.ToString() + ")!");
                    }
                }

                //  If necessary, re-run the specified FME Job.
                if (rerunJob)
                {
                    //  Retry to run the job.
                    goto attemptFMEJobReRun;
                }


                //  Close the FME Workspace Runner Object since it is no longer needed.
                fmeWorkspaceRunner.Dispose();


                //  Let the User know whether or not the job finished successfully.
                if (successfullyRanFMEWorkspace)
                {
                    if (ProcessMessage != null)
                    {
                        ProcessMessage("      - The specified FME Job finished successfully...");
                    }
                }
                else
                {
                    if (ErrorMessage != null)
                    {
                        ErrorMessage("The specified FME Workbench Job failed to complete!");
                    }
                }


                //  Return the result of the run to the calling method.
                return(successfullyRanFMEWorkspace);


                ////  If the process made it to here, the job finished successfully so report the successful completion of the job and return TRUE to
                ////  the calling method.
                //if (ProcessMessage != null)
                //{
                //  ProcessMessage("      - The specified FME Job finished successfully...");
                //}
                //return true;
            }
            catch (Safe.FMEObjects.FMEOException fmeException)
            {
                //  Determine the Line Number from which the exception was thrown.
                System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(fmeException, 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 RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with FME error message:  " + fmeException.FmeErrorMessage + " (Line:  " + lineNumber.ToString() + ")!");
                }

                //  Return FALSE to the calling method 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 RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with error message:  " + caught.Message + " (Line:  " + lineNumber.ToString() + ")!");
                }

                //  Return FALSE to the calling method to indicate that this process failed.
                return(false);
            }
            finally
            {
                //  If the BTS Data Maintenance Utilities General Utilities Object was instantiated, close it.
                if (generalUtilities != null)
                {
                    generalUtilities = null;
                }
                //  If the FME Workspace Runner Object was instantiated, close it.
                if (fmeWorkspaceRunner != null)
                {
                    fmeWorkspaceRunner.Dispose();
                    fmeWorkspaceRunner = null;
                }
            }
        } //  RUNFMEWorkbenchJob
コード例 #6
0
        } //  GetLayerSourceInfo()

        public PDX.BTS.DataMaintenance.MaintTools.FeatureClassSourceInfo GetLayerSourceInfo(string FeatureClassName, string OutputGeodatabaseName)
        {
            System.Data.SqlClient.SqlCommand    getSourceInfoSQLCommand    = null;
            System.Data.SqlClient.SqlDataReader getSourceInfoSQLDataReader = null;
            ESRI.ArcGIS.esriSystem.IPropertySet sourcePropertySet          = null;
            PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities      maintenanceGeneralUtilities = null;
            PDX.BTS.DataMaintenance.MaintTools.PathManager           shapefilePathGenerator      = null;
            PDX.BTS.DataMaintenance.MaintTools.FeatureClassUtilities featureClassUtilities       = null;

            try
            {
                //  Make sure there is a valid connection to the Load Metadata Database before attempting to update it.
                if (!ConnecttoImportMonitorDatabase())
                {
                    //  Send a Message to the calling application to let the user know why this process failed.
                    if (ErrorMessage != null)
                    {
                        ErrorMessage("     Could not establish a connection to the Load Metadata Database!  LoaderUtilities.DatabaseTools.GetLayerSourceInfo() Failed!");
                    }

                    //  Return a NULL String to the calling routine to indicate that this process failed.
                    return(null);
                }


                //  Build the SQL Statement that will be used to retrieve the Source Information for the Feature Class.
                string getSourceInfoSQLStatement = "SELECT [Load_Source], [Data_Source], [Dataset], [GeoDB_File], [Source_Server_Name],"
                                                   + "       [Source_Instance], [Source_Database_Name], [Source_Database_User_Name],"
                                                   + "       [Input_Dataset_Name], [Output_Database] "
                                                   + "FROM " + _monitorTableName + " "
                                                   + "WHERE [Feature_Class_Name] = '" + FeatureClassName + "'";


                //  If the Output Geodatabase Name was passed to this method, include it in the query.
                if (!System.String.IsNullOrEmpty(OutputGeodatabaseName))
                {
                    //  Add the Output Geodatabase Name to the SQL Statement.
                    getSourceInfoSQLStatement = getSourceInfoSQLStatement + " AND [Output_Database] = '" + OutputGeodatabaseName + "'";
                }


                //  Build the SQL Command Object that will be used to retrieve the Source Data Info for the specified Feature Class.
                getSourceInfoSQLCommand                = new System.Data.SqlClient.SqlCommand();
                getSourceInfoSQLCommand.Connection     = _importMonitorDatabaseConnection;
                getSourceInfoSQLCommand.CommandType    = System.Data.CommandType.Text;
                getSourceInfoSQLCommand.CommandText    = getSourceInfoSQLStatement;
                getSourceInfoSQLCommand.CommandTimeout = 30;


                //  Use the SQL Command Object that was just instantiated to populate a SQL Data Reader Object with the info about the specified
                //  Feature Class.
                getSourceInfoSQLDataReader = getSourceInfoSQLCommand.ExecuteReader();


                //  Instantiate a Feature Class Source Info Object.
                PDX.BTS.DataMaintenance.MaintTools.FeatureClassSourceInfo currentFeatureClassSourceInfo = new PDX.BTS.DataMaintenance.MaintTools.FeatureClassSourceInfo();

                //  If some information was retrieved, populate a Feature Class Source Info Object and return it to the calling method.  If not,
                //  return a NULL Pointer to indicate that this method failed.
                if (getSourceInfoSQLDataReader.HasRows)
                {
                    if (getSourceInfoSQLDataReader.Read())
                    {
                        //  Populate the New Feature Class Source Info Object with the Source Info for the specified Feature Class.
                        //  Populate the Source Type Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Load_Source")))
                        {
                            currentFeatureClassSourceInfo.SourceType = (string)getSourceInfoSQLDataReader["Load_Source"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceType = "";
                        }
                        //  Populate the Source Data Share Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Data_Source")))
                        {
                            currentFeatureClassSourceInfo.SourceDataShare = (string)getSourceInfoSQLDataReader["Data_Source"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceDataShare = "";
                        }
                        //  Populate the Source Dataset Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Dataset")))
                        {
                            currentFeatureClassSourceInfo.SourceDataset = (string)getSourceInfoSQLDataReader["Dataset"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceDataset = "";
                        }
                        //  Populate the Source Geodatabase File Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("GeoDB_File")))
                        {
                            currentFeatureClassSourceInfo.SourceGeoDBFile = (string)getSourceInfoSQLDataReader["GeoDB_File"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceGeoDBFile = "";
                        }
                        //  Populate the Source Server Name Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Source_Server_Name")))
                        {
                            currentFeatureClassSourceInfo.SourceServerName = (string)getSourceInfoSQLDataReader["Source_Server_Name"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceServerName = "";
                        }
                        //  Populate the Source Instance Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Source_Instance")))
                        {
                            currentFeatureClassSourceInfo.SourceInstance = (string)getSourceInfoSQLDataReader["Source_Instance"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceInstance = "";
                        }
                        //  Populate the Source Database Name Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Source_Database_Name")))
                        {
                            currentFeatureClassSourceInfo.SourceDatabaseName = (string)getSourceInfoSQLDataReader["Source_Database_Name"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceDatabaseName = "";
                        }
                        //  Populate the Source Database User Name Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Source_Database_User_Name")))
                        {
                            currentFeatureClassSourceInfo.SourceDatabaseUser = (string)getSourceInfoSQLDataReader["Source_Database_User_Name"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceDatabaseUser = "";
                        }
                        //  Populate the Input Feature Class Name Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Input_Dataset_Name")))
                        {
                            currentFeatureClassSourceInfo.SourceFeatureClassName = (string)getSourceInfoSQLDataReader["Input_Dataset_Name"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.SourceFeatureClassName = "";
                        }
                        //  Populate the Output Geodatabase Property.
                        if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Output_Database")))
                        {
                            currentFeatureClassSourceInfo.OutputGeodatabaseName = (string)getSourceInfoSQLDataReader["Output_Database"];
                        }
                        else
                        {
                            currentFeatureClassSourceInfo.OutputGeodatabaseName = "";
                        }
                    }
                    else
                    {
                        //  Send a Message to the calling application to let the user know why this process failed.
                        if (ErrorMessage != null)
                        {
                            ErrorMessage("     No Source Information for the Specified Feature Class was found in the Load Metadata Database!  LoaderUtilities.DatabaseTools.GetLayerSourceInfo() Failed!");
                        }
                        //  Return a NULL String to the calling routine to indicate that this process failed.
                        return(null);
                    }
                }
                else
                {
                    //  Send a Message to the calling application to let the user know why this process failed.
                    if (ErrorMessage != null)
                    {
                        ErrorMessage("     The query to retrieve Source Information for the Specified Feature Class failed to retrieve any data from the Load Metadata Database!  LoaderUtilities.DatabaseTools.GetLayerSourceInfo() Failed!");
                    }

                    //  Return a NULL String to the calling routine to indicate that this process failed.
                    return(null);
                }


                //  Instantiate a Feature Class Utilities Object.
                featureClassUtilities = new PDX.BTS.DataMaintenance.MaintTools.FeatureClassUtilities();


                //  Build the Property Set for the Source Dataset and determine its Last Update Date.
                sourcePropertySet = new ESRI.ArcGIS.esriSystem.PropertySet();
                switch (currentFeatureClassSourceInfo.SourceType)
                {
                case "FILEGEODB":
                    //  Build the File Geodatabase PropertySet.
                    sourcePropertySet.SetProperty("DATABASE", currentFeatureClassSourceInfo.SourceGeoDBFile);
                    //  Determine the File Geodatabase Feature Class Last Update Date.
                    currentFeatureClassSourceInfo.SourceLastUpdateDate = featureClassUtilities.GetFileGeodatabaseFeatureClassLastUpdate(currentFeatureClassSourceInfo.SourceGeoDBFile, currentFeatureClassSourceInfo.SourceFeatureClassName);
                    //  Exit this case.
                    break;

                case "PERSONALGEODB":
                    //  Build the Personal Geodatabase PropertySet.
                    sourcePropertySet.SetProperty("DATABASE", currentFeatureClassSourceInfo.SourceGeoDBFile);
                    //  Determine the Source Personal Geodatabase Last Update Date.
                    currentFeatureClassSourceInfo.SourceLastUpdateDate = featureClassUtilities.GetPersonalGeoDBLastUpdateDate(currentFeatureClassSourceInfo.SourceGeoDBFile);
                    //  Exit this case.
                    break;

                case "GEODATABASE":
                    //  Determine the Server User Password.
                    maintenanceGeneralUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();
                    string serverUserPassword = maintenanceGeneralUtilities.RetrieveParameterValue(currentFeatureClassSourceInfo.SourceDatabaseUser + "_Password", _parameterTableName, _parameterDatabaseConnectionString, true);
                    //  Build the Enterprise Geodatabase Property Set.
                    sourcePropertySet.SetProperty("SERVER", currentFeatureClassSourceInfo.SourceServerName);
                    sourcePropertySet.SetProperty("INSTANCE", currentFeatureClassSourceInfo.SourceInstance);
                    sourcePropertySet.SetProperty("DATABASE", currentFeatureClassSourceInfo.SourceDatabaseName);
                    sourcePropertySet.SetProperty("USER", currentFeatureClassSourceInfo.SourceDatabaseUser);
                    sourcePropertySet.SetProperty("PASSWORD", serverUserPassword);
                    sourcePropertySet.SetProperty("VERSION", "SDE.Default");
                    //  Determine the Enterprise Geodatabase Feature Class Last Udpate Date.
                    currentFeatureClassSourceInfo.SourceLastUpdateDate = featureClassUtilities.GetEntGeoDBFeatureClassLastUpdate(currentFeatureClassSourceInfo.SourceFeatureClassName, currentFeatureClassSourceInfo.SourceServerName, currentFeatureClassSourceInfo.SourceDatabaseName, currentFeatureClassSourceInfo.SourceDatabaseUser, serverUserPassword);
                    //  Exit this case.
                    break;

                case "SHAPEFILE":
                    //  Instantiate a City of Portland Path Manager Object that will be used to determine the Path to the Source Shapefile.
                    shapefilePathGenerator = new PDX.BTS.DataMaintenance.MaintTools.PathManager();
                    string shapefileDirectoryPath = shapefilePathGenerator.BuildShapefileDirectoryPath(currentFeatureClassSourceInfo.SourceDataShare, currentFeatureClassSourceInfo.SourceDataset, currentFeatureClassSourceInfo.SourceFeatureClassName);
                    //  Build the Shapefile PropertySet.
                    sourcePropertySet.SetProperty("DATABASE", shapefileDirectoryPath);
                    //  Determine the Source Shapefile Last Update Date.
                    string fullShapefilePath = shapefilePathGenerator.BuildShapefilePath(currentFeatureClassSourceInfo.SourceDataShare, currentFeatureClassSourceInfo.SourceDataset, currentFeatureClassSourceInfo.SourceFeatureClassName);
                    currentFeatureClassSourceInfo.SourceLastUpdateDate = featureClassUtilities.GetShapefileLastUpdateDate(fullShapefilePath);
                    //  Exit this case.
                    break;

                default:
                    //  Exit this case.
                    break;
                }

                //  Set the Source PropertySet Property of the Current Source Feature Class Info Object.
                currentFeatureClassSourceInfo.SourceDatasetPropertySet = sourcePropertySet;


                //  Return the populated Current Feature Class Source Info Object to the calling method.
                return(currentFeatureClassSourceInfo);
            }
            catch (Exception caught)
            {
                //  Send a Message to the calling application to let the user know why this process failed.
                if (ErrorMessage != null)
                {
                    ErrorMessage("    The LoaderUtilities.DatabaseTools.GetLayerSourceInfo() Method Failed with error message:  " + caught.Message);
                }

                //  Return a NULL String to the calling routine to indicate that this process failed.
                return(null);
            }
            finally
            {
                //  If the Get Source Info SQL Data Reader Object was instantiated, close it.
                if (getSourceInfoSQLDataReader != null)
                {
                    if (!getSourceInfoSQLDataReader.IsClosed)
                    {
                        getSourceInfoSQLDataReader.Close();
                    }
                    getSourceInfoSQLDataReader.Dispose();
                    getSourceInfoSQLDataReader = null;
                }
                //  If the Get Source Info SQL Command Object was instantiated, close it.
                if (getSourceInfoSQLCommand != null)
                {
                    getSourceInfoSQLCommand.Dispose();
                    getSourceInfoSQLCommand = null;
                }
            }
        } //  GetLayerSourceInfo()
コード例 #7
0
        public PDX.BTS.DataMaintenance.MaintTools.FeatureClassSourceInfo GetLayerSourceInfo(string FeatureClassName, string OutputGeodatabaseName)
        {
            System.Data.SqlClient.SqlCommand                         getSourceInfoSQLCommand     = null;
              System.Data.SqlClient.SqlDataReader                      getSourceInfoSQLDataReader  = null;
              ESRI.ArcGIS.esriSystem.IPropertySet                      sourcePropertySet           = null;
              PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities      maintenanceGeneralUtilities = null;
              PDX.BTS.DataMaintenance.MaintTools.PathManager           shapefilePathGenerator      = null;
              PDX.BTS.DataMaintenance.MaintTools.FeatureClassUtilities featureClassUtilities       = null;

              try
              {
            //  Make sure there is a valid connection to the Load Metadata Database before attempting to update it.
            if (!ConnecttoImportMonitorDatabase())
            {
              //  Send a Message to the calling application to let the user know why this process failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("     Could not establish a connection to the Load Metadata Database!  LoaderUtilities.DatabaseTools.GetLayerSourceInfo() Failed!");
              }

              //  Return a NULL String to the calling routine to indicate that this process failed.
              return null;

            }

            //  Build the SQL Statement that will be used to retrieve the Source Information for the Feature Class.
            string getSourceInfoSQLStatement = "SELECT [Load_Source], [Data_Source], [Dataset], [GeoDB_File], [Source_Server_Name],"
                                         + "       [Source_Instance], [Source_Database_Name], [Source_Database_User_Name],"
                                         + "       [Input_Dataset_Name], [Output_Database] "
                                         + "FROM " + _monitorTableName + " "
                                         + "WHERE [Feature_Class_Name] = '" + FeatureClassName + "'";

            //  If the Output Geodatabase Name was passed to this method, include it in the query.
            if (!System.String.IsNullOrEmpty(OutputGeodatabaseName))
            {
              //  Add the Output Geodatabase Name to the SQL Statement.
              getSourceInfoSQLStatement = getSourceInfoSQLStatement + " AND [Output_Database] = '" + OutputGeodatabaseName + "'";

            }

            //  Build the SQL Command Object that will be used to retrieve the Source Data Info for the specified Feature Class.
            getSourceInfoSQLCommand = new System.Data.SqlClient.SqlCommand();
            getSourceInfoSQLCommand.Connection = _importMonitorDatabaseConnection;
            getSourceInfoSQLCommand.CommandType = System.Data.CommandType.Text;
            getSourceInfoSQLCommand.CommandText = getSourceInfoSQLStatement;
            getSourceInfoSQLCommand.CommandTimeout = 30;

            //  Use the SQL Command Object that was just instantiated to populate a SQL Data Reader Object with the info about the specified
            //  Feature Class.
            getSourceInfoSQLDataReader = getSourceInfoSQLCommand.ExecuteReader();

            //  Instantiate a Feature Class Source Info Object.
            PDX.BTS.DataMaintenance.MaintTools.FeatureClassSourceInfo currentFeatureClassSourceInfo = new PDX.BTS.DataMaintenance.MaintTools.FeatureClassSourceInfo();

            //  If some information was retrieved, populate a Feature Class Source Info Object and return it to the calling method.  If not,
            //  return a NULL Pointer to indicate that this method failed.
            if (getSourceInfoSQLDataReader.HasRows)
            {
              if (getSourceInfoSQLDataReader.Read())
              {
            //  Populate the New Feature Class Source Info Object with the Source Info for the specified Feature Class.
            //  Populate the Source Type Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Load_Source")))
            {
              currentFeatureClassSourceInfo.SourceType = (string)getSourceInfoSQLDataReader["Load_Source"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceType = "";
            }
            //  Populate the Source Data Share Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Data_Source")))
            {
              currentFeatureClassSourceInfo.SourceDataShare = (string)getSourceInfoSQLDataReader["Data_Source"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceDataShare = "";
            }
            //  Populate the Source Dataset Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Dataset")))
            {
              currentFeatureClassSourceInfo.SourceDataset = (string)getSourceInfoSQLDataReader["Dataset"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceDataset = "";
            }
            //  Populate the Source Geodatabase File Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("GeoDB_File")))
            {
              currentFeatureClassSourceInfo.SourceGeoDBFile = (string)getSourceInfoSQLDataReader["GeoDB_File"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceGeoDBFile = "";
            }
            //  Populate the Source Server Name Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Source_Server_Name")))
            {
              currentFeatureClassSourceInfo.SourceServerName = (string)getSourceInfoSQLDataReader["Source_Server_Name"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceServerName = "";
            }
            //  Populate the Source Instance Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Source_Instance")))
            {
              currentFeatureClassSourceInfo.SourceInstance = (string)getSourceInfoSQLDataReader["Source_Instance"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceInstance = "";
            }
            //  Populate the Source Database Name Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Source_Database_Name")))
            {
              currentFeatureClassSourceInfo.SourceDatabaseName = (string)getSourceInfoSQLDataReader["Source_Database_Name"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceDatabaseName = "";
            }
            //  Populate the Source Database User Name Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Source_Database_User_Name")))
            {
              currentFeatureClassSourceInfo.SourceDatabaseUser = (string)getSourceInfoSQLDataReader["Source_Database_User_Name"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceDatabaseUser = "";
            }
            //  Populate the Input Feature Class Name Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Input_Dataset_Name")))
            {
              currentFeatureClassSourceInfo.SourceFeatureClassName = (string)getSourceInfoSQLDataReader["Input_Dataset_Name"];
            }
            else
            {
              currentFeatureClassSourceInfo.SourceFeatureClassName = "";
            }
            //  Populate the Output Geodatabase Property.
            if (!getSourceInfoSQLDataReader.IsDBNull(getSourceInfoSQLDataReader.GetOrdinal("Output_Database")))
            {
              currentFeatureClassSourceInfo.OutputGeodatabaseName = (string)getSourceInfoSQLDataReader["Output_Database"];
            }
            else
            {
              currentFeatureClassSourceInfo.OutputGeodatabaseName = "";
            }
              }
              else
              {
            //  Send a Message to the calling application to let the user know why this process failed.
            if (ErrorMessage != null)
            {
              ErrorMessage("     No Source Information for the Specified Feature Class was found in the Load Metadata Database!  LoaderUtilities.DatabaseTools.GetLayerSourceInfo() Failed!");
            }
            //  Return a NULL String to the calling routine to indicate that this process failed.
            return null;
              }

            }
            else
            {
              //  Send a Message to the calling application to let the user know why this process failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("     The query to retrieve Source Information for the Specified Feature Class failed to retrieve any data from the Load Metadata Database!  LoaderUtilities.DatabaseTools.GetLayerSourceInfo() Failed!");
              }

              //  Return a NULL String to the calling routine to indicate that this process failed.
              return null;

            }

            //  Instantiate a Feature Class Utilities Object.
            featureClassUtilities = new PDX.BTS.DataMaintenance.MaintTools.FeatureClassUtilities();

            //  Build the Property Set for the Source Dataset and determine its Last Update Date.
            sourcePropertySet = new ESRI.ArcGIS.esriSystem.PropertySet();
            switch (currentFeatureClassSourceInfo.SourceType)
            {
              case "FILEGEODB":
            //  Build the File Geodatabase PropertySet.
            sourcePropertySet.SetProperty("DATABASE", currentFeatureClassSourceInfo.SourceGeoDBFile);
            //  Determine the File Geodatabase Feature Class Last Update Date.
            currentFeatureClassSourceInfo.SourceLastUpdateDate = featureClassUtilities.GetFileGeodatabaseFeatureClassLastUpdate(currentFeatureClassSourceInfo.SourceGeoDBFile, currentFeatureClassSourceInfo.SourceFeatureClassName);
            //  Exit this case.
            break;
              case "PERSONALGEODB":
            //  Build the Personal Geodatabase PropertySet.
            sourcePropertySet.SetProperty("DATABASE", currentFeatureClassSourceInfo.SourceGeoDBFile);
            //  Determine the Source Personal Geodatabase Last Update Date.
            currentFeatureClassSourceInfo.SourceLastUpdateDate = featureClassUtilities.GetPersonalGeoDBLastUpdateDate(currentFeatureClassSourceInfo.SourceGeoDBFile);
            //  Exit this case.
            break;
              case "GEODATABASE":
            //  Determine the Server User Password.
            maintenanceGeneralUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();
            string serverUserPassword = maintenanceGeneralUtilities.RetrieveParameterValue(currentFeatureClassSourceInfo.SourceDatabaseUser + "_Password", _parameterTableName, _parameterDatabaseConnectionString, true);
            //  Build the Enterprise Geodatabase Property Set.
            sourcePropertySet.SetProperty("SERVER", currentFeatureClassSourceInfo.SourceServerName);
            sourcePropertySet.SetProperty("INSTANCE", currentFeatureClassSourceInfo.SourceInstance);
            sourcePropertySet.SetProperty("DATABASE", currentFeatureClassSourceInfo.SourceDatabaseName);
            sourcePropertySet.SetProperty("USER", currentFeatureClassSourceInfo.SourceDatabaseUser);
            sourcePropertySet.SetProperty("PASSWORD", serverUserPassword);
            sourcePropertySet.SetProperty("VERSION", "SDE.Default");
            //  Determine the Enterprise Geodatabase Feature Class Last Udpate Date.
            currentFeatureClassSourceInfo.SourceLastUpdateDate = featureClassUtilities.GetEntGeoDBFeatureClassLastUpdate(currentFeatureClassSourceInfo.SourceFeatureClassName, currentFeatureClassSourceInfo.SourceServerName, currentFeatureClassSourceInfo.SourceDatabaseName, currentFeatureClassSourceInfo.SourceDatabaseUser, serverUserPassword);
            //  Exit this case.
            break;
              case "SHAPEFILE":
            //  Instantiate a City of Portland Path Manager Object that will be used to determine the Path to the Source Shapefile.
            shapefilePathGenerator = new PDX.BTS.DataMaintenance.MaintTools.PathManager();
            string shapefileDirectoryPath = shapefilePathGenerator.BuildShapefileDirectoryPath(currentFeatureClassSourceInfo.SourceDataShare, currentFeatureClassSourceInfo.SourceDataset, currentFeatureClassSourceInfo.SourceFeatureClassName);
            //  Build the Shapefile PropertySet.
            sourcePropertySet.SetProperty("DATABASE", shapefileDirectoryPath);
            //  Determine the Source Shapefile Last Update Date.
            string fullShapefilePath = shapefilePathGenerator.BuildShapefilePath(currentFeatureClassSourceInfo.SourceDataShare, currentFeatureClassSourceInfo.SourceDataset, currentFeatureClassSourceInfo.SourceFeatureClassName);
            currentFeatureClassSourceInfo.SourceLastUpdateDate = featureClassUtilities.GetShapefileLastUpdateDate(fullShapefilePath);
            //  Exit this case.
            break;
              default:
            //  Exit this case.
            break;
            }

            //  Set the Source PropertySet Property of the Current Source Feature Class Info Object.
            currentFeatureClassSourceInfo.SourceDatasetPropertySet = sourcePropertySet;

            //  Return the populated Current Feature Class Source Info Object to the calling method.
            return currentFeatureClassSourceInfo;

              }
              catch (Exception caught)
              {
            //  Send a Message to the calling application to let the user know why this process failed.
            if (ErrorMessage != null)
            {
              ErrorMessage("    The LoaderUtilities.DatabaseTools.GetLayerSourceInfo() Method Failed with error message:  " + caught.Message);
            }

            //  Return a NULL String to the calling routine to indicate that this process failed.
            return null;

              }
              finally
              {
            //  If the Get Source Info SQL Data Reader Object was instantiated, close it.
            if (getSourceInfoSQLDataReader != null)
            {
              if (!getSourceInfoSQLDataReader.IsClosed)
              {
            getSourceInfoSQLDataReader.Close();
              }
              getSourceInfoSQLDataReader.Dispose();
              getSourceInfoSQLDataReader = null;
            }
            //  If the Get Source Info SQL Command Object was instantiated, close it.
            if (getSourceInfoSQLCommand != null)
            {
              getSourceInfoSQLCommand.Dispose();
              getSourceInfoSQLCommand = null;
            }

              }
        }
コード例 #8
0
        /// <summary>
        /// Runs an FME Workbench Job and returns an indicator of whether or not the job completed successfully.
        /// </summary>
        /// <param name="FMEJobName">
        /// The Path and Name of the FME Workbench Job that is to be run.
        /// </param>
        /// <param name="FMEJobParameters">
        /// The parameters necessary to run the FME JOb (String Format).  The parameters will be passed to the FME Workspace Runner Object.
        /// </param>
        /// <param name="ReRunOnError">
        /// Indicator of whether or not the FME Job should be re-run a number of times (3) if it fails the to complete before the re-run
        /// limit has been reached.
        /// </param>
        /// <param name="FMELogFile">
        /// The Path and Name of the FME Session Log File that should be written by this process if one is desired.
        /// </param>
        /// <returns>
        /// TRUE - If the FME Job completed successfully.
        /// FALSE - If the FME Job failed to complete.
        /// </returns>
        public bool RUNFMEWorkbenchJob(string FMEJobName, System.Collections.Specialized.StringCollection FMEJobParameters, bool ReRunOnError = true, string FMELogFile = "")
        {
            PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities generalUtilities   = null;
              Safe.FMEObjects.IFMEOWorkspaceRunner                fmeWorkspaceRunner = null;

              try
              {
            //  Set the ReTry Attempts Counter to 0.
            int retryAttempts = 0;

            //  Instantiate a Data Maintenance Utilities General Utilities Object.
            generalUtilities = new PDX.BTS.DataMaintenance.MaintTools.GeneralUtilities();
            generalUtilities.ErrorMessage += new SendErrorMessage(HandleErrorMessage);

            //  If a parameter includes a directory path, make sure that path exists.
            string previousValue = "";
            foreach(string currentParameterString in FMEJobParameters)
            {
              try
              {
            //  Determine if the Current Parameter String is a directory Path.
            if ((System.IO.Path.GetFullPath(currentParameterString).Length > 0) && (System.IO.Path.IsPathRooted(currentParameterString)))
            {
              //  Make sure the path exists or can be created.
              if (!generalUtilities.ConfirmDirectoryPath(System.IO.Path.GetDirectoryName(currentParameterString), true))
              {
                //  Let the user know what happened.
                if (ErrorMessage != null)
                {
                  ErrorMessage("Could not confirm the path - " + currentParameterString + " for parameter -" + previousValue + "!  Aborting the Maintools.FMEJobManager.RUNFMEWorkbenchJob() Method.");
                }
                //  Return FALSE to the calling method to indicate that this method failed.
                return false;
              }
            }
              }
              catch(System.ArgumentException)
              {
            //  This is not a Path so do nothing.
              }
              catch (System.NotSupportedException)
              {
            //  This is not a Path so do nothing.
              }
              catch
              {
            //  This is not a Path so do nothing.
              }

              //  Set the Current Parameter Value to be the Previous Value for the next value.
              previousValue = currentParameterString;

            }

            //  This Label will be used when the job run attempt is retryed.
            attemptFMEJobReRun:

            //  Default the ReRun Job Indicator Variable to FALSE.
            bool rerunJob = false;

            //  Attempt to run the FME Job in a "TRY" Block so that it can be "re-run" if it fails for a recoverable
            //  reason.  If the failure is not recoverable, do not attempt to re-run the job.
            bool successfullyRanFMEWorkspace = false;
            try
            {
              //  Let the User know what is happening.
              if (ProcessMessage != null)
              {
            ProcessMessage("      - Preparing the FME Workspace Runner Object that will run the FME Job...");

              }

              //  Make sure there is a valid FME Session Object available before attempting to create
              //  Workspace Runner in it.
              if (_fmeSession == null)
              {
            //  Let the User know what is happening.
            if (ProcessMessage != null)
            {
              ProcessMessage("        + There is not a current valid FME Session, Instantiating one...");
            }

            //  Instantiate an FME Session Object.
            _fmeSession = Safe.FMEObjects.FMEObjects.CreateSession();
            _fmeSession.Init(null);

              }

              //  Create the Workspace Runner in a try block so that any errors can be trapped.
              try
              {
            //  Instantiate the FME Workspace Runner Object.
            Safe.FMEObjects.IFMEOWorkspaceRunner createFMEWorkspaceRunner = _fmeSession.CreateWorkspaceRunner();
            fmeWorkspaceRunner = createFMEWorkspaceRunner;
              }
              catch (Safe.FMEObjects.FMEOException fmeException)
              {
            //  Determine the Line Number from which the exception was thrown.
            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(fmeException, true);
            System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1);
            int lineNumber = stackFrame.GetFileLineNumber();

            //  Let the user know what happened.
            if (ErrorMessage != null)
            {
              ErrorMessage("The Process to Create the FME Workspace Runner Object Failed with error - " + fmeException.FmeErrorMessage + " (FME Error Number:  " + fmeException.FmeErrorNumber + " Line:  " + lineNumber.ToString() + ")!");
            }
            //  Return FALSE to the calling method to indicate that this method failed.
            return false;
              }
              catch (System.NullReferenceException nullReferenceException)
              {
            //  Determine the Line Number from which the exception was thrown.
            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(nullReferenceException, true);
            System.Diagnostics.StackFrame stackFrame = stackTrace.GetFrame(stackTrace.FrameCount - 1);
            int lineNumber = stackFrame.GetFileLineNumber();

            //  Let the user know what happened.
            if (ErrorMessage != null)
            {
              ErrorMessage("The Process to Create the FME Workspace Runner Object Failed with error - " + nullReferenceException.Message + " (Line:  " + lineNumber.ToString() + ")!");
            }
            //  Return FALSE to the calling method to indicate that this method 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 what happened.
            if (ErrorMessage != null)
            {
              ErrorMessage("The Process to Create the FME Workspace Runner Object Failed with error - " + caught.Message + " (Line:  " + lineNumber.ToString() + ")!");
            }
            //  Return FALSE to the calling method to indicate that this method failed.
            return false;
              }

              //  Let the User know what is happening.
              if (ProcessMessage != null)
              {
            ProcessMessage("      - Running the specified FME Job...");

              }

              //  Run the specified FME Workbench Job using the specified parameters.
              successfullyRanFMEWorkspace = fmeWorkspaceRunner.RunWithParameters(FMEJobName, FMEJobParameters);

              //  Make sure the job finished successfully before moving on.
              if (!successfullyRanFMEWorkspace)
              {
            //  Determine if the job should be retried.
            if ((retryAttempts <= 2) && (ReRunOnError))
            {
              //  Increment the Retry Attempts Counter.
              retryAttempts++;
              //  Let the user know that the job is being re-run.
              if (ProcessMessage != null)
              {
                ProcessMessage("");
                ProcessMessage("      - The FME Job did not complete successfully!");
                ProcessMessage("      - Attempting to re-run the FME Job.  Retry attempt - " + retryAttempts.ToString() + "...");
                ProcessMessage("");
              }
              //  Set the ReRun Job Indicator Variable to TRUE.
              rerunJob = true;
            }

              }

            }
            catch (System.IO.IOException ioException)
            {
              //  Dispose of the current FME Workspace Runner Object since it is no longer needed.
              fmeWorkspaceRunner.Dispose();

              //  Determine if the job should be retried.
              if ((retryAttempts <= 2) && (ReRunOnError))
              {
            //  Increment the Retry Attempts Counter.
            retryAttempts++;
            //  Let the user know that the job is being re-run.
            if (ProcessMessage != null)
            {
              ProcessMessage("");
              ProcessMessage("      - The FME failed with exception - " + ioException.Message + "!");
              ProcessMessage("      - Attempting to re-run the FME Job Due to an exception (" + ioException.Message + ").  Retry attempt - " + retryAttempts.ToString() + "...");
              ProcessMessage("");
            }
            //  Set the ReRun Job Indicator Variable to TRUEM
            rerunJob = true;
              }
              else
              {
            //  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 this process failed.
            if (ErrorMessage != null)
            {
              ErrorMessage("The RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with error message:  " + ioException.Message + " (Line:  " + lineNumber.ToString() + ")!");
            }
              }

            }
            catch (Safe.FMEObjects.FMEOException fmeException)
            {
              //  Dispose of the current FME Workspace Runner Object since it is no longer needed.
              fmeWorkspaceRunner.Dispose();

              //  If this
              if (fmeException.FmeErrorMessage.ToUpper().IndexOf("OBJECT INPUT PARAMETER HAS NOT") > -1)
              {
            //  Determine if the job should be retried.
            if ((retryAttempts <= 2) && (ReRunOnError))
            {
              //  Increment the Retry Attempts Counter.
              retryAttempts++;
              //  Let the user know that the job is being re-run.
              if (ProcessMessage != null)
              {
                ProcessMessage("");
                ProcessMessage("      - The FME Job failed with FME Exception - " + fmeException.FmeErrorMessage + "(" + fmeException.FmeErrorNumber + ")!");
                ProcessMessage("      - Attempting to re-run the FME Job.  Retry attempt - " + retryAttempts.ToString() + "...");
                ProcessMessage("");
              }
              //  Set the ReRun Job Indicator Variable to TRUEM
              rerunJob = true;
            }
              }
              else
              {
            //  Determine the Line Number from which the exception was thrown.
            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(fmeException, 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 RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with FME error message:  " + fmeException.FmeErrorMessage + " (Line:  " + lineNumber.ToString() + ")!");
            }
              }

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

              //  Le the user know that this process failed.
              if (ErrorMessage != null)
              {
            ErrorMessage("The RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with error message:  " + caught.Message + " (Line:  " + lineNumber.ToString() + ")!");
              }

            }

            //  If necessary, re-run the specified FME Job.
            if (rerunJob)
            {
              //  Retry to run the job.
              goto attemptFMEJobReRun;
            }

            //  Close the FME Workspace Runner Object since it is no longer needed.
            fmeWorkspaceRunner.Dispose();

            //  Let the User know whether or not the job finished successfully.
            if (successfullyRanFMEWorkspace)
            {
              if (ProcessMessage != null)
              {
            ProcessMessage("      - The specified FME Job finished successfully...");
              }

            }
            else
            {
              if (ErrorMessage != null)
              {
            ErrorMessage("The specified FME Workbench Job failed to complete!");
              }

            }

            //  Return the result of the run to the calling method.
            return successfullyRanFMEWorkspace;

            ////  If the process made it to here, the job finished successfully so report the successful completion of the job and return TRUE to
            ////  the calling method.
            //if (ProcessMessage != null)
            //{
            //  ProcessMessage("      - The specified FME Job finished successfully...");
            //}
            //return true;

              }
              catch (Safe.FMEObjects.FMEOException fmeException)
              {
            //  Determine the Line Number from which the exception was thrown.
            System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(fmeException, 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 RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with FME error message:  " + fmeException.FmeErrorMessage + " (Line:  " + lineNumber.ToString() + ")!");

            }

            //  Return FALSE to the calling method 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 RunFMEWorkbenchJob(FMEJobName, FMEJobParameters(Collection), ServerFMELogFile) failed with error message:  " + caught.Message + " (Line:  " + lineNumber.ToString() + ")!");

            }

            //  Return FALSE to the calling method to indicate that this process failed.
            return false;

              }
              finally
              {
            //  If the BTS Data Maintenance Utilities General Utilities Object was instantiated, close it.
            if (generalUtilities != null)
            {
              generalUtilities = null;
            }
            //  If the FME Workspace Runner Object was instantiated, close it.
            if (fmeWorkspaceRunner != null)
            {
              fmeWorkspaceRunner.Dispose();
              fmeWorkspaceRunner = null;
            }

              }
        }