public WMSLayers getAllLayerNamesOfWMS(string urlstring) { WMSLayers wms_layers = new WMSLayers(); List <WMSLayer> layerList = new List <WMSLayer>(); wms_layers.layersList = layerList; wms_layers.WMSURL = urlstring; if (!urlstring.ToLower().Contains("service=")) { if (urlstring.Contains("?")) { if (urlstring.EndsWith("&")) { urlstring += "SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"; } else { urlstring += "&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"; } } else { urlstring += "?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"; } } XDocument doc = null; try { string response = BaseHttpFunctions.HttpGet(urlstring); doc = XDocument.Parse(response); } catch (Exception e) { e.GetType(); return(null); } if (doc != null) { XElement rootElement = doc.Root; IEnumerable <XElement> Services = rootElement.Descendants(XName.Get("Service")); if (Services != null) { foreach (XElement Service in Services) { string name = null; string title = null; XElement nameElement = Service.Element(XName.Get("Name")); if (nameElement != null) { name = nameElement.Value; if (name != null && !(name.Trim().Equals(""))) { wms_layers.name = name; } } XElement titleElement = Service.Element(XName.Get("Title")); if (titleElement != null) { title = titleElement.Value; if (title != null && !(title.Trim().Equals(""))) { wms_layers.title = title; } } } } Dictionary <XElement, BBox> layer_bbox_map = new Dictionary <XElement, BBox>(); IEnumerable <XElement> Layers = rootElement.Descendants(XName.Get("Layer")); if (Layers != null) { foreach (XElement layer in Layers) { string name = null; string title = null; XElement nameElement = layer.Element(XName.Get("Name")); XElement LatLonBoundingBoxElement = layer.Element(XName.Get("LatLonBoundingBox")); WMSLayer layerObject = new WMSLayer(); BBox bbox = null; if (LatLonBoundingBoxElement != null) { bbox = new BBox(); XAttribute a = LatLonBoundingBoxElement.Attribute(XName.Get("maxy")); if (a != null) { string value = a.Value; if (value != null) { bbox.BBox_Upper_Lat = Double.Parse(value); } } a = LatLonBoundingBoxElement.Attribute(XName.Get("miny")); if (a != null) { string value = a.Value; if (value != null) { bbox.BBox_Lower_Lat = Double.Parse(value); } } a = LatLonBoundingBoxElement.Attribute(XName.Get("maxx")); if (a != null) { string value = a.Value; if (value != null) { bbox.BBox_Upper_Lon = Double.Parse(value); } } a = LatLonBoundingBoxElement.Attribute(XName.Get("minx")); if (a != null) { string value = a.Value; if (value != null) { bbox.BBox_Lower_Lon = Double.Parse(value); } } layerObject.box = bbox; layer_bbox_map.Add(layer, bbox); } //if current layer don't contain LatLonBoundingBox and Parent Layer is not exist or do not contain LatLonBoundingBox either, current layer is not accessible else { if (layer.Parent.Name.Equals(XName.Get("Layer"))) { if (layer_bbox_map.ContainsKey(layer.Parent)) { bbox = BBox.CreateBBox(layer_bbox_map[layer.Parent]); layerObject.box = bbox; layer_bbox_map.Add(layer, bbox); } else { continue; } } else { continue; } } //if there is not Layer name or LatLonBoundingBox element exist, the layer is not accessible if (nameElement == null) { continue; } else { name = nameElement.Value; if (name != null && !(name.Trim().Equals(""))) { layerObject.name = name; } XElement titleElement = layer.Element(XName.Get("Title")); if (titleElement != null) { title = titleElement.Value; if (title != null && !(title.Trim().Equals(""))) { layerObject.title = title; } } //we want to show title, which provide us more inforamtion than layer name, but when there is not layer title, we still show layer name as title if (layerObject.title == null && layerObject.name != null) { layerObject.title = layerObject.name; } layerList.Add(layerObject); } } } } return(wms_layers); }
public WMSLayerInfoWithQoS getWMSLayersQoSSummaryInfo(ServiceInfoForSummary serviceInfo) { XDocument doc1 = new XDocument(); XElement Envelope = new XElement(XName.Get("Envelope", soapenv_namespace)); Envelope.Add(new XAttribute(XNamespace.Xmlns + "xsd", xsd_namespace)); Envelope.Add(new XAttribute(XNamespace.Xmlns + "xsi", xsi_namespace)); Envelope.Add(new XAttribute(XNamespace.Xmlns + "soapenv", soapenv_namespace)); XElement Body = new XElement(XName.Get("Body", soapenv_namespace)); XElement GetLayerPerforRank = new XElement(XName.Get(GetLayerPerforRank_String, CISCChecker_namespace)); GetLayerPerforRank.Add(new XAttribute(XNamespace.Xmlns + "ns", CISCChecker_namespace)); string url = serviceInfo.serviceURL; string serviceType = serviceInfo.serviceType; if (serviceType.Equals(SearchingContent.resourceTypeValue_CLH_Services)) { serviceType = SearchingContent.ServiceType_WMS; } if (url != null && !url.Trim().Equals("") && serviceType != null && !serviceType.Trim().Equals("")) { //XElement ServiceInfo = new XElement(XName.Get("ServiceInfo", CISCChecker_namespace)); XElement ServiceInfo = new XElement(ServiceInfo_String); ServiceInfo.SetAttributeValue(URL_String, url); ServiceInfo.SetAttributeValue(ServiceType_String, serviceType); GetLayerPerforRank.Add(ServiceInfo); } Body.Add(GetLayerPerforRank); Envelope.Add(Body); doc1.Add(Envelope); string postRequest = doc1.ToString(); resultString = BaseHttpFunctions.HttpPost(ServicePerformanceCheckerURL, postRequest); if (resultString == null || resultString.Trim().Equals("")) { return(null); } WMSLayerInfoWithQoS wmsLayerInfoWithQoS = null; XDocument doc = XDocument.Parse(resultString); if (doc != null) { XElement rootElement = doc.Root; if (!rootElement.Name.LocalName.Equals("Envelope")) { return(null); } XElement responeBody = rootElement.Element(XName.Get("Body", soapenv_namespace)); if (responeBody != null) { XElement GetLayerPerforRankResponse = responeBody.Element(XName.Get(GetLayerPerforRankResponse_String, CISCChecker_namespace)); if (GetLayerPerforRankResponse != null) { XElement LayerPerforRank = GetLayerPerforRankResponse.Element(LayerRankInfo_String); if (LayerPerforRank != null) { wmsLayerInfoWithQoS = new WMSLayerInfoWithQoS(); wmsLayerInfoWithQoS.serviceURL = LayerPerforRank.Attribute(URL_String).Value; wmsLayerInfoWithQoS.serviceType = LayerPerforRank.Attribute(ServiceType_String).Value; IEnumerable <XElement> rankinfoList = LayerPerforRank.Elements(Layer_String); if (rankinfoList != null) { List <WMSLayer> WMSLayersList = new List <WMSLayer>(); //wmsLayerInfoWithQoS.WMSLayersList = WMSLayersList; foreach (XElement rankInfo in rankinfoList) { WMSLayer wmsLayer = new WMSLayer(); wmsLayer.name = rankInfo.Attribute(LayerName_String).Value; wmsLayer.title = rankInfo.Attribute(LayerTitle_String).Value; string rankvalue = rankInfo.Attribute(RankValue_String).Value; string responseTime = rankInfo.Attribute(responseTime_String).Value; wmsLayer.rankValue = double.Parse(rankvalue); wmsLayer.responseTime = double.Parse(responseTime); WMSLayersList.Add(wmsLayer); } if (WMSLayersList.Count > 0) { wmsLayerInfoWithQoS.WMSLayersList = WMSLayersList; } } } } else { return(null); } } } else { return(null); } return(wmsLayerInfoWithQoS); }