Пример #1
0
        public static string GetDatasetName(IDataset ds)
        {
            if (ds != null)
            {
                ISQLSyntax sqlSyntax = ds.Workspace as ISQLSyntax;
                string     dbName, ownerName, tableName;
                sqlSyntax.ParseTableName(ds.Name, out dbName, out ownerName, out tableName);

                return(tableName);
            }

            return("");
        }
Пример #2
0
        public static string ParseTableName(IDataset dataset)
        {
            if (dataset == null)
            {
                throw new ArgumentNullException("dataset");
            }
            string     dbName    = string.Empty;
            string     tableName = string.Empty;
            string     ownerName = string.Empty;
            ISQLSyntax syntax    = (ISQLSyntax)dataset.Workspace;

            syntax.ParseTableName(dataset.Name, out dbName, out ownerName, out tableName);
            return(tableName);
        }
Пример #3
0
        //OK
        public string GetDataSetName(IFeatureClass featureClass)
        {
            IDataset   dataSet   = featureClass as IDataset;
            ISQLSyntax sqlSyntax = dataSet.Workspace as ISQLSyntax;

            if (sqlSyntax != null)
            {
                string dataName  = string.Empty;
                string dbName    = string.Empty;
                string ownerName = string.Empty;
                sqlSyntax.ParseTableName(dataSet.Name, out dbName, out ownerName, out dataName);
                return(dataName);
            }
            else
            {
                return(dataSet.Name);
            }
        }
        void OnDeleteFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
        {
            // Don't do anything if the extension is disabled
            if (IsExtensionEnabled != true)
            {
                return;
            }

            // Bail if this is not a valid NCGMP workspace
            if (m_DatabaseIsValid == false)
            {
                return;
            }

            #region "Groundwork"
            // Grab the FeatureClass name from the Row's Table (as an IDataset).
            IRow     theRow    = obj;
            ITable   theTable  = theRow.Table;
            IDataset theDS     = (IDataset)theTable;
            string   TableName = theDS.Name;

            // Parse the table name in order to strip out unneccessary bits of SDE tables
            ISQLSyntax nameParser = (ISQLSyntax)theDS.Workspace;
            string     parsedDbName, parsedOwnerName, parsedTableName;
            nameParser.ParseTableName(TableName, out parsedDbName, out parsedOwnerName, out parsedTableName);
            #endregion

            //    #region "Delete Related Station Data"
            //    if (parsedTableName == "Stations")
            //    {
            //        // Get the related information first, then prompt, then delete if that's what they want.
            //        string stationName = (string)theRow.get_Value(theTable.FindField("FieldID"));
            //        IRelationshipClass stationStructureLink = commonFunctions.OpenRelationshipClass(m_EditWorkspace, "StationOrientationPointsLink");
            //        IRelationshipClass stationSamplesLink = commonFunctions.OpenRelationshipClass(m_EditWorkspace, "StationSampleLink");
            //        IRelationshipClass stationNotesLink = commonFunctions.OpenRelationshipClass(m_EditWorkspace, "StationNotesLink");
            //        IRelationshipClass stationDocsLink = commonFunctions.OpenRelationshipClass(m_EditWorkspace, "StationDocumentLink");

            //        ESRI.ArcGIS.esriSystem.ISet structureSet = stationStructureLink.GetObjectsRelatedToObject(obj);
            //        ESRI.ArcGIS.esriSystem.ISet sampleSet = stationSamplesLink.GetObjectsRelatedToObject(obj);
            //        ESRI.ArcGIS.esriSystem.ISet noteSet = stationNotesLink.GetObjectsRelatedToObject(obj);
            //        ESRI.ArcGIS.esriSystem.ISet docSet = stationDocsLink.GetObjectsRelatedToObject(obj);

            //        string theMessage = ("Deleting Station " + stationName + " will also delete the following:");
            //        theMessage += Environment.NewLine;
            //        theMessage += structureSet.Count.ToString() + " structural observations";
            //        theMessage += Environment.NewLine;
            //        theMessage += sampleSet.Count.ToString() + " sample locations";
            //        theMessage += Environment.NewLine;
            //        theMessage += noteSet.Count.ToString() + " recorded notes";
            //        theMessage += Environment.NewLine;
            //        theMessage += docSet.Count.ToString() + " related document links";
            //        theMessage += Environment.NewLine;
            //        theMessage += Environment.NewLine;
            //        theMessage += "Are you sure you want to do this?";

            //        // Probably would be wise to warn them first...
            //        System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show(theMessage, "NCGMP Tools", System.Windows.Forms.MessageBoxButtons.YesNo);
            //        if (result == System.Windows.Forms.DialogResult.Yes)
            //        {
            //            IFeature theFeature = (IFeature)structureSet.Next();
            //            while (theFeature != null)
            //            {
            //                theFeature.Delete();
            //                theFeature = (IFeature)structureSet.Next();
            //            }
            //            theFeature = (IFeature)sampleSet.Next();
            //            while (theFeature != null)
            //            {
            //                theFeature.Delete();
            //                theFeature = (IFeature)sampleSet.Next();
            //            }
            //            theFeature = (IFeature)noteSet.Next();
            //            while (theFeature != null)
            //            {
            //                theFeature.Delete();
            //                theFeature = (IFeature)noteSet.Next();
            //            }
            //            theFeature = (IFeature)docSet.Next();
            //            while (theFeature != null)
            //            {
            //                theFeature.Delete();
            //                theFeature = (IFeature)docSet.Next();
            //            }
            //        }
            //    }
            //    #endregion
        }
        void OnChangeFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
        {
            // Don't do anything if the extension is disabled
            if (IsExtensionEnabled != true)
            {
                return;
            }

            // Bail if this is not a valid NCGMP workspace
            if (m_DatabaseIsValid == false)
            {
                return;
            }

            #region "Groundwork"
            // Grab the FeatureClass name from the Row's Table (as an IDataset).
            IRow     theRow    = obj;
            ITable   theTable  = theRow.Table;
            IDataset theDS     = (IDataset)theTable;
            string   TableName = theDS.Name;

            // Parse the table name in order to strip out unneccessary bits of SDE tables
            ISQLSyntax nameParser = (ISQLSyntax)theDS.Workspace;
            string     parsedDbName, parsedOwnerName, parsedTableName;
            nameParser.ParseTableName(TableName, out parsedDbName, out parsedOwnerName, out parsedTableName);
            #endregion

            #region "Calculate SymbolRotation"
            if (m_DatabaseUsesRepresentation == true)
            {
                if (parsedTableName == "OrientationPoints")
                {
                    // Get the Azimuth from the feature - this is ugly -- why is this m_identifier a double?
                    int Azimuth = (int)Math.Round((double)theRow.get_Value(theTable.FindField("Azimuth")), 0);
                    // Calculate the stupid form of rotation...
                    int Rotation = CalculateSymbolRotation(Azimuth);
                    // Set the SymbolRotation Field
                    theRow.set_Value(theTable.FindField("SymbolRotation"), double.Parse(Rotation.ToString()));
                }
            }
            #endregion

            // Debugging flag to turn off repositioning of related data when stations are edited:
            bool adjustLocations = false;

            if (adjustLocations == true)
            {
                #region "Adjust Samples/OrientationPoints to Match Stations"
                if (parsedTableName == "Stations")
                {
                    // Cast the obj as a Feature in order to access Geometry information
                    IFeature  theStation  = (IFeature)obj;
                    IGeometry stationGeom = theStation.ShapeCopy;

                    // Find related Samples
                    IRelationshipClass          stationSampleLink = commonFunctions.OpenRelationshipClass(m_EditWorkspace, "StationSampleLink");
                    ESRI.ArcGIS.esriSystem.ISet relatedSamples    = stationSampleLink.GetObjectsRelatedToObject(obj);

                    // Loop through the related Samples and set their Geometry to that of the Station
                    relatedSamples.Reset();
                    IFeature aSample = (IFeature)relatedSamples.Next();
                    while (aSample != null)
                    {
                        aSample.Shape = stationGeom;
                        aSample.Store();
                        aSample = (IFeature)relatedSamples.Next();
                    }

                    // Find related OrientationPoints
                    IRelationshipClass          stationStructureLink = commonFunctions.OpenRelationshipClass(m_EditWorkspace, "StationOrientationPointsLink");
                    ESRI.ArcGIS.esriSystem.ISet relatedStructures    = stationStructureLink.GetObjectsRelatedToObject(obj);

                    // Loop through the related OrientationPoints and set their Geometry to that of the Station
                    relatedStructures.Reset();
                    IFeature aStructure = (IFeature)relatedStructures.Next();
                    while (aStructure != null)
                    {
                        aStructure.Shape = stationGeom;
                        aStructure.Store();
                        aStructure = (IFeature)relatedStructures.Next();
                    }
                }
                #endregion
            }
        }
        void OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
        {
            // Don't do anything if the extension is disabled
            if (IsExtensionEnabled != true)
            {
                return;
            }

            // Bail if this is not a valid NCGMP workspace
            if (m_DatabaseIsValid == false)
            {
                return;
            }

            #region "Groundwork"
            // Grab the FeatureClass name from the Row's Table (as an IDataset).
            IRow     theRow    = obj;
            ITable   theTable  = theRow.Table;
            IDataset theDS     = (IDataset)theTable;
            string   TableName = theDS.Name;

            // Parse the table name in order to strip out unneccessary bits of SDE tables
            ISQLSyntax nameParser = (ISQLSyntax)theDS.Workspace;
            string     parsedDbName, parsedOwnerName, parsedTableName;
            nameParser.ParseTableName(TableName, out parsedDbName, out parsedOwnerName, out parsedTableName);
            #endregion

            #region "Set New ID"
            // Call the routine to get a new ID
            int id = m_SysInfo.GetNextIdValue(parsedTableName);

            // Set the new ID value on the row itself
            theRow.set_Value(theTable.FindField(parsedTableName + "_ID"), m_SysInfo.ProjAbbr + "." + parsedTableName + "." + id);
            #endregion

            #region "Calculate SymbolRotation"
            if (m_DatabaseUsesRepresentation == true)
            {
                if (parsedTableName == "OrientationPoints")
                {
                    // Get the Azimuth from the feature
                    int  Azimuth;
                    bool result = int.TryParse(theRow.get_Value(theTable.FindField("Azimuth")).ToString(), out Azimuth);
                    // Calculate the stupid form of rotation...
                    int Rotation = CalculateSymbolRotation(Azimuth);
                    // Set the SymbolRotation Field
                    theRow.set_Value(theTable.FindField("SymbolRotation"), double.Parse(Rotation.ToString()));
                }
            }
            #endregion

            #region "Set DataSource"
            // Bail if the new object is in fact a Data Source
            if (parsedTableName != "DataSources")
            {
                if (globalVariables.currentDataSource == null)
                {
                    // I can warn the user that they should choose a data source, but I can't keep the feature from being created anyways
                    System.Windows.Forms.MessageBox.Show("You have not selected a valid Data Source for this edit session." + Environment.NewLine + "Your feature was created without a Data Source.", "NCGMP Tools");
                    return;
                }
                else
                {
                    // Set the DataSourceID value
                    if (parsedTableName == "Glossary")
                    {
                        theRow.set_Value(theTable.FindField("DefinitionSourceID"), globalVariables.currentDataSource);
                    }
                    else if (parsedTableName == "DescriptionOfMapUnits")
                    {
                        theRow.set_Value(theTable.FindField("DescriptionSourceID"), globalVariables.currentDataSource);
                    }
                    else if (obj.get_Value(theTable.FindField("DataSourceID")).ToString() == "")
                    {
                        theRow.set_Value(theTable.FindField("DataSourceID"), globalVariables.currentDataSource);
                    }
                }
            }
            #endregion
        }
Пример #7
0
        protected override bool WorkspaceIsValid(IFeatureWorkspace fworkspace)
        {
            bool result = true;

            try
            {
                IWorkspace workspace = fworkspace as IWorkspace;
                ISQLSyntax sqlSyntax = (ISQLSyntax)workspace;

                // ----------------------------------------------
                // Need to get the db name & onwer. This is very
                // important so we can deal with different types
                // of table name qualification when dealing with
                // enterprise and file geodatabases.Names are
                // only fully qualified with enterprise GDBs.
                // ----------------------------------------------
                IWorkspace       wksp            = fworkspace as IWorkspace;
                IEnumDatasetName enumDatasetName = wksp.get_DatasetNames(esriDatasetType.esriDTAny);
                IDatasetName     datasetName     = enumDatasetName.Next();
                if (datasetName != null)
                {
                    datasetName = enumDatasetName.Next();
                    // Parse path name out into db, owner, table.
                    string db    = string.Empty;
                    string owner = string.Empty;
                    string tbl   = string.Empty;
                    sqlSyntax.ParseTableName(datasetName.Name, out db, out owner, out tbl);
                    _ownerName = owner;
                    _dbName    = db;
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Database owner...", _ownerName);
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Database name...", _dbName);
                }
                else
                {
                    // Not a valid workspace if nothing found in it
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Invalid workspace selected.");
                    return(false);
                }

                // ----------------------------------------------
                // Workspace is valid and is a feature workspace
                // ----------------------------------------------
                if (fworkspace == null || workspace == null)
                {
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Invalid workspace selected.");
                    return(false);
                }
                else
                {
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Reading Workspace...",
                                           workspace.PathName + "," + workspace.Type.ToString());
                }

                // -----------------------------------
                // Are we dealing with a geodatabase
                // ie not shapefiles etc
                // -----------------------------------
                if (workspace.Type != esriWorkspaceType.esriRemoteDatabaseWorkspace &&
                    workspace.Type != esriWorkspaceType.esriLocalDatabaseWorkspace)
                {
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Telecom workspace is not a geodatabase.");
                    return(false);
                }

                // --------------------------------
                // Get the workspace properties
                // --------------------------------
                IDatabaseConnectionInfo2 dbInfo = workspace as IDatabaseConnectionInfo2;

                IPropertySet wkPropSet = workspace.ConnectionProperties;
                object       names;
                object       values;
                wkPropSet.GetAllProperties(out names, out values);

                if (dbInfo != null)
                {
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Database Connection Info...");
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Connected DB: ", dbInfo.ConnectedDatabase);
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Connected User: "******"INFO", "DB Type: ", dbInfo.ConnectionDBMS.ToString());
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Connection Server: ", dbInfo.ConnectionServer);
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "GDB Server Class: ", dbInfo.GeodatabaseServerClass.ToString());
                }

                // ---------------------------------------
                // Does it have a dynamic values dataset?
                // ---------------------------------------
                IWorkspace2 wksp2 = fworkspace as IWorkspace2;
                if (!InWorkspace(wksp2, esriDatasetType.esriDTTable, m_defaultsTableName))
                {
                    return(false);
                }

                // -------------------------------------------------
                // Do checks for other FCs and tables in app.config
                // -------------------------------------------------
                if (!InWorkspace(wksp2, esriDatasetType.esriDTFeatureClass, ConfigUtil.FiberCableFtClassName))
                {
                    return(false);
                }
                if (!InWorkspace(wksp2, esriDatasetType.esriDTTable, ConfigUtil.FiberSpliceTableName))
                {
                    return(false);
                }
                if (!InWorkspace(wksp2, esriDatasetType.esriDTTable, ConfigUtil.FiberTableName))
                {
                    return(false);
                }
                if (!InWorkspace(wksp2, esriDatasetType.esriDTTable, ConfigUtil.BufferTubeClassName))
                {
                    return(false);
                }
                // ----------
                // Devices
                // ----------
                string[] devices = ConfigUtil.DeviceFeatureClassNames;
                foreach (string name in devices)
                {
                    if (!InWorkspace(wksp2, esriDatasetType.esriDTFeatureClass, name))
                    {
                        return(false);
                    }
                }

                // --------------------------------------------
                // Do a check for # Fibers and Strands domains
                // If these exist, DB will need upgrading first
                // --------------------------------------------
                IFeatureClass cableFc = FindFeatureClass(ConfigUtil.FiberCableFtClassName);
                if (cableFc == null)
                {
                    return(false);
                }
                int buffersIdx = cableFc.FindField(ConfigUtil.NumberOfBuffersFieldName);
                if (buffersIdx == -1)
                {
                    return(false);
                }
                IField field = cableFc.Fields.Field[buffersIdx];
                if (field.Domain != null)
                {
                    //MessageBox.Show("An invalid schema was found. Please read the " +
                    //    "documentation on how to upgrade old databases to work with the " +
                    //    "newer tools. Also view the log for more details. The log is " +
                    //    "accessible from telecom toolbar.", "Invalid Telecom Schema");

                    _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "DB Telecom Schema Version OK?", "False. Invalid Domain found on FiberCable.");


                    // Assume no until they say yes
                    DialogResult dialogResult = DialogResult.No;

                    dialogResult = MessageBox.Show("Do you wish to try to upgrade this database? \n\nPLEASE ENSURE YOU HAVE EXCLUSIVE ACCESS TO THIS DATABASE AND THAT NO SERVICES ARE RUNNING AGAINST IT \n\nPLEASE ALWAYS ENSURE YOU HAVE A BACKUP BEFORE CONSIDERING THIS!", "Upgrade Workspace", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (DialogResult.No == dialogResult)
                    {
                        _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Database upgrade NO.", "");
                        return(false);
                    }
                    else if (DialogResult.Yes == dialogResult)
                    {
                        _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Database Upgrade YES.", "");
                        result = RemoveFiberCableConfigDomains(workspace);
                    }
                }
                else
                {
                    _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "DB Telecom Schema Version OK?", "True");
                }
            }
            catch (Exception e)
            {
                result = false;
                _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "WorkspaceIsValid", e.Message);
            }

            return(result);
        }