/// <summary> /// Used to get the type of the Database /// </summary> /// <param name="ipWorkspace">Input database</param> /// <returns>The type of the input database</returns> private DatabaseType GetDatabaseType(IWorkspace ipWorkspace) { DatabaseType eDBType = DatabaseType.FGDB; if (null != ipWorkspace) { if (ipWorkspace.Type == esriWorkspaceType.esriFileSystemWorkspace) { eDBType = DatabaseType.SHAPEFILE; } else if (ipWorkspace.Type == esriWorkspaceType.esriLocalDatabaseWorkspace) { IWorkspaceFactory ipWSFact = ((ipWorkspace as IDataset).FullName as IWorkspaceName).WorkspaceFactory; UID temp = ipWSFact.GetClassID(); string strWorkspaceCLSID = Convert.ToString((ipWSFact.GetClassID().Value)); if (strWorkspaceCLSID.ToUpper() == "{DD48C96A-D92A-11D1-AA81-00C04FA33A15}".ToUpper()) { eDBType = DatabaseType.MDB; } else if (strWorkspaceCLSID.ToUpper() == "{71FE75F0-EA0C-4406-873E-B7D53748AE7E}".ToUpper()) { eDBType = DatabaseType.FGDB; } else if (strWorkspaceCLSID.ToUpper() == "{A06ADB96-D95C-11D1-AA81-00C04FA33A15}".ToUpper()) { eDBType = DatabaseType.SHAPEFILE; } } else if (ipWorkspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { IDatabaseConnectionInfo2 ipDBInfo = ipWorkspace as IDatabaseConnectionInfo2; esriConnectionDBMS eConnDBMS = ipDBInfo.ConnectionDBMS; if (eConnDBMS == esriConnectionDBMS.esriDBMS_Oracle) { eDBType = DatabaseType.ORACLE; } else if (eConnDBMS == esriConnectionDBMS.esriDBMS_PostgreSQL) { eDBType = DatabaseType.POSTGRESQL; } else if (eConnDBMS == esriConnectionDBMS.esriDBMS_SQLServer) { eDBType = DatabaseType.SQLSERVER; } } } return(eDBType); }
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); }
private void AddQALayerToActiveView(IMap map, IFeatureClass SourceLineFeatureClass, IFeatureClass SourcePolygonFeatureClass, string layerPathFile, double metersPerUnit, bool bIsBefore1022, bool bFabricIsInGCS) { if (map == null || layerPathFile == null || !layerPathFile.EndsWith(".lyr")) { return; } IWorkspace pWS = SourceLineFeatureClass.FeatureDataset.Workspace; bool bIsPostGres = false; if (pWS.Type != esriWorkspaceType.esriLocalDatabaseWorkspace) { IDatabaseConnectionInfo2 connectionInfo2 = (IDatabaseConnectionInfo2)(pWS); bIsPostGres = (connectionInfo2.ConnectionDBMS == esriConnectionDBMS.esriDBMS_PostgreSQL); } // Create a new GxLayer IGxLayer gxLayer = new GxLayerClass(); IGxFile gxFile = (IGxFile)gxLayer; // Set the path for where the layerfile is located on disk gxFile.Path = layerPathFile; // Test if we have a valid layer and add it to the map if (!(gxLayer.Layer == null)) { if (!(gxLayer.Layer is ICompositeLayer)) { return; } ICompositeLayer pCompLyr = (ICompositeLayer)gxLayer.Layer; for (int i = 0; i < pCompLyr.Count; i++) { ILayer pLyr = pCompLyr.get_Layer(i); // if (pLyr is IFeatureLayer) { IFeatureLayer pFlyr = (IFeatureLayer)pLyr; //now update the definition query IFeatureLayerDefinition pFeatLyrDef = (IFeatureLayerDefinition)pFlyr; string sLyrName = pFlyr.Name; bool bExc = false; if (sLyrName.Contains("Minus")) { pFlyr.FeatureClass = SourceLineFeatureClass; bExc = false; SetLabelExpressionOnFeatureLayer(pFlyr, out bExc); if (bExc || bFabricIsInGCS) { int jj = pFlyr.FeatureClass.FindField("ComputedMinusObserved"); if (jj > -1) { string sVal = (0.1 / metersPerUnit).ToString("0.00"); string sCminusO = pFlyr.FeatureClass.Fields.get_Field(jj).Name; pFeatLyrDef.DefinitionExpression = "(" + sCminusO + " > " + sVal + " OR " + sCminusO + " < -" + sVal + ") AND (" + sCminusO + " IS NOT NULL)"; if (bIsPostGres) { pFeatLyrDef.DefinitionExpression = "(((st_length(shape) - distance) > " + sVal + " OR (st_length(shape) - distance) < -" + sVal + " OR (distance - st_length(shape)) > " + sVal + " OR (distance - st_length(shape)) < -" + sVal + ") AND (radius IS NULL AND (densifytype IS NULL OR densifytype <> 3)) AND category <> 4) OR ( ( ((st_length(shape) - arclength) > " + sVal + " OR (st_length(shape) - arclength) < -" + sVal + ") OR (arclength - st_length(shape)) > " + sVal + " OR (arclength - st_length(shape)) < -" + sVal + ") AND ( NOT arclength IS NULL ) )"; //this is query for ST_Geometry as well as PG_Geometry } } continue; } string s = pFeatLyrDef.DefinitionExpression; int iField = SourceLineFeatureClass.FindField("ArcLength"); if (iField > -1) { string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name; pFeatLyrDef.DefinitionExpression = s.Replace("\"ArcLength\"", s2); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("ArcLength", s2); } s = pFeatLyrDef.DefinitionExpression; iField = SourceLineFeatureClass.FindField("Category"); if (iField > -1) { string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name; pFeatLyrDef.DefinitionExpression = s.Replace("\"Category\"", s2); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("Category", s2); } s = pFeatLyrDef.DefinitionExpression; iField = SourceLineFeatureClass.FindField("Radius"); if (iField > -1) { string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name; pFeatLyrDef.DefinitionExpression = s.Replace("\"Radius\"", s2); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("Radius", s2); } s = pFeatLyrDef.DefinitionExpression; iField = SourceLineFeatureClass.FindField("Distance"); if (iField > -1) { string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name; pFeatLyrDef.DefinitionExpression = s.Replace("\"Distance\"", s2); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("Distance", s2); } s = pFeatLyrDef.DefinitionExpression; iField = SourceLineFeatureClass.FindField("DensifyType"); if (iField > -1) { string s2 = SourceLineFeatureClass.Fields.get_Field(iField).Name; pFeatLyrDef.DefinitionExpression = s.Replace("\"DensifyType\"", s2); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("DensifyType", s2); } s = pFeatLyrDef.DefinitionExpression; pFeatLyrDef.DefinitionExpression = s.Replace("\"Shape_Length\"", SourceLineFeatureClass.LengthField.Name); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("Shape_Length", SourceLineFeatureClass.LengthField.Name); } else if (sLyrName.Contains("Parcel")) { //In 10.1 start editing crashes if the definition query in these layers that use POWER function is present. //Can test if the release is 10.1 and knock out the def query, or else exclude the layers. string s = pFeatLyrDef.DefinitionExpression; int iField = SourcePolygonFeatureClass.FindField("MiscloseDistance"); string s2 = SourcePolygonFeatureClass.Fields.get_Field(iField).Name; pFeatLyrDef.DefinitionExpression = s.Replace("\"MiscloseDistance\"", s2); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("MiscloseDistance", s2); s = pFeatLyrDef.DefinitionExpression; iField = SourcePolygonFeatureClass.FindField("ShapeStdErrorE"); s2 = SourcePolygonFeatureClass.Fields.get_Field(iField).Name; pFeatLyrDef.DefinitionExpression = s.Replace("\"ShapeStdErrorE\"", s2); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("ShapeStdErrorE", s2); s = pFeatLyrDef.DefinitionExpression; iField = SourcePolygonFeatureClass.FindField("ShapeStdErrorN"); s2 = SourcePolygonFeatureClass.Fields.get_Field(iField).Name; pFeatLyrDef.DefinitionExpression = s.Replace("\"ShapeStdErrorN\"", s2); pFeatLyrDef.DefinitionExpression = pFeatLyrDef.DefinitionExpression.Replace("ShapeStdErrorN", s2); pFlyr.FeatureClass = SourcePolygonFeatureClass; SetLabelExpressionOnFeatureLayer(pFlyr, out bExc); if (s.ToLower().Contains("power") && bIsBefore1022) {//remove the def query CR278039 pFeatLyrDef.DefinitionExpression = ""; continue; } } } } gxLayer.Layer.Name = "QA Symbology"; IMxDocument pMXDoc = ArcMap.Document; IOperationStack pOpSt = pMXDoc.OperationStack; IAddLayersOperation pAddLyrOp = new AddLayersOperationClass(); pAddLyrOp.SetDestinationInfo(0, map, null); pAddLyrOp.Name = "Add Fabric QA Layer"; pAddLyrOp.AddLayer(gxLayer.Layer); IOperation pOp = (IOperation)pAddLyrOp; pOpSt.Do(pOp); } }