public static IEnumerable <IMapLayerInfo3> AsEnumerable(this IMapLayerInfos layerInfos)
 {
     for (int i = 0; i < layerInfos.Count; i++)
     {
         yield return(layerInfos.get_Element(i) as IMapLayerInfo3);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Locates the map layer that matches the supplied name.
        /// </summary>
        /// <param name="serverObject"></param>
        /// <param name="layerName"></param>
        /// <returns></returns>
        public static IMapLayerInfo FindLayer(this ESRI.ArcGIS.Server.IServerObject serverObject, string layerName)
        {
            // Get the list of layers
            var mapServer = serverObject as IMapServer3;

            if (mapServer == null)
            {
                return(null);
            }

            IMapLayerInfos mapLayerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos;

            for (int i = 0; i < mapLayerInfos.Count; i++)
            {
                IMapLayerInfo layer = mapLayerInfos.get_Element(i);

                if (layer == null || !layer.IsFeatureLayer || !string.Equals(layer.Name, layerName))
                {
                    continue;
                }

                return(layer);
            }

            return(null);
        }
        private CustomLayerInfos GetLayerInfos()
        {
            IMapServer3 mapServer = serverObjectHelper.ServerObject as IMapServer3;

            if (mapServer == null)
            {
                throw new Exception("Unable to access the map server.");
            }

            IMapServerInfo msInfo     = mapServer.GetServerInfo(mapServer.DefaultMapName);
            IMapLayerInfos layerInfos = msInfo.MapLayerInfos;
            int            c          = layerInfos.Count;

            CustomLayerInfos customLayerInfos = new CustomLayerInfos(Constants.SOENamespaceURI);

            for (int i = 0; i < c; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);

                CustomLayerInfo customLayerInfo = new CustomLayerInfo();
                customLayerInfo.Name   = layerInfo.Name;
                customLayerInfo.ID     = layerInfo.ID;
                customLayerInfo.Extent = layerInfo.Extent;

                customLayerInfos.Add(customLayerInfo);
            }

            return(customLayerInfos);
        }
Beispiel #4
0
        /// <summary>
        /// Returns an array of layer IDs.  This list of layer IDs correspond to Feature Layers.
        /// </summary>
        /// <returns>An array of layer ID <see cref="int"/>s.</returns>
        private int[] GetIdsOfLayersThatHaveMetadata()
        {
            var    mapServer      = (IMapServer3)_serverObjectHelper.ServerObject;
            string defaultMapName = mapServer.DefaultMapName;

            IMapServerInfo3 serverInfo    = mapServer.GetServerInfo(defaultMapName) as IMapServerInfo3;
            IMapLayerInfos  mapLayerInfos = serverInfo.MapLayerInfos;

            IMapLayerInfo3 layerInfo = null;
            var            output    = new List <int>(mapLayerInfos.Count);

            for (int i = 0; i < mapLayerInfos.Count; i++)
            {
                layerInfo = mapLayerInfos.get_Element(i) as IMapLayerInfo3;
                if (layerInfo.IsFeatureLayer)
                {
                    output.Add(i);
                }
            }

            // Untested.
            ////var output = from layerInfo in mapLayerInfos.AsEnumerable()
            ////             where layerInfo.IsFeatureLayer
            ////             select layerInfo.ID;

            return(output.ToArray());
        }
Beispiel #5
0
        /// <summary>
        /// 得到地图服务的某个图层的ID.
        /// </summary>
        /// <param name="pMapServer">地图服务</param>
        /// <param name="pLayer">图层</param>
        /// <param name="dataFrameName">一般用缺省状态""</param>
        /// <returns>图层ID,不存在该图层则返回-1.</returns>
        public static int GetServerLayerID(IMapServer pMapServer, ILayer pLayer, string dataFrameName)
        {
            //缺省状态下dataframe。
            if (dataFrameName == "")
            {
                dataFrameName = pMapServer.DefaultMapName;
            }

            int            layerID        = -1;
            IMapServerInfo pMapServerInfo = new MapServerInfoClass();

            pMapServerInfo = pMapServer.GetServerInfo(dataFrameName);
            IMapLayerInfos layerInfos = pMapServerInfo.MapLayerInfos;
            IMapLayerInfo  layerInfo  = new MapLayerInfoClass();

            for (int j = 0; j < layerInfos.Count; j++)
            {
                layerInfo = layerInfos.get_Element(j);
                if (layerInfo.Name == pLayer.Name)
                {
                    layerID = j;
                    break;
                }
            }
            return(layerID);
        }
Beispiel #6
0
        /// <summary>
        /// From service fills list of layer with M
        /// </summary>
        private void GetRouteLayerInfos()
        {
            IMapServer3    serverObject  = this.GetMapServer();
            IMapLayerInfos mapLayerInfos = serverObject.GetServerInfo(serverObject.DefaultMapName).MapLayerInfos;

            this.routeLayerInfos = new List <RouteLayerInfo>();
            for (int i = 0; i < mapLayerInfos.Count; i++)
            {
                IMapLayerInfo mapLayerInfo = mapLayerInfos.get_Element(i);
                if (mapLayerInfo.IsFeatureLayer)
                {
                    IFields fields = mapLayerInfo.Fields;
                    for (int j = 0; j < fields.FieldCount; j++)
                    {
                        IField field = fields.get_Field(j);
                        if (field.Type == esriFieldType.esriFieldTypeGeometry)
                        {
                            IGeometryDef geometryDef = field.GeometryDef;
                            if (geometryDef.HasM)
                            {
                                this.routeLayerInfos.Add(new RouteLayerInfo(mapLayerInfo));
                            }

                            break;
                        }
                    }
                }
            }
        }
 public void Shutdown() 
 {
     serverLog.LogMessage(ServerLogger.msgType.infoStandard, this.soeName + ".init()", 200, "Shutting down " + this.soeName + " SOE.");
     this.soHelper = null;
     this.serverLog = null;
     this.mapServerDataAccess = null;
     this.layerInfos = null;
 }
Beispiel #8
0
 public void Shutdown()
 {
     serverLog.LogMessage(ServerLogger.msgType.infoStandard, this.soeName + ".init()", 200, "Shutting down " + this.soeName + " SOE.");
     this.soHelper            = null;
     this.serverLog           = null;
     this.mapServerDataAccess = null;
     this.layerInfos          = null;
 }
Beispiel #9
0
 /// <summary>
 ///     Creates an <see cref="IEnumerable{T}" /> from a <see cref="IMapLayerInfos" />
 /// </summary>
 /// <param name="source">Map layer informations</param>
 /// <returns><see cref="IEnumerable{T}" /> of <see cref="IMapLayerInfo" /></returns>
 public static IEnumerable <IMapLayerInfo> AsEnumerable(this IMapLayerInfos source)
 {
     if (source != null)
     {
         for (int i = 0; i < source.Count; i++)
         {
             yield return(source.Element[i]);
         }
     }
 }
        public void Init(IServerObjectHelper pSOH)
        {
            this.soHelper = pSOH;
            this.serverLog = new ServerLogger();
            this.mapServerDataAccess = (IMapServerDataAccess)this.soHelper.ServerObject;
            IMapServer3 ms = (IMapServer3)this.mapServerDataAccess;
            IMapServerInfo mapServerInfo = ms.GetServerInfo(ms.DefaultMapName);
            this.layerInfos = mapServerInfo.MapLayerInfos;

            serverLog.LogMessage(ServerLogger.msgType.infoStandard, this.soeName + ".init()", 200, "Initialized " + this.soeName + " SOE.");
        }
Beispiel #11
0
        public void Init(IServerObjectHelper pSOH)
        {
            this.soHelper            = pSOH;
            this.serverLog           = new ServerLogger();
            this.mapServerDataAccess = (IMapServerDataAccess)this.soHelper.ServerObject;
            IMapServer     ms            = (IMapServer)this.mapServerDataAccess;
            IMapServerInfo mapServerInfo = ms.GetServerInfo(ms.DefaultMapName);

            this.layerInfos = mapServerInfo.MapLayerInfos;

            serverLog.LogMessage(ServerLogger.msgType.infoStandard, this.soeName + ".init()", 200, "Initialized " + this.soeName + " SOE.");
        }
        private bool loadGeometricNetworkFromServer(IServerObjectHelper serverObjectHelper, ServerLogger logger)
        {
            bool result = false;

            if (null != serverObjectHelper)
            {
                try
                {
                    IMapServer3          mapServer  = (IMapServer3)serverObjectHelper.ServerObject;
                    IMapServerDataAccess da         = (IMapServerDataAccess)mapServer;
                    IMapLayerInfos       layerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos;
                    IFeatureDataset      ftrDataset = null;
                    for (int i = 0; i < layerInfos.Count; i++)
                    {
                        IMapLayerInfo lyrInfo = layerInfos.get_Element(i);
                        if (lyrInfo.IsFeatureLayer)
                        {
                            IFeatureClass ftrClass = (IFeatureClass)da.GetDataSource(mapServer.DefaultMapName, lyrInfo.ID);
                            if (null == ftrDataset && ftrClass.FeatureDataset.Name == this.networkName)
                            {
                                ftrDataset = ftrClass.FeatureDataset;
                            }
                            if (esriFeatureType.esriFTSimpleEdge == ftrClass.FeatureType)
                            {
                                this.addEdgeFeatureClass(ftrClass);
                            }
                            else if (esriFeatureType.esriFTSimpleJunction == ftrClass.FeatureType)
                            {
                                this.addJunctionFeatureClass(ftrClass);
                            }
                        }
                    }
                    if (this.edgeCount > 0 && this.junctionCount > 0 && null != ftrDataset)
                    {
                        INetworkCollection networkCollection = ftrDataset as INetworkCollection;
                        if (networkCollection != null && networkCollection.GeometricNetworkCount > 0)
                        {
                            this.geometricNetwork = networkCollection.GeometricNetwork[0];
                            result = true;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (null != logger)
                    {
                        logger.LogMessage(ServerLogger.msgType.error, typeof(NetworkHelper).Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name, GLC.AO.AOUtilities.ErrorCode, e.Message);
                    }
                }
            }
            return(result);
        }
        public void Init(IServerObjectHelper pSOH)
        {
            serverObjectHelper = pSOH;

            mapServerDataAccess = (IMapServerDataAccess)pSOH.ServerObject;
            IMapServer3 ms = (IMapServer3)pSOH.ServerObject;

            this.mapServerInfo = ms.GetServerInfo(ms.DefaultMapName);
            this.layerInfos    = mapServerInfo.MapLayerInfos;

            if (layerId < 0)
            {
                layerId = 0;
            }
        }
        /**
         * This method returns the layer id of the layer matching the specified name
         */
        public int GetLayerIdByName(IMapServer mapService, string name)
        {
            IMapServerInfo msInfo     = mapService.GetServerInfo(mapService.DefaultMapName);
            IMapLayerInfos layerInfos = msInfo.MapLayerInfos;

            for (int i = 0; i < layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.Element[i];
                if (layerInfo.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
                {
                    return(layerInfo.ID);
                }
            }

            return(-1);
        }
        /**
         * This method returns the Utility Network Layer information object.
         */
        public IMapLayerInfo GetUNLayerInfo(IMapServer mapService)
        {
            IMapServerInfo mapServerInfo = mapService.GetServerInfo(mapService.DefaultMapName);
            IMapLayerInfos layerInfos    = mapServerInfo.MapLayerInfos;

            for (int i = 0; i < layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.Element[i];
                if (layerInfo.Type.Equals("Utility Network Layer", StringComparison.OrdinalIgnoreCase))
                {
                    return(layerInfo);
                }
            }

            return(null);
        }
Beispiel #16
0
        private esriGeometryType GetLayerGeometryType(IMapLayerInfos layerInfos, int layerIndex)
        {
            IMapLayerInfo3 layerInfo;

            // Find the index of the layer of interest.
            int layerCount = layerInfos.Count;

            for (int i = 0; i < layerCount; i++)
            {
                layerInfo = layerInfos.get_Element(i) as IMapLayerInfo3;
                if (layerInfo.ID == layerIndex)
                {
                    return(this.GetGeometryTypeFromFields(layerInfo.Fields));
                }
            }

            throw new InvalidOperationException(string.Format("Unable to locate layerId [{0}] in map service. Please check the map service REST API to ensure this layer index exists.", layerIndex));
        }
        private IMapLayerInfo GetLayerInfo(IMapServer3 mapServer, int layerID)
        {
            IMapLayerInfo layerInfo;

            IMapLayerInfos layerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos;
            long           c          = layerInfos.Count;

            for (int i = 0; i < c; i++)
            {
                layerInfo = layerInfos.get_Element(i);
                if (layerInfo.ID == layerID)
                {
                    return(layerInfo);
                }
            }

            throw new ArgumentOutOfRangeException("layerID");
        }
        public void Init(IServerObjectHelper pSOH)
        {
            IMapServer           mapServer           = pSOH.ServerObject as IMapServer;
            IMapServerDataAccess mapServerDataAccess = mapServer as IMapServerDataAccess;
            IMapServerInfo       mapServerInfo       = mapServer.GetServerInfo(mapServer.DefaultMapName);
            IMapLayerInfos       layerInfos          = mapServerInfo.MapLayerInfos;
            IMapLayerInfo        ndLayerInfo         = null;

            // Get the network dataset layer from current service
            for (var i = 0; i < layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.Element[i];
                if (layerInfo.Type.Equals("Network Dataset Layer", StringComparison.InvariantCultureIgnoreCase))
                {
                    ndLayerInfo = layerInfo;
                    break;
                }
            }

            // Get the network dataset
            if (ndLayerInfo != null)
            {
                var dt = mapServerDataAccess.GetDataSource(mapServer.DefaultMapName, ndLayerInfo.ID);
                // Cast the dataset to required network dataset interface
                networkDataset = dt as INetworkDataset;
            }

            if (networkDataset != null)
            {
                // Open the streets feature class
                IDataset          dataSet    = networkDataset as IDataset;
                IFeatureWorkspace fWorkspace = dataSet.Workspace as IFeatureWorkspace;
                streetFC = fWorkspace.OpenFeatureClass(streetsName);

                // Get the Streets source ID
                INetworkSource streetNetworkSource = networkDataset.SourceByName[streetsName];
                streetsSourceID = streetNetworkSource.ID;

                // Get the TraveTime attribute ID
                INetworkAttribute travelTimeAttribute = networkDataset.AttributeByName[costAttributeName];
                travelTimeAttributeID = travelTimeAttribute.ID;
            }
        }
Beispiel #19
0
        /// <summary>
        /// Locates the feature class matching the supplied name.
        /// </summary>
        /// <param name="serverObject"></param>
        /// <param name="featureClassName"></param>
        /// <returns></returns>
        public static IFeatureClass FindFeatureClass(this ESRI.ArcGIS.Server.IServerObject serverObject, string featureClassName)
        {
            // Get the list of layers
            var mapServer = serverObject as IMapServer3;

            if (mapServer == null)
            {
                return(null);
            }

            var mapServerDataAccess = mapServer as IMapServerDataAccess;

            if (mapServerDataAccess == null)
            {
                return(null);
            }

            IMapLayerInfos mapLayerInfos = mapServer.GetServerInfo(mapServer.DefaultMapName).MapLayerInfos;

            for (int i = 0; i < mapLayerInfos.Count; i++)
            {
                IMapLayerInfo layer = mapLayerInfos.get_Element(i);

                if (layer == null || !layer.IsFeatureLayer)
                {
                    continue;
                }

                var featureClass = mapServerDataAccess.GetDataSource(mapServer.DefaultMapName, layer.ID) as IFeatureClass;

                if (featureClass == null || string.IsNullOrEmpty(featureClass.AliasName))
                {
                    continue;
                }

                if (featureClass.AliasName.EndsWith(featureClassName))
                {
                    return(featureClass);
                }
            }

            return(null);
        }
        /// <summary>
        /// list layers in each dataframes in a TreeView
        /// </summary>
        private void listLayers(IMapServer pMapServer)
        {
            string         strMapName    = "";
            IMapServerInfo pMSI          = null;
            IMapLayerInfos pMLInfos      = null;
            IMapLayerInfo  pMLI          = null;
            TreeViewItem   pTVIDataFrame = null;

            for (int i = 0; i < pMapServer.MapCount; i++)
            {
                strMapName = pMapServer.get_MapName(i);
                if (!strMapName.Equals(pMapServer.DefaultMapName))
                {
                    continue;
                }

                //only for the active dataframe
                pMSI     = pMapServer.GetServerInfo(strMapName);
                pMLInfos = pMSI.MapLayerInfos;

                pTVIDataFrame = CreateTreeViewItem(strMapName);
                tvwLayers.Items.Add(pTVIDataFrame);

                for (int j = 0; j < pMLInfos.Count; j++)
                {
                    pMLI = pMLInfos.get_Element(j);
                    AddTVItemForSubLayer(pTVIDataFrame, pMLInfos, pMLI, ref j);
                }
                pTVIDataFrame.IsExpanded = true;
            }

            if (pMapServer.MapCount > 1)
            {
                tvwLayers.Items.Add("");
                TextBlock tb = new TextBlock()
                {
                    Text       = "<Other non-active dataframe cannot be used>",
                    Foreground = new SolidColorBrush(Colors.DarkGray),
                    FontStyle  = FontStyles.Italic
                };
                tvwLayers.Items.Add(tb);
            }
        }
Beispiel #21
0
        /// <summary>
        /// Returns a dictionary of feature layer IDs keyed by data source names.
        /// </summary>
        /// <returns>Returns a dictionary of feature layer IDs keyed by data source names.</returns>
        private Dictionary <string, List <int> > GetDistinctDataSourceInfo()
        {
            var    mapServer      = (IMapServer3)_serverObjectHelper.ServerObject;
            string defaultMapName = mapServer.DefaultMapName;

            var msDataAccess = (IMapServerDataAccess)_serverObjectHelper.ServerObject;

            IMapServerInfo3 serverInfo    = mapServer.GetServerInfo(defaultMapName) as IMapServerInfo3;
            IMapLayerInfos  mapLayerInfos = serverInfo.MapLayerInfos;

            var output = (from layerInfo in mapLayerInfos.AsEnumerable()
                          where layerInfo.IsFeatureLayer
                          select new
            {
                Id = layerInfo.ID,
                DataSource = ((IDataset)msDataAccess.GetDataSource(defaultMapName, layerInfo.ID)).Name
            }).GroupBy(a => a.DataSource, a => a.Id).ToDictionary(g => g.Key, g => g.ToList());

            return(output);
        }
        private void AddTVItemForSubLayer(TreeViewItem pTVIParent, IMapLayerInfos pMLInfos, IMapLayerInfo pMLI, ref int curMLIindex)
        {
            TreeViewItem pTVIlayer = CreateTreeViewItem(pMLI); //pMLI.Name, pMLI.ID, false);

            pTVIParent.Items.Add(pTVIlayer);

            ILongArray pSubLayersIDs = pMLI.SubLayers;

            if (pSubLayersIDs == null)
            {
                return;
            }

            //when it is a group layer
            IMapLayerInfo pChildMLI = null;

            for (int i = 0; i < pSubLayersIDs.Count; i++)
            {
                pChildMLI = pMLInfos.get_Element(++curMLIindex);
                AddTVItemForSubLayer(pTVIlayer, pMLInfos, pChildMLI, ref curMLIindex);
            }
        }
Beispiel #23
0
        /// <summary>
        /// get RouteLayerInfo from Id
        /// </summary>
        /// <param name="routeLayerID">value of routeLayerID</param>
        /// <returns>object RouteLayerInfo</returns>
        private RouteLayerInfo GetRouteLayerInfo(int routeLayerID)
        {
            if (routeLayerID < 0)
            {
                throw new ArgumentOutOfRangeException("routeLayerID");
            }

            IMapServer3    serverObject  = this.GetMapServer();
            IMapLayerInfos mapLayerInfos = serverObject.GetServerInfo(serverObject.DefaultMapName).MapLayerInfos;
            long           count         = mapLayerInfos.Count;

            for (int i = 0; i < count; i++)
            {
                IMapLayerInfo mapLayerInfo = mapLayerInfos.get_Element(i);
                if (mapLayerInfo.ID == routeLayerID)
                {
                    return(new RouteLayerInfo(mapLayerInfo));
                }
            }

            throw new ArgumentOutOfRangeException("routeLayerID");
        }
Beispiel #24
0
        public void Init(IServerObjectHelper pSOH)
        {
            _soHelper  = pSOH;
            _serverLog = new ServerLogger();

            // set the name of the point layer in the mapservice
            string mapLayerToFind = "points";

            //System.Diagnostics.Debugger.Launch();
            //Access the map service and its layer infos
            ESRI.ArcGIS.Carto.IMapServer3 mapServer = (ESRI.ArcGIS.Carto.IMapServer3)_soHelper.ServerObject;
            string         mapName    = mapServer.DefaultMapName;
            IMapLayerInfos layerInfos = mapServer.GetServerInfo(mapName).MapLayerInfos;
            IMapLayerInfo  layerInfo;

            // Find the index of the layer of interest
            int c          = layerInfos.Count;
            int layerIndex = 0;

            for (int i = 0; i < c; i++)
            {
                layerInfo = layerInfos.get_Element(i);
                if (layerInfo.Name == mapLayerToFind)
                {
                    layerIndex = i;
                    break;
                }
            }

            // Access the source feature class of the layer data source (to request it on map export :-))
            IMapServerDataAccess dataAccess = (IMapServerDataAccess)mapServer;

            myPointsClass = (IFeatureClass)dataAccess.GetDataSource(mapName, layerIndex);

            _serverLog.LogMessage(ServerLogger.msgType.infoStandard, _soiName + ".init()", 200, "Initialized " + _soiName + " SOI.");
        }
Beispiel #25
0
        public void Construct(IPropertySet props)
        {
            configProps = props;
            // Read the properties.

            if (props.GetProperty("FieldName") != null)
            {
                m_mapFieldToQuery = props.GetProperty("FieldName") as string;
            }
            else
            {
                throw new ArgumentNullException();
            }
            if (props.GetProperty("LayerName") != null)
            {
                m_mapLayerNameToQuery = props.GetProperty("LayerName") as string;
            }
            else
            {
                throw new ArgumentNullException();
            }
            try
            {
                // Get the feature layer to be queried.
                // Since the layer is a property of the SOE, this only has to be done once.
                IMapServer3    mapServer = (IMapServer3)serverObjectHelper.ServerObject;
                string         mapName   = mapServer.DefaultMapName;
                IMapLayerInfo  layerInfo;
                IMapLayerInfos layerInfos = mapServer.GetServerInfo(mapName).MapLayerInfos;
                // Find the index position of the map layer to query.
                int c          = layerInfos.Count;
                int layerIndex = 0;
                for (int i = 0; i < c; i++)
                {
                    layerInfo = layerInfos.get_Element(i);
                    if (layerInfo.Name == m_mapLayerNameToQuery)
                    {
                        layerIndex = i;
                        break;
                    }
                }
                // Use IMapServerDataAccess to get the data
                IMapServerDataAccess dataAccess = (IMapServerDataAccess)mapServer;
                // Get access to the source feature class.
                m_fcToQuery = (IFeatureClass)dataAccess.GetDataSource(mapName, layerIndex);
                if (m_fcToQuery == null)
                {
                    logger.LogMessage(ServerLogger.msgType.error, "Construct", 8000, "SOE custom error: Layer name not found.");
                    return;
                }
                // Make sure the layer contains the field specified by the SOE's configuration.
                if (m_fcToQuery.FindField(m_mapFieldToQuery) == -1)
                {
                    logger.LogMessage(ServerLogger.msgType.error, "Construct", 8000, "SOE custom error: Field not found in layer.");
                }
            }
            catch
            {
                logger.LogMessage(ServerLogger.msgType.error, "Construct", 8000, "SOE custom error: Could not get the feature layer.");
            }
        }
Beispiel #26
0
        /// <summary>
        /// Retrieves a list of connection properties from the layers of a <see cref="IMapServer"/>.
        /// </summary>
        /// <param name="mapServer">A map server.</param>
        /// <param name="propertyNames">The names of the keys in each dictionary of the output object.</param>
        /// <returns>
        /// A list of <see cref="KeyValuePair&lt;TKey,KValue&gt;"/> objects.
        /// Each <see cref="KeyValuePair&lt;TKey,KValue&gt;.Key"/> corresponds to a data source name.
        /// Each value is a <see cref="Dictionary&lt;TKey,TValue&gt;"/> of connection properties.
        /// </returns>
        public static List <ConnectionProperties> GetConnectionProperties(this IMapServer mapServer /*, out List<string> propertyNames*/)
        {
            IMapLayerInfos       mapLayerInfos = null;
            IMapLayerInfo        mapLayerInfo  = null;
            IMapServerDataAccess mapServerDA   = null;
            IMapServerInfo       mapServerInfo = null;;
            ////propertyNames = new List<string>();
            IDataset     dataset = null;
            IPropertySet connectionPropertySet = null;
            object       namesObj, valuesObj;

            string[] names;
            object[] values;

            var output = new List <ConnectionProperties>();

            try
            {
                mapServerDA = (IMapServerDataAccess)mapServer;
                // Get the server info for the default map. (This application will assume that there is only a single map: the default.)
                string mapName = mapServer.DefaultMapName;
                mapServerInfo = mapServer.GetServerInfo(mapName);
                // Loop through all of the layers in the map service...
                mapLayerInfos = mapServerInfo.MapLayerInfos;

                ConnectionProperties connectionProperties;

                for (int i = 0, l = mapLayerInfos.Count; i < l; i++)
                {
                    mapLayerInfo = mapLayerInfos.get_Element(i);
                    if (mapLayerInfo.IsComposite)
                    {
                        continue;
                    }

                    connectionProperties = new ConnectionProperties(mapLayerInfo.Name);
                    try
                    {
                        dataset = mapServerDA.GetDataSource(mapName, i) as IDataset;
                    }
                    catch (NotImplementedException ex)
                    {
                        connectionProperties["error"] = ex.Message;
                        output.Add(connectionProperties);
                        continue;
                    }

                    if (dataset != null)
                    {
                        connectionPropertySet = dataset.Workspace.ConnectionProperties;
                        connectionPropertySet.GetAllProperties(out namesObj, out valuesObj);
                        names  = namesObj as string[];
                        values = valuesObj as object[];

                        string name;
                        for (int j = 0; j < names.Length; j++)
                        {
                            name = names[j];
                            connectionProperties[name] = values[j];
                        }
                        output.Add(connectionProperties);
                    }
                }
            }
            finally
            {
                foreach (var item in new object[] { mapLayerInfos, mapLayerInfo, mapServerDA, mapServerInfo, dataset, connectionPropertySet })
                {
                    if (item != null)
                    {
                        Marshal.ReleaseComObject(item);
                    }
                }
            }

            return(output);
        }
        public void Init(IServerObjectHelper pSOH)
        {
            serverObjectHelper = pSOH;

            mapServerDataAccess = (IMapServerDataAccess)pSOH.ServerObject;
            IMapServer3 ms = (IMapServer3)pSOH.ServerObject;
            this.mapServerInfo = ms.GetServerInfo(ms.DefaultMapName);
            this.layerInfos = mapServerInfo.MapLayerInfos;

            if (layerId < 0)
                layerId = 0;
        }
        private void AddTVItemForSubLayer(TreeViewItem pTVIParent, IMapLayerInfos pMLInfos, IMapLayerInfo pMLI, ref int curMLIindex)
        {
            TreeViewItem pTVIlayer = CreateTreeViewItem(pMLI); //pMLI.Name, pMLI.ID, false);
            pTVIParent.Items.Add(pTVIlayer);

            ILongArray pSubLayersIDs = pMLI.SubLayers;
            if (pSubLayersIDs == null)
                return;

            //when it is a group layer
            IMapLayerInfo pChildMLI = null;
            for (int i = 0; i < pSubLayersIDs.Count; i++)
            {
                pChildMLI = pMLInfos.get_Element(++curMLIindex);
                AddTVItemForSubLayer(pTVIlayer, pMLInfos, pChildMLI, ref curMLIindex);
            }
        }
Beispiel #29
0
        private esriGeometryType GetLayerGeometryType(IMapLayerInfos layerInfos, int layerIndex)
        {
            IMapLayerInfo3 layerInfo;

            // Find the index of the layer of interest.
            int layerCount = layerInfos.Count;
            for (int i = 0; i < layerCount; i++)
            {
                layerInfo = layerInfos.get_Element(i) as IMapLayerInfo3;
                if (layerInfo.ID == layerIndex)
                {
                    return this.GetGeometryTypeFromFields(layerInfo.Fields);
                }
            }

            throw new InvalidOperationException(string.Format("Unable to locate layerId [{0}] in map service. Please check the map service REST API to ensure this layer index exists.", layerIndex));
        }
        private void btnExportAsJSON_Click(object sender, RoutedEventArgs e)
        {
            string         dataframeName;
            string         outFile;
            IMapLayerInfos pMLInfos = null;
            IMapLayerInfo  pMLI     = null;

            //checking the existence of the output folder
            //DirectoryInfo outDirInfo = new DirectoryInfo(txtOutputFolder.Text);
            string outDir = txtOutputFolder.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(txtMXD.Text);

            if (Directory.Exists(outDir))
            {
                MessageBoxResult msgRes = System.Windows.MessageBox.Show(String.Format("Folder already exists \n{0}. \nDo you want to over write it?", outDir), "Output Folder", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (msgRes == MessageBoxResult.No)
                {
                    System.Windows.MessageBox.Show("Operation is cancelled", "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
                else
                {
                    try
                    {
                        Directory.Delete(outDir, true);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.MessageBox.Show(String.Format("Failed to delete the folder \n{0}\n\n{1}", outDir, ex.Message), "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
            }
            Directory.CreateDirectory(outDir);

            prsProgress.IsIndeterminate = false;
            prsProgress.Visibility      = System.Windows.Visibility.Visible;

            TreeViewItem pTVIDataframe = null;

            for (int i = 0; i < m_pMapServer.MapCount; i++)
            {
                dataframeName = m_pMapServer.get_MapName(i);
                if (dataframeName != m_pMapServer.DefaultMapName)
                {
                    continue;
                }

                //ONLY for the default dataframe
                pTVIDataframe = tvwLayers.Items[0] as TreeViewItem;

                //getting REST resources including layer infos
                string     restOutputResource = Utils.GetLayersResource(m_pMapServer);
                JSONObject jObject            = new JSONObject();
                jObject.ParseString(restOutputResource);
                IJSONArray layers = null;
                jObject.TryGetValueAsArray("layers", out layers);

                pMLInfos            = m_pMapServer.GetServerInfo(dataframeName).MapLayerInfos;
                prsProgress.Maximum = pMLInfos.Count;
                for (int j = 0; j < pMLInfos.Count; j++)
                {
                    pMLI = pMLInfos.get_Element(j);
                    if (pMLI.IsFeatureLayer)
                    {
                        bool isSelected = false;
                        IsLayerSelectedForExport(pTVIDataframe, pMLI.ID, ref isSelected);
                        if (isSelected)
                        {
                            IJSONObject layer    = (IJSONObject)layers.get_Value(j);
                            String      renderer = Utils.GetRendererFromLayer(layer.ToJSONString(null));

                            outFile = string.Format(@"{0}\{1:000} {2}.json", outDir, pMLI.ID, Utils.ValidateFileName(pMLI.Name));
                            try
                            {
                                File.WriteAllText(outFile, renderer);
                            }
                            catch (Exception ex)
                            {
                                System.Windows.MessageBox.Show(String.Format("Failed to write content to the file\n{0}\n\n{1}", outFile, ex.Message), "Export As JSON", MessageBoxButton.OK, MessageBoxImage.Error);
                                prsProgress.Visibility = System.Windows.Visibility.Hidden;
                                return;
                            }
                        }
                    }
                    prsProgress.Value += 1;
                }
            }

            prsProgress.Visibility = System.Windows.Visibility.Hidden;
            System.Windows.MessageBox.Show(String.Format("Conversion Completed\nOutput Path: {0}", outDir), "JSON Conversion", MessageBoxButton.OK, MessageBoxImage.Information);
        }