Exemplo n.º 1
0
 private void AddMapServiceLayer(CswRecord cswrecord, string sldForWMS)
 {
     MapServiceInfo msinfo = new MapServiceInfo();
     msinfo.Server = cswrecord.MapServerURL;
     msinfo.Service = cswrecord.ServiceName;
     msinfo.ServiceType = cswrecord.Protocol;
     CswProfile.ParseServiceInfoFromUrl(msinfo, cswrecord.MapServerURL, cswrecord.Protocol);
     switch (cswrecord.Protocol.ToUpper())
     {
         case "WMS":
         case "OGC:WMS":
             AddLayerWMS(msinfo, true,sldForWMS);
             break;
         case "WCS":
         case "OGC:WCS":
             AddLayerWCS(cswrecord.MapServerURL);
             break;
         case "OGC:WMTS"://"TMS":
         case "UKST":
             AddLayerWMTS(cswrecord);//AddLayerTMS(cswrecord);
             break;
         case "WFS":
         case "OGC:WFS":
             AddLayerWFS(cswrecord);
             break;
         case "AGS":
             string url = String.Empty;
             url = cswrecord.MapServerURL;
             if (url.ToLower().Contains("arcgis/rest"))
             {
                 url = url + "?f=lyr";
                 CswClient client = new CswClient();
                 AddAGSService(client.SubmitHttpRequest("DOWNLOAD", url, ""));
             }
             else
             {
                 AddAGSService(url);
             }
             break;
         case "AIMS":
             AddLayerArcIMS(msinfo);
             break;
         default: 
             MessageBox.Show(String.Format("Adding data of type {0} is not implemented yet.",cswrecord.Protocol.ToUpper()));
             break;
     }
 }
Exemplo n.º 2
0
        public static void ParseServiceInfoFromUrl(MapServiceInfo msinfo, String mapServerUrl, String serviceType)
        {

            msinfo.Service = "Generic " + serviceType + " Service Name";
            String[] urlParts = mapServerUrl.Trim().Split('?');
            if (urlParts.Length > 0)
                msinfo.Server = urlParts[0];
            else
                msinfo.Server = mapServerUrl;

            String[] s = msinfo.Server.Split(new String[] { "/servlet/com.esri.esrimap.Esrimap" }, StringSplitOptions.RemoveEmptyEntries);
            msinfo.Server = s[0];

            if (urlParts.Length > 1)
            {
                String[] urlParams = urlParts[1].Trim().Split('&');

                foreach (String param in urlParams)
                {
                    String paramPrefix = param.ToLower();
                    if (paramPrefix.StartsWith("service=") || paramPrefix.StartsWith("servicename="))
                    {
                        msinfo.Service = param.Trim().Split('=')[1];
                    }
                }

            }

        }     
Exemplo n.º 3
0
        /// <summary>
        /// prepare metadata. Metadata xml is transformed to an intermediate format. 
        /// Map service information shall be generated and put in <Esri></Esri> tags.
        /// </summary>
        /// <param name="xmlDoc">Metadata XML document</param>
        /// <returns>Transformed XML document</returns>
       /* private XmlDocument PrepareMetadata(XmlDocument xmlDoc)
        {
            try
            {
                if (xmlDoc == null) { throw new ArgumentNullException(); }

                //load the Xsl if necessary
                if (_xsltPrepare == null)
                {
                    _xsltPrepare = new XslCompiledTransform();
                    try { _xsltPrepare.Load(_xsltPrepareMetadataFilePath); }
                    catch (Exception ex)
                    {
                        ShowErrorMessageBox(StringResources.LoadMetadataPreparationStylesheetFailed + "\r\n" + ex.Message);
                        return null;
                    }
                }

                // todo: clean metadata xml. remove namespaces (to be consistant with the behavior on Portal) (?) 

                // transform
                StringWriter strWriter = new StringWriter();
                _xsltPrepare.Transform(new XmlNodeReader(xmlDoc), null, (TextWriter)strWriter);
                strWriter.Close();

                XmlDocument newXmlDoc = new XmlDocument();
                newXmlDoc.LoadXml(strWriter.ToString());

                return newXmlDoc;
            }
            catch (Exception ex)
            {
                ShowErrorMessageBox(StringResources.PrepareMetadataFailed + "\r\n" + ex.Message);
                return null;
            }
        }*/

        /// <summary>
        /// Parse out service information (such as service type, server name, service name, etc) from metadta document
        /// </summary>
        /// <param name="xmlDoc">xml metadata doc to be parsed</param>
        /// <param name="msi">A MapServiceInfo object as output</param>
        private MapServiceInfo ParseServiceInfoFromMetadata(XmlDocument xmlDoc)
        {
            // note: some required node may missing if it isn't a metadata for liveData or map
            try
            {
                if (xmlDoc == null) { throw new ArgumentNullException(); }

                MapServiceInfo msi = new MapServiceInfo();

                XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(xmlDoc.NameTable);
                xmlNamespaceManager.AddNamespace("cat", "http://www.esri.com/metadata/csw/");
                xmlNamespaceManager.AddNamespace("csw", "http://www.opengis.net/cat/csw");
                xmlNamespaceManager.AddNamespace("gmd", "http://www.isotc211.org/2005/gmd");

                XmlNode nodeMetadata = xmlDoc.SelectSingleNode("//metadata|//cat:metadata|//csw:metadata|//gmd:MD_Metadata", xmlNamespaceManager);
                if (nodeMetadata == null) { throw new Exception(StringResources.MetadataNodeMissing); }

                // parse out service information
                XmlNode nodeEsri = nodeMetadata.SelectSingleNode("Esri");
                if (nodeEsri == null) throw new Exception(StringResources.EsriNodeMissing);

                // server
                XmlNode node = nodeEsri.SelectSingleNode("Server");
                if (node == null) throw new Exception(StringResources.ServerNodeMissing);
                msi.Server = node.InnerText;

                // service
                node = nodeEsri.SelectSingleNode("Service");
                if (node != null) { msi.Service = node.InnerText; }

                // service type
                node = nodeEsri.SelectSingleNode("ServiceType");
                if (node != null) { msi.ServiceType = node.InnerText; }

                // service param
                node = nodeEsri.SelectSingleNode("ServiceParam");
                if (node != null) { msi.ServiceParam = node.InnerText; }

                // issecured
                node = nodeEsri.SelectSingleNode("issecured");
                if (node != null) { msi.IsSecured = (node.InnerText.Equals("True", StringComparison.OrdinalIgnoreCase)); }

                return msi;
            }
            catch (Exception ex)
            {
                ShowErrorMessageBox(StringResources.MapServiceInfoNotAvailable + "\r\n" + ex.Message);
                return null;
            }
        }