public Task <bool> SetConnectionString(string value) { _class = null; _wfsDataset = null; switch (ConfigTextStream.ExtractValue(value, "service").ToUpper()) { case "WMS": _type = SERVICE_TYPE.WMS; _connection = ConfigTextStream.ExtractValue(value, "wms"); _class = new WMSClass(this); break; case "WFS": _type = SERVICE_TYPE.WFS; _wfsDataset = new WFSDataset(this, ConfigTextStream.ExtractValue(value, "wfs")); break; case "WMS_WFS": _type = SERVICE_TYPE.WMS_WFS; _connection = ConfigTextStream.ExtractValue(value, "wms"); _class = new WMSClass(this); _wfsDataset = new WFSDataset(this, ConfigTextStream.ExtractValue(value, "wfs")); break; default: return(Task.FromResult(false)); } _connectionString = value; return(Task.FromResult(true)); }
async public Task <bool> Open(gView.MapServer.IServiceRequestContext context) { string url = String.Empty; try { _isOpened = true; bool ret = true; if (_wfsDataset != null) { ret = _wfsDataset.Open(); } if (_class != null) { string param = "REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS"; url = Append2Url(_connection, param); string response = WebFunctions.HttpSendRequest(url, "GET", null, ConfigTextStream.ExtractValue(_connectionString, "usr"), ConfigTextStream.ExtractValue(_connectionString, "pwd")); response = RemoveDOCTYPE(response); _class.Init(response, _wfsDataset); } _state = (ret) ? DatasetState.opened : DatasetState.unknown; return(ret); } catch (Exception ex) { await WMSClass.ErrorLogAsync(context, "GetCapabilities", url, ex); _class = null; _wfsDataset = null; return(false); } }
internal void Init(string CapabilitiesString, WFSDataset wfsDataset) { try { _themes = new List <IWebServiceTheme>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(CapabilitiesString); XmlNode CapabilitiesNode = doc.SelectSingleNode("WMT_MS_Capabilities/Capability"); _getCapabilities = new GetCapabilities(CapabilitiesNode.SelectSingleNode("Request/GetCapabilities")); _getMap = new GetMap(CapabilitiesNode.SelectSingleNode("Request/GetMap")); _getFeatureInfo = new GetFeatureInfo(CapabilitiesNode.SelectSingleNode("Request/GetFeatureInfo")); _describeLayer = new DescribeLayer(CapabilitiesNode.SelectSingleNode("Request/DescribeLayer")); _getLegendGraphic = new GetLegendGraphic(CapabilitiesNode.SelectSingleNode("Request/GetLegendGraphic")); _getStyles = new GetStyles(CapabilitiesNode.SelectSingleNode("Request/GetStyles")); _exceptions = new WMSExceptions(CapabilitiesNode.SelectSingleNode("Exception")); _userDefinedSymbolization = new UserDefinedSymbolization(CapabilitiesNode.SelectSingleNode("UserDefinedSymbolization")); XmlNode service = CapabilitiesNode.SelectSingleNode("Layer"); XmlNode title = service.SelectSingleNode("Title"); if (title != null) { _name = title.InnerText; } _srs = new SRS(service); this.SRSCode = _srs.Srs[_srs.SRSIndex]; foreach (XmlNode layer in service.SelectNodes("Layer")) { string name = "", Title = ""; XmlNode nameNode = layer.SelectSingleNode("Name"); XmlNode titleNode = layer.SelectSingleNode("Title"); if (nameNode == null) { continue; } name = Title = nameNode.InnerText; if (titleNode != null) { Title = titleNode.InnerText; } XmlNodeList styles = layer.SelectNodes("Style"); WFSFeatureClass wfsFc = null; if (wfsDataset != null) { IDatasetElement wfsElement = wfsDataset[name]; if (wfsElement != null && wfsElement.Class is WFSFeatureClass) { wfsFc = wfsElement.Class as WFSFeatureClass; } } if (styles.Count == 0) { IClass wClass = null; if (wfsFc != null) { wClass = wfsFc; } else if (layer.Attributes["queryable"] != null && layer.Attributes["queryable"].Value == "1") { wClass = new WMSQueryableThemeClass(_dataset, name, String.Empty, layer, _getFeatureInfo, _srs, _exceptions); } else { wClass = new WMSThemeClass(_dataset, name, String.Empty, layer); } IWebServiceTheme theme; if (wClass is WFSFeatureClass) { theme = new WebServiceTheme2( wClass, Title, name, true, this); } else { theme = new WebServiceTheme( wClass, Title, name, true, this ); } _themes.Add(theme); } else { foreach (XmlNode style in styles) { string sName = "", sTitle = ""; XmlNode sNameNode = style.SelectSingleNode("Name"); XmlNode sTitleNode = style.SelectSingleNode("Title"); if (sNameNode == null) { continue; } sName = sTitle = sNameNode.InnerText; if (sTitleNode != null) { sTitle = sTitleNode.InnerText; } IClass wClass = null; if (wfsFc is WFSFeatureClass) { wClass = wfsFc; ((WFSFeatureClass)wClass).Style = sName; } else if (layer.Attributes["queryable"] != null && layer.Attributes["queryable"].Value == "1") { wClass = new WMSQueryableThemeClass(_dataset, name, sName, layer, _getFeatureInfo, _srs, _exceptions); } else { wClass = new WMSThemeClass(_dataset, name, sName, layer); } IWebServiceTheme theme; if (wClass is WFSFeatureClass) { theme = new WebServiceTheme2( wClass, Title + " (Style=" + sTitle + ")", name, true, this); } else { theme = new WebServiceTheme( wClass, Title + " (Style=" + sTitle + ")", name, true, this ); } _themes.Add(theme); } } } doc = null; } catch (Exception ex) { string errMsg = ex.Message; } }