private IWorkspace GetGeodatabase()
        {
            IPropertySet2 connectionProperties = ConnectionProperties.GetConnectionProperties();
            IWorkspace    wks = WorkspaceHandler.GetSdeWorkspace(connectionProperties);

            return(wks);
        }
        //search outside datasets
        protected IFeatureClass GetFeatureClass(string featureClassName)
        {
            IWorkspaceFactory2 factory = null;

            if (_serverContext != null)
            {
                factory = (IWorkspaceFactory2)_serverContext.CreateObject("esriDataSourcesGDB.SDEWorkspaceFactory");
            }

            IWorkspace        ipWks            = null;
            IFeatureClass     ipFeatClass      = null;
            IFeatureClass     ipFeatDS         = null;
            IFeatureClass     ipEnumSubDataset = null;
            IEnumDataset      ipEnumDataset    = null;
            IFeatureWorkspace fws = null;

            try
            {
                IPropertySet2 propSet = null;
                if (_serverContext != null)
                {
                    propSet = (IPropertySet2)_serverContext.CreateObject("esriSystem.PropertySet");
                }

                propSet.SetProperty("SERVER", _sdeServerInfo.server);
                propSet.SetProperty("INSTANCE", _sdeServerInfo.instance);
                propSet.SetProperty("DATABASE", _sdeServerInfo.database);
                propSet.SetProperty("USER", _sdeServerInfo.user);
                propSet.SetProperty("PASSWORD", _sdeServerInfo.password);
                propSet.SetProperty("VERSION", _sdeServerInfo.version);

                ipWks = factory.Open(propSet, 0);
                fws   = (IFeatureWorkspace)ipWks;

                //try and open it
                if (ipWks != null)
                {
                    ipEnumDataset = ipWks.get_Datasets(esriDatasetType.esriDTFeatureClass);
                    ipEnumDataset.Reset();
                    ipFeatDS = ipEnumDataset.Next() as IFeatureClass;
                    while (ipFeatDS != null)
                    {
                        ipEnumSubDataset = ipFeatDS;
                        ipFeatClass      = ipEnumSubDataset;
                        while (ipFeatClass != null)
                        {
                            if (ipFeatClass.AliasName.ToUpper().Contains(featureClassName.ToUpper()))
                            {
                                return(ipFeatClass);
                            }
                            ipFeatClass = ipEnumDataset.Next() as IFeatureClass;
                        }
                        ipFeatDS         = ipEnumDataset.Next() as IFeatureClass;
                        ipEnumSubDataset = null;
                    }

                    ipEnumDataset = null;
                }
            }
            catch (System.Runtime.InteropServices.COMException edd)
            {
                //exception is coming from Arcobjects...
                ipFeatClass = null;
                throw edd;
            }
            finally
            {
                Util.ReleaseCOMObject(fws);
                Util.ReleaseCOMObject(ipEnumSubDataset);
                Util.ReleaseCOMObject(ipEnumDataset);
                Util.ReleaseCOMObject(factory);
            }
            return(GetFeatureClassInsideDataset(featureClassName));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds ArcGIS layer to map
        /// </summary>
        /// <param name="ipMxDoc"></param>
        /// <param name="strServer"></param>
        /// <param name="strLayerName"></param>
        /// <param name="strSecretName"></param>
        /// <returns></returns>
        private bool addLayerAGS(IMxDocument ipMxDoc, string strServer, string strLayerName, string strSecretName)
        {
            IPropertySet2 pProps = null;
            string        pServerUrl;
            string        strServerObj;

            pServerUrl = GetAGSServiceUrl(strServer);

            // connect to the GIS server
            IAGSServerConnectionFactory pAGSServerConnectionFactory = new AGSServerConnectionFactory();

            pProps = (IPropertySet2) new PropertySet();
            pProps.SetProperty("URL", pServerUrl);

            IAGSServerConnection pAGSConnection = pAGSServerConnectionFactory.Open(pProps, 0);

            //get server objectname from url
            strServerObj = GetServerObjectName(strServer);

            // enumerate over server objects
            IAGSEnumServerObjectName pAGSSObjs = pAGSConnection.ServerObjectNames;
            IAGSServerObjectName     pAGSSObj  = pAGSSObjs.Next();

            while (pAGSSObj != null)
            {
                if (pAGSSObj.Type == "MapServer" && pAGSSObj.Name == strServerObj)
                {
                    break;
                }
                pAGSSObj = pAGSSObjs.Next();
            }


            IName            pName     = (IName)pAGSSObj;
            IAGSServerObject pAGSO     = (IAGSServerObject)pName.Open();
            IMapServer       mapServer = (IMapServer)pAGSO;


            IPropertySet prop = new PropertySetClass();

            prop.SetProperty("URL", pServerUrl);
            prop.SetProperty("Name", pAGSSObj.Name);

            //Create new layer
            IMapServerLayer pMSLayer = (IMapServerLayer) new MapServerLayer();

            pMSLayer.ServerConnect(pAGSSObj, mapServer.DefaultMapName);

            if (!isMapServerAdded(strServer))
            {
                setAGSLayerVisiblity((MapServerLayer)pMSLayer, strSecretName);
                IMap ipMap = ipMxDoc.FocusMap;
                ipMap.AddLayer((ILayer)pMSLayer);
                logger.writeLog(StringResources.AddAGSLayer + strSecretName);
            }
            else
            {
                // set visibility
                setAGSLayerVisiblity((MapServerLayer)pMSLayer, strSecretName);
            }

            //add to the service list
            string strItem = EncodeServiceList(strServer, strLayerName, strSecretName);

            // m_pLogger.Msg "adding to service list : " & strItem
            colServiceList.Add(strItem);

            //set flag
            logger.writeLog("strServer = " + strServer + " strServer & strLayerName = " + strServer + strLayerName);
            return(true);
        }