protected override string SendRequest(IUserData userData, string axlRequest) { if (_dataset == null) { return(""); } string server = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "server"); string service = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "service"); IServiceRequestContext context = (userData != null) ? userData.GetUserData("IServiceRequestContext") as IServiceRequestContext : null; string user = ConfigTextStream.ExtractValue(_dataset.ConnectionString, "user"); string pwd = Identity.HashPassword(ConfigTextStream.ExtractValue(_dataset.ConnectionString, "pwd")); if ((user == "#" || user == "$") && context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null) { string roles = String.Empty; if (user == "#" && context.ServiceRequest.Identity.UserRoles != null) { foreach (string role in context.ServiceRequest.Identity.UserRoles) { if (String.IsNullOrEmpty(role)) { continue; } roles += "|" + role; } } user = context.ServiceRequest.Identity.UserName + roles; pwd = context.ServiceRequest.Identity.HashedPassword; } MapServerConnection conn = new MapServerConnection(server); string resp = conn.Send(service, axlRequest, "BB294D9C-A184-4129-9555-398AA70284BC", user, pwd); try { return(conn.Send(service, axlRequest, "BB294D9C-A184-4129-9555-398AA70284BC", user, pwd)); } catch (Exception ex) { MapServerClass.ErrorLog(context, "Query", server, service, ex); return(String.Empty); } }
private void Run(object args) { try { _connector.Send(_service, args.ToString(), "ED770739-12FA-40d7-8EF9-38FE9299564A", _user, _pwd); } catch (Exception ex) { _exceptions.Append(ex.Message + "\n"); } }
private void FormAddServiceCollection_Load(object sender, EventArgs e) { MapServerConnection service = new MapServerConnection(ConfigTextStream.ExtractValue(_connectionString, "server")); string axl = service.Send("catalog", "<GETCLIENTSERVICES/>", "BB294D9C-A184-4129-9555-398AA70284BC", ConfigTextStream.ExtractValue(_connectionString, "user"), Identity.HashPassword(ConfigTextStream.ExtractValue(_connectionString, "pwd"))); if (axl == "") { return; } XmlDocument doc = new XmlDocument(); doc.LoadXml(axl); foreach (XmlNode mapService in doc.SelectNodes("//SERVICE[@name]")) { MapServiceType type = MapServiceType.MXL; if (mapService.Attributes["servicetype"] != null) { switch (mapService.Attributes["servicetype"].Value.ToLower()) { case "mxl": type = MapServiceType.MXL; break; case "svc": type = MapServiceType.SVC; break; default: continue; } } lstAvailServices.Items.Add( new ListViewItem(mapService.Attributes["name"].Value, (type == MapServiceType.MXL) ? 0 : 1)); } }
public bool MapRequest(gView.Framework.Carto.IDisplay display) { if (_dataset == null) { return(false); } if (!_dataset._opened) { _dataset.Open(); } IServiceRequestContext context = display.Map as IServiceRequestContext; try { ISpatialReference sRef = (display.SpatialReference != null) ? display.SpatialReference.Clone() as ISpatialReference : null; StringBuilder sb = new StringBuilder(); sb.Append("<?xml version='1.0' encoding='utf-8'?>"); sb.Append("<ARCXML version='1.1'>"); sb.Append("<REQUEST>"); sb.Append("<GET_IMAGE>"); sb.Append("<PROPERTIES>"); sb.Append("<ENVELOPE minx='" + display.Envelope.minx.ToString() + "' miny='" + display.Envelope.miny.ToString() + "' maxx='" + display.Envelope.maxx.ToString() + "' maxy='" + display.Envelope.maxy.ToString() + "' />"); sb.Append("<IMAGESIZE width='" + display.iWidth + "' height='" + display.iHeight + "' />"); sb.Append("<BACKGROUND color='255,255,255' transcolor='255,255,255' />"); //if (display.SpatialReference != null && !display.SpatialReference.Equals(_sRef)) //{ // string map_param = gView.Framework.Geometry.SpatialReference.ToProj4(display.SpatialReference); // sb.Append("<SPATIALREFERENCE name='" + display.SpatialReference.Name + "' param='" + map_param + "' />"); //} if (sRef != null) { string map_param = gView.Framework.Geometry.SpatialReference.ToProj4(display.SpatialReference); sb.Append("<SPATIALREFERENCE name='" + display.SpatialReference.Name + "' param='" + map_param + "' />"); string wkt = gView.Framework.Geometry.SpatialReference.ToESRIWKT(sRef); string geotranwkt = gView.Framework.Geometry.SpatialReference.ToESRIGeotransWKT(sRef); if (wkt != null) { wkt = wkt.Replace("\"", """); geotranwkt = geotranwkt.Replace("\"", """); if (!String.IsNullOrEmpty(geotranwkt)) { sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />"); sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" datumtransformstring=\"" + geotranwkt + "\" />"); } else { sb.Append("<FEATURECOORDSYS string=\"" + wkt + "\" />"); sb.Append("<FILTERCOORDSYS string=\"" + wkt + "\" />"); } } } sb.Append("<LAYERLIST>"); foreach (IWebServiceTheme theme in Themes) { sb.Append("<LAYERDEF id='" + theme.LayerID + "' visible='" + (theme.Visible && !theme.Locked).ToString() + "' />"); } sb.Append("</LAYERLIST>"); sb.Append("</PROPERTIES>"); sb.Append("</GET_IMAGE>"); sb.Append("</REQUEST>"); sb.Append("</ARCXML>"); string user = ConfigTextStream.ExtractValue(_dataset._connection, "user"); string pwd = Identity.HashPassword(ConfigTextStream.ExtractValue(_dataset._connection, "pwd")); if ((user == "#" || user == "$") && context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null) { string roles = String.Empty; if (user == "#" && context.ServiceRequest.Identity.UserRoles != null) { foreach (string role in context.ServiceRequest.Identity.UserRoles) { if (String.IsNullOrEmpty(role)) { continue; } roles += "|" + role; } } user = context.ServiceRequest.Identity.UserName + roles; pwd = context.ServiceRequest.Identity.HashedPassword; } #if (DEBUG) //Logger.LogDebug("Start gView Mapserver Request"); #endif MapServerConnection service = new MapServerConnection(ConfigTextStream.ExtractValue(_dataset._connection, "server")); string resp = service.Send(_name, sb.ToString(), "BB294D9C-A184-4129-9555-398AA70284BC", user, pwd); #if (DEBUG) //Logger.LogDebug("gView Mapserver Request Finished"); #endif XmlDocument doc = new XmlDocument(); doc.LoadXml(resp); System.Drawing.Bitmap bm = null; XmlNode output = doc.SelectSingleNode("//OUTPUT[@file]"); if (_image != null) { _image.Dispose(); _image = null; } try { System.IO.FileInfo fi = new System.IO.FileInfo(output.Attributes["file"].Value); if (fi.Exists) { bm = System.Drawing.Bitmap.FromFile(fi.FullName) as System.Drawing.Bitmap; } } catch { } if (bm == null) { bm = WebFunctions.DownloadImage(output); } if (bm != null) { _image = new GeorefBitmap(bm); _image.SpatialReference = display.SpatialReference; _image.Envelope = display.Envelope; if (AfterMapRequest != null) { AfterMapRequest(this, display, _image); } } return(_image != null); } catch (Exception ex) { MapServerClass.ErrorLog(context, "MapRequest", ConfigTextStream.ExtractValue(_dataset._connection, "server"), _name, ex); return(false); } }
public bool Open() { try { _opened = true; _themes.Clear(); MapServerConnection server = new MapServerConnection(ConfigTextStream.ExtractValue(_connection, "server")); string axl = "<ARCXML version=\"1.1\"><REQUEST><GET_SERVICE_INFO fields=\"true\" envelope=\"true\" renderer=\"false\" extensions=\"false\" gv_meta=\"true\" /></REQUEST></ARCXML>"; axl = server.Send(_name, axl, "BB294D9C-A184-4129-9555-398AA70284BC", ConfigTextStream.ExtractValue(_connection, "user"), ConfigTextStream.ExtractValue(_connection, "pwd")); XmlDocument doc = new XmlDocument(); doc.LoadXml(axl); if (_class == null) { _class = new MapServerClass(this); } double dpi = 96.0; XmlNode screen = doc.SelectSingleNode("//ENVIRONMENT/SCREEN"); if (screen != null) { if (screen.Attributes["dpi"] != null) { dpi = Convert.ToDouble(screen.Attributes["dpi"].Value.Replace(".", ",")); } } double dpm = (dpi / 0.0254); XmlNode spatialReference = doc.SelectSingleNode("//PROPERTIES/SPATIALREFERENCE"); if (spatialReference != null) { if (spatialReference.Attributes["param"] != null) { SpatialReference sRef = new SpatialReference(); gView.Framework.Geometry.SpatialReference.FromProj4(sRef, spatialReference.Attributes["param"].Value); if (spatialReference.Attributes["name"] != null) { sRef.Name = spatialReference.Attributes["name"].Value; } _class.SpatialReference = sRef; } } else { XmlNode FeatureCoordSysNode = doc.SelectSingleNode("ARCXML/RESPONSE/SERVICEINFO/PROPERTIES/FEATURECOORDSYS"); if (FeatureCoordSysNode != null) { if (FeatureCoordSysNode.Attributes["id"] != null) { _class.SpatialReference = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + FeatureCoordSysNode.Attributes["id"].Value); } else if (FeatureCoordSysNode.Attributes["string"] != null) { _class.SpatialReference = gView.Framework.Geometry.SpatialReference.FromWKT(FeatureCoordSysNode.Attributes["string"].Value); } // TODO: Geogr. Datum aus "datumtransformid" und "datumtransformstring" //if (_sRef != null && FeatureCoordSysNode.Attributes["datumtransformstring"] != null) //{ //} } } foreach (XmlNode envelopeNode in doc.SelectNodes("//ENVELOPE")) { if (_envelope == null) { _envelope = (new Envelope(envelopeNode)).MakeValid(); } else { _envelope.Union((new Envelope(envelopeNode)).MakeValid()); } } foreach (XmlNode layerNode in doc.SelectNodes("//LAYERINFO[@id]")) { bool visible = true; ISpatialReference sRef = _class.SpatialReference; /* * spatialReference = doc.SelectSingleNode("//PROPERTIES/SPATIALREFERENCE"); * if (spatialReference != null) * { * if (spatialReference.Attributes["param"] != null) * { * sRef = new SpatialReference(); * gView.Framework.Geometry.SpatialReference.FromProj4(sRef, spatialReference.Attributes["param"].Value); * * if (spatialReference.Attributes["name"] != null) * ((SpatialReference)sRef).Name = spatialReference.Attributes["name"].Value; * } * } * else * { * XmlNode FeatureCoordSysNode = doc.SelectSingleNode("ARCXML/RESPONSE/SERVICEINFO/PROPERTIES/FEATURECOORDSYS"); * if (FeatureCoordSysNode != null) * { * if (FeatureCoordSysNode.Attributes["id"] != null) * { * sRef = gView.Framework.Geometry.SpatialReference.FromID("epsg:" + FeatureCoordSysNode.Attributes["id"].Value); * } * else if (FeatureCoordSysNode.Attributes["string"] != null) * { * sRef = gView.Framework.Geometry.SpatialReference.FromWKT(FeatureCoordSysNode.Attributes["string"].Value); * } * * // TODO: Geogr. Datum aus "datumtransformid" und "datumtransformstring" * //if (_sRef != null && FeatureCoordSysNode.Attributes["datumtransformstring"] != null) * //{ * * //} * } * } */ if (layerNode.Attributes["visible"] != null) { bool.TryParse(layerNode.Attributes["visible"].Value, out visible); } IClass themeClass = null; IWebServiceTheme theme = null; if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "featureclass") { themeClass = new MapThemeFeatureClass(this, layerNode.Attributes["id"].Value); ((MapThemeFeatureClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value; ((MapThemeFeatureClass)themeClass).fieldsFromAXL = layerNode.InnerXml; ((MapThemeFeatureClass)themeClass).SpatialReference = sRef; XmlNode FCLASS = layerNode.SelectSingleNode("FCLASS[@type]"); if (FCLASS != null) { ((MapThemeFeatureClass)themeClass).fClassTypeString = FCLASS.Attributes["type"].Value; } theme = LayerFactory.Create(themeClass, _class) as IWebServiceTheme; if (theme == null) { continue; } theme.Visible = visible; } else if (layerNode.Attributes["type"] != null && layerNode.Attributes["type"].Value == "image") { if (layerNode.SelectSingleNode("gv_meta/class/implements[@type='gView.Framework.Data.IPointIdentify']") != null) { themeClass = new MapThemeQueryableRasterClass(this, layerNode.Attributes["id"].Value); ((MapThemeQueryableRasterClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value; } else { themeClass = new MapThemeRasterClass(this, layerNode.Attributes["id"].Value); ((MapThemeRasterClass)themeClass).Name = layerNode.Attributes["name"] != null ? layerNode.Attributes["name"].Value : layerNode.Attributes["id"].Value; } theme = new WebServiceTheme( themeClass, themeClass.Name, layerNode.Attributes["id"].Value, visible, _class); } else { continue; } try { if (layerNode.Attributes["minscale"] != null) { theme.MinimumScale = Convert.ToDouble(layerNode.Attributes["minscale"].Value.Replace(".", ",")) * dpm; } if (layerNode.Attributes["maxscale"] != null) { theme.MaximumScale = Convert.ToDouble(layerNode.Attributes["maxscale"].Value.Replace(".", ",")) * dpm; } } catch { } _themes.Add(theme); } _state = DatasetState.opened; return(true); } catch (Exception ex) { _state = DatasetState.unknown; _class = null; return(false); } }