Пример #1
0
        private string ReplaceToken(string token, IJTXDatabase pDB, IJTXJob pJob, ESRI.ArcGIS.esriSystem.IPropertySet pOverrides)
        {
            string tokenout = token;

            // Drop the [] and convert to uppercase
            token = token.Substring(1, token.Length - 2).ToUpper();

            // Split the prefix from the actual token
            string[] parts = token.Split(new char[] { ':' }, 2);
            // make sure it is a environment token (starts with "ENV:")
            if (parts.Length == 2)
            {
                if (parts[0].Equals("ENV"))
                {
                    // try to get the env variable
                    string value = Environment.GetEnvironmentVariable(parts[1]);
                    if (value != null)
                    {
                        tokenout = value;
                    }
                }
            }

            return(tokenout);
        }
Пример #2
0
        public string Parse(string sourceText, IJTXDatabase pDB, IJTXJob pJob, ESRI.ArcGIS.esriSystem.IPropertySet pOverrides)
        {
            // Find the token
            string strSource = sourceText;
            string strFinal  = sourceText;
            int    curpos    = strSource.IndexOf('[');
            int    startmarker;
            int    endmarker = -1;
            int    nestedcount;
            int    curtokenpos;

            string strToken;
            string strNewValue;

            while (curpos >= 0)
            {
                nestedcount = 1;
                curtokenpos = curpos + 1;
                strToken    = "";
                //need to find the whole token (including any nested tokens)
                while (nestedcount > 0)
                {
                    startmarker = strSource.IndexOf('[', curtokenpos);
                    endmarker   = strSource.IndexOf(']', curtokenpos);

                    if (startmarker >= 0 && startmarker < endmarker)
                    {
                        nestedcount++;
                        curtokenpos = startmarker + 1;
                    }
                    else if (endmarker < 0)
                    {
                        break;
                    }
                    else
                    {
                        nestedcount--;
                        curtokenpos = endmarker + 1;
                    }
                }
                if (endmarker >= 0)
                {
                    strToken    = strSource.Substring(curpos, endmarker - curpos + 1);
                    strNewValue = ReplaceToken(strToken, pDB, pJob, pOverrides);
                    strFinal    = strFinal.Replace(strToken, strNewValue);
                }

                curpos = strSource.IndexOf('[', curpos + 1);
            }

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