Exemple #1
0
        private void ReadLayer(ILayer layer, ILayer parentLayer)
        {
            string connectionstringdata = string.Empty;
            string parentlayername      = "None";

            if (parentLayer != null)
            {
                parentlayername = parentLayer.Name;
            }

            if (layer is GroupLayer)
            {
                ICompositeLayer compositeLayer = (ICompositeLayer)layer;

                for (int i = 0; i < compositeLayer.Count; i++)
                {
                    ILayer sublayer = compositeLayer.get_Layer(i);
                    ReadLayer(sublayer, layer);
                }
            }
            else if (layer is IGeoFeatureLayer)
            {
                IGeoFeatureLayer geofeaturelayer = (IGeoFeatureLayer)layer;
                connectionstringdata = GetConnectionString(geofeaturelayer);
            }
            else if (layer is ICoverageAnnotationLayer)
            {
                //ignore for now:
                Trace.WriteLine("Converage Anno:  " + layer.Name);
            }
            else if (layer is IMapServerLayer)
            {
                IMapServerLayer      mapserverLayer = (IMapServerLayer)layer;
                IAGSServerObjectName serverObject;

                string url     = string.Empty;
                string mapname = string.Empty;

                mapserverLayer.GetConnectionInfo(out serverObject, out url, out mapname);

                string connstring = "url={0};map={1};name={2};type={3}";

                connectionstringdata = string.Format(connstring, serverObject.URL, mapname, serverObject.Name, serverObject.Type);
            }
            else if (layer is RasterLayer)
            {
                Trace.WriteLine("Raster Layer:  " + layer.Name);
                connectionstringdata = GetConnectionString(layer);
            }
            else
            {
                Console.WriteLine("Unknown Layer Type: " + layer.Name);
            }

            FileInfo fi = new FileInfo(this.MXDFilePath);

            OnReadLayer(layer.Name, parentlayername, layer.Valid, connectionstringdata, Path.GetFileName(this.MXDFilePath), this.MXDFilePath, fi.LastWriteTime);

            Trace.WriteLine(string.Format("Layer:{0},Valid={1},ConnectionProps={2},ParentLayer={3}", layer.Name, layer.Valid.ToString(), connectionstringdata, parentlayername));
        }
Exemple #2
0
        protected override void OnClick()
        {
            IMxDocument pmxdoc    = (IMxDocument)ArcMap.Application.Document;
            IMap        pmap      = pmxdoc.FocusMap;
            IGxDialog   pGxDialog = new GxDialog();

            pGxDialog.Title = "Browse Data";
            //pGxDialog.set_StartingLocation("C:\\Temp");
            pGxDialog.set_StartingLocation("GIS Servers");
            IEnumGxObject pEnumGx;

            if (!pGxDialog.DoModalOpen(0, out pEnumGx))
            {
                return;  // Exit if user press Cancel
            }
            IGxObject                pgxobject               = pEnumGx.Next();
            IGxAGSObject             gxAGSObject             = pgxobject as IGxAGSObject;
            IAGSServerObjectName     agsServerObjectName     = gxAGSObject.AGSServerObjectName;
            IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName;
            IPropertySet             propertySet             = agsServerConnectionName.ConnectionProperties;
            //create a new ArcGIS Server connection factory
            IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2) new AGSServerConnectionFactory();
            IAGSServerConnection         agsServerConnection         = agsServerConnectionFactory2.Open(propertySet, 0);
            //get an enum of all server object names from the server (GIS services, i.e.)
            IAGSEnumServerObjectName soNames        = agsServerConnection.ServerObjectNames;
            IAGSServerObjectName3    soName         = (IAGSServerObjectName3)soNames.Next();
            ILayerFactory            msLayerFactory = new MapServerLayerFactory();
            IEnumLayer      enumLyrs       = msLayerFactory.Create(soName);
            IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next();

            pmap.AddLayer((ILayer)mapServerLayer);

            ArcMap.Application.CurrentTool = null;
        }
Exemple #3
0
 private void cmbService_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (mpSrvDic.ContainsKey(cmbService.Text))
     {
         IMapServerLayer mpSvrLyr = mpSrvDic[cmbService.Text];
         ESRI.ArcGIS.GISClient.IAGSServerObjectName svrObjName;
         string docLocation;
         mpSvrLyr.GetConnectionInfo(out svrObjName, out docLocation, out mpName);
         //MessageBox.Show("MapName = " + mpName);
         mpSvr = mapserviceutility.getMapServer(svrObjName);
         cmbLayer.Items.Clear();
         mpLayerDic = mapserviceutility.getLayerIds(mpSvr, mpName, true);
         foreach (string s in mpLayerDic.Keys)
         {
             cmbLayer.Items.Add(s);
         }
     }
 }
Exemple #4
0
        private static IMapServerLayer GetArcGisServerGroupLayer(IAGSServerObjectName3 soName)
        {
            IMapServerLayer outLayer = null;
            var             factory  = new MapServerLayerFactory() as ILayerFactory;

            try
            {
                //create an enum of layers using the name object (will contain only a single layer)
                outLayer = factory.Create(soName).Next() as IMapServerLayer;
            }
            catch
            {
                throw;
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(factory);
            }
            return(outLayer);
        }
Exemple #5
0
        internal static ConnectionStringList GetConnectionString(ILayer layer, string filepath)
        {
            ConnectionStringList connectionStrings = new ConnectionStringList();

            Trace.WriteLine("ConnectionStringList LayerName: {0})".FormatString(layer.Name));

            if (layer is IFeatureLayer)
            {
                IFeatureLayer featureLayer = layer as IFeatureLayer;

                IDataset dataset = featureLayer.FeatureClass as IDataset;

                if (dataset != null)
                {
                    object propertyNames;
                    object propertyValues;

                    dataset.Workspace.ConnectionProperties.GetAllProperties(out propertyNames, out propertyValues);

                    connectionStrings.Add(
                        string.Format(LayerConnectionString, layer.Name, MakeConnectionString(propertyNames, propertyValues), filepath));
                }
                else
                {
                    connectionStrings.Add(string.Format(LayerConnectionString, layer.Name, "No Dataset Information", filepath));
                }
            }
            else if (layer is ImageServerLayer)
            {
                IImageServerLayer  imageserverlayer  = layer as IImageServerLayer;
                IImageServerLayer2 imageserverlayer2 = layer as IImageServerLayer2;
                if (imageserverlayer != null)
                {
                    IAGSServerObject2 serverobject = (imageserverlayer.DataSource) as IAGSServerObject2;
                    if (serverobject != null)
                    {
                        IAGSServerObjectName serverobjectname = serverobject.FullName as IAGSServerObjectName;
                        if (serverobjectname != null)
                        {
                            //name, description, url
                            string s           = "{0},{1},{2}";
                            string servicename = serverobjectname.Name;
                            string serviceurl  = serverobjectname.URL;
                            string servicetype = serverobjectname.Type;

                            connectionStrings.Add(s.FormatString(
                                                      servicename,
                                                      servicetype,
                                                      serviceurl));
                        }
                    }
                    Trace.WriteLine(imageserverlayer2.ServiceProperties);
                }
            }
            else if (layer is MapServerLayer)
            {
                IMapServerLayer mapServerLayer = layer as IMapServerLayer;

                if (mapServerLayer != null)
                {
                    try
                    {
                        IAGSServerObjectName agsson;
                        string docLocation = string.Empty;
                        string mapname     = string.Empty;

                        mapServerLayer.GetConnectionInfo(out agsson, out docLocation, out mapname);
                        string s = "{0},{1},{2}";

                        connectionStrings.Add(s.FormatString(agsson.Name, agsson.Type, agsson.URL));
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.StackTrace);
                        throw;
                    }
                }
            }
            else if (layer is IGroupLayer)
            {
                ICompositeLayer compositeLayer = layer as ICompositeLayer;

                for (int i = 0; i < compositeLayer.Count; i++)
                {
                    ILayer subLayer = compositeLayer.Layer[i];

                    connectionStrings.AddRange(GetConnectionString(subLayer, filepath));
                }
            }
            else
            {
            }

            return(connectionStrings);
        }
Exemple #6
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);
        }