Example #1
0
        // starts at IMAGE begin element
        public static EsriImageResponse ProcessImageReturn(XmlReader responseReader, string requestString, string responseString)
        {
            string localName = "start";
            EsriImageResponse response = new EsriImageResponse();

            response.LastRequest = requestString;
            response.LastResponse = responseString;

            try
            {
                while (responseReader.Read())
                {
                    if (responseReader.NodeType == XmlNodeType.Element)
                    {
                        localName = responseReader.LocalName;

                        switch (responseReader.LocalName)
                        {
                            case "OUTPUT":
                                responseReader.MoveToAttribute("url");
                                response._mapImageUrl = responseReader.Value;
                                break;
                            case "LEGEND":
                                responseReader.MoveToAttribute("url");
                                response._legendUrl = responseReader.Value;
                                break;
                            case "ENVELOPE":
                                response._envelope = EsriEnvelope.ProcessEnvelopeNode(responseReader);
                                break;
                            case "LAYER":
                                EsriLayerInfo newLayer = EsriService.AddLayerInfo(responseReader, false);

                                try
                                {
                                    response._layers.Add(newLayer);
                                }
                                catch
                                {
                                    // exception for value in range
                                }
                                break;
                            case "LAYERDEF":
                                LayerDef newLayerDef = LayerDef.ProcessLayerNode(responseReader);
                                try
                                {
                                    response._layerdefs.Add(newLayerDef);
                                }
                                catch
                                {
                                    // exception for value in range
                                }
                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.LastResponse = localName;
                response.ErrorMessage = ex.Message;
            }

            return response;
        }
        public override bool GetMap(GISService activeService, List<GISLayerInfo> mapLayers, GISEnvelope mapEnvelope, double zoomLevel, string requestXml)
        {
            string requestUrl = String.Format(SERVICE_URL, Server.Host, Server.ServletPath, activeService.Id, Server.UseForm, Server.Version);
            XmlReader responseString = null;
            EsriImageResponse response = new EsriImageResponse();

            try
            {
                response.Envelope = mapEnvelope;
                response._layers.AddRange(mapLayers);
                response.LastRequest = requestXml;
                response._mapImageUrl = requestUrl;
                response.ZoomLevel = zoomLevel;

                // http://websig.hidrografico.pt/servlet/com.esri.esrimap.Esrimap?ServiceName=ICENCUK&ClientVersion=4.0&Form=True&Encode=False
                webClient.PostRequest(requestUrl, Server.UseForm ? ApplyFormEncoding(requestXml) : requestXml, ProcessImageReturn, response);
                return true;
            }
            catch (Exception ex)
            {
                return false; // new GISResponse() { _envelope = mapEnvelope, _layers = mapLayers, ErrorMessage = ex.Message, HasError = true, LastRequest = requestXml, LastResponse = Return };
                //return GISResponse.ProcessErrorResponse("The last map request failed: " + ex.Message, Request, Return);
            }
            finally
            {
                //if (responseString != null) responseString.Close();
            }
        }
        public override bool GetMap(GISService activeService, List<GISLayerInfo> mapLayers, GISEnvelope mapEnvelope, double zoomLevel, string requestString)
        {
            EsriImageResponse response = new EsriImageResponse();

            try
            {
                response.Envelope = mapEnvelope;
                response._layers.AddRange(mapLayers);
                response.LastRequest = requestString;
                response._mapImageUrl = requestString;
                response.ZoomLevel = zoomLevel;

                webClient.GetRequest(requestString, ProcessImageReturn, response);
                return true;
            }
            catch (System.Exception ex)
            {
                Server.RaiseErrorResponse(new GISResponse() { LastResponse = ex.Message, ErrorMessage = ex.Message, HasError = true, LastRequest = requestString, _envelope = response.Envelope, _layers = mapLayers });
                return false;
            }
        }