Ejemplo n.º 1
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);
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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 static IEnumerable <IMapLayerInfo3> AsEnumerable(this IMapLayerInfos layerInfos)
 {
     for (int i = 0; i < layerInfos.Count; i++)
     {
         yield return(layerInfos.get_Element(i) as IMapLayerInfo3);
     }
 }
        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);
        }
        private CustomLayerInfo[] GetLayerInfos()
        {
            int c = this.layerInfos.Count;

            CustomLayerInfo[] customLayerInfos = new CustomLayerInfo[c];

            for (int i = 0; i < c; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                customLayerInfos[i] = new CustomLayerInfo(layerInfo);
            }

            return(customLayerInfos);
        }
Ejemplo n.º 9
0
        private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";

            JSONArray layersArray = new JSONArray();

            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                JSONObject    jo        = new JSONObject();
                jo.AddString("name", layerInfo.Name);
                jo.AddLong("id", layerInfo.ID);
                jo.AddString("type", layerInfo.Type);
                jo.AddString("description", layerInfo.Description);

                layersArray.AddJSONObject(jo);
            }

            JSONObject result = new JSONObject();

            result.AddJSONArray("layers", layersArray);
            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }
        private JSONArray getLayerInfo()
        {
            JSONArray layersArray = new JSONArray();

            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                JSONObject    jo        = new JSONObject();
                jo.AddString("name", layerInfo.Name);
                jo.AddLong("id", layerInfo.ID);
                jo.AddString("description", layerInfo.Description);
                layersArray.AddJSONObject(jo);
            }

            return(layersArray);
        }
        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");
        }
Ejemplo n.º 12
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));
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        /// <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);
            }
        }
Ejemplo n.º 15
0
        private byte[] LayersResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = "{\"Content-Type\" : \"application/json\"}";
            String aoLayerType = "";

            if (this.layerType.Equals("feature"))
            {
                aoLayerType = "Feature Layer";
            }
            else if (this.layerType.Equals("raster"))
            {
                aoLayerType = "Raster Layer";
            }
            else if (this.layerType.Equals("dataset"))
            {
                aoLayerType = "Network Dataset Layer";
            }
            else
            {
                throw new Exception("Propety layerType has invalid value. Acceptable values are \"feature\", \"raster\", and \"dataset\".");
            }

            JSONArray layersArray = new JSONArray();

            for (int i = 0; i < this.layerInfos.Count; i++)
            {
                IMapLayerInfo layerInfo = layerInfos.get_Element(i);
                String        lType     = layerInfo.Type;
                if (lType.Equals(aoLayerType))
                {
                    JSONObject jo = new JSONObject();
                    jo.AddString("name", layerInfo.Name);
                    jo.AddLong("id", layerInfo.ID);
                    jo.AddString("description", layerInfo.Description);
                    layersArray.AddJSONObject(jo);
                }
            }

            JSONObject result = new JSONObject();

            result.AddJSONArray("Layers", layersArray);
            return(Encoding.UTF8.GetBytes(result.ToJSONString(null)));
        }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
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");
        }
Ejemplo n.º 18
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.");
        }
Ejemplo n.º 19
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.");
            }
        }
Ejemplo n.º 20
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);
            }
        }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
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));
        }