コード例 #1
0
        public void version_param_is_optional()
        {
            MockRepository  mocks = new MockRepository();
            IContextRequest req   = mocks.StrictMock <IContextRequest>();

            With.Mocks(mocks)
            .Expecting(() =>
            {
                Expect.Call(req.GetParam("VERSION")).Return(null);
                Expect.Call(req.GetParam("SERVICE")).Return("WMS");
                Expect.Call(req.Url).Return(new Uri(Desc.OnlineResource)).Repeat.AtLeastOnce();
                Expect.Call(req.Encode(Desc.OnlineResource)).Return(Desc.OnlineResource);
            })
            .Verify(() =>
            {
                IHandler handler      = new GetCapabilities(Desc);
                IHandlerResponse resp = handler.Handle(Map, req);
                Assert.That(resp, Is.Not.Null);
                Assert.IsInstanceOf <GetCapabilitiesResponse>(resp);
                Validate((GetCapabilitiesResponse)resp);
            });
        }
コード例 #2
0
ファイル: ServerCapabilities.cs プロジェクト: cugkgq/Project
        private static XmlNode GenerateCapabilityNode(Map map, XmlDocument capabilities, string publicWMSUrl, IContextRequest request)
        {
            string onlineResource;

            if (String.IsNullOrEmpty(publicWMSUrl))
            {
                string port = request.Url.IsDefaultPort ? "" : ":" + request.Url.Port;
                string s    = String.Format("http://{0}{1}{2}", request.Url.Host, port,
                                            request.Url.AbsolutePath);
                onlineResource = request.Encode(s);
            }
            else
            {
                onlineResource = publicWMSUrl;
            }

            XmlNode capabilityNode      = capabilities.CreateNode(XmlNodeType.Element, "Capability", WmsNamespaceUri);
            XmlNode requestNode         = capabilities.CreateNode(XmlNodeType.Element, "Request", WmsNamespaceUri);
            XmlNode getCapabilitiesNode = capabilities.CreateNode(XmlNodeType.Element, "GetCapabilities",
                                                                  WmsNamespaceUri);

            // Set format of supported capabilities mime types (only text/xml supported)
            getCapabilitiesNode.AppendChild(CreateElement("Format", "text/xml", capabilities, WmsNamespaceUri));
            getCapabilitiesNode.AppendChild(GenerateDCPTypeNode(capabilities, onlineResource));
            requestNode.AppendChild(getCapabilitiesNode);
            XmlNode getFeatureInfoNode = capabilities.CreateNode(XmlNodeType.Element, "GetFeatureInfo", WmsNamespaceUri);

            getFeatureInfoNode.AppendChild(CreateElement("Format", "text/plain", capabilities, WmsNamespaceUri));
            getFeatureInfoNode.AppendChild(CreateElement("Format", "text/json", capabilities, WmsNamespaceUri));
            getFeatureInfoNode.AppendChild(GenerateDCPTypeNode(capabilities, onlineResource));
            requestNode.AppendChild(getFeatureInfoNode);
            XmlNode getMapNode = capabilities.CreateNode(XmlNodeType.Element, "GetMap", WmsNamespaceUri);

            // Add supported fileformats. Return the ones that GDI+ supports
            foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders())
            {
                getMapNode.AppendChild(CreateElement("Format", encoder.MimeType, capabilities, WmsNamespaceUri));
            }

            getMapNode.AppendChild(GenerateDCPTypeNode(capabilities, onlineResource));

            requestNode.AppendChild(getMapNode);
            capabilityNode.AppendChild(requestNode);
            XmlElement exceptionNode = capabilities.CreateElement("Exception", WmsNamespaceUri);

            exceptionNode.AppendChild(CreateElement("Format", "text/xml", capabilities, WmsNamespaceUri));
            capabilityNode.AppendChild(exceptionNode); // Add supported exception types

            // Build layerlist
            XmlNode layerRootNode = capabilities.CreateNode(XmlNodeType.Element, "Layer", WmsNamespaceUri);

            layerRootNode.AppendChild(CreateElement("Title", "SharpMap", capabilities, WmsNamespaceUri));
            layerRootNode.AppendChild(CreateElement("CRS", "EPSG:" + map.Layers[0].SRID, capabilities, WmsNamespaceUri)); //TODO
            layerRootNode.AppendChild(GenerateBoundingBoxElement(map.GetExtents(), map.Layers[0].SRID, capabilities));

            XmlElement geoBox = capabilities.CreateElement("EX_GeographicBoundingBox", WmsNamespaceUri);
            // Using default values here. TODO: this should be changed when projection library is complete
            const string minX = "-180";
            const string minY = "-90";
            const string maxX = "180";
            const string maxY = "90";

            geoBox.AppendChild(CreateElement("westBoundLongitude", minX, capabilities, WmsNamespaceUri));
            geoBox.AppendChild(CreateElement("southBoundLatitude", minY, capabilities, WmsNamespaceUri));
            geoBox.AppendChild(CreateElement("eastBoundLongitude", maxX, capabilities, WmsNamespaceUri));
            geoBox.AppendChild(CreateElement("northBoundLatitude", maxY, capabilities, WmsNamespaceUri));

            // The above way to respresent the boundingbox is correct and replace the incorrect way below.
            // For downward compatibility I will keep the old code.
            geoBox.Attributes.Append(CreateAttribute("minx", minX, capabilities));
            geoBox.Attributes.Append(CreateAttribute("miny", minY, capabilities));
            geoBox.Attributes.Append(CreateAttribute("maxx", maxX, capabilities));
            geoBox.Attributes.Append(CreateAttribute("maxy", maxY, capabilities));
            layerRootNode.AppendChild(geoBox);

            foreach (ILayer layer in map.Layers)
            {
                XmlNode wmsLayerNode = GetWmsLayerNode(layer, capabilities);
                layerRootNode.AppendChild(wmsLayerNode);
            }

            capabilityNode.AppendChild(layerRootNode);
            return(capabilityNode);
        }
コード例 #3
0
        private static XmlNode GenerateCapabilityNode(Map map, XmlDocument capabilities, string publicWMSUrl, IContextRequest request)
        {
            string OnlineResource = "";

            if (String.IsNullOrEmpty(publicWMSUrl))
            {
                string port = request.Url.IsDefaultPort ? "" : ":" + request.Url.Port;
                string s = String.Format("http://{0}{1}{2}", request.Url.Host, port,
                    request.Url.AbsolutePath);
                OnlineResource = request.Encode(s);
            }
            else OnlineResource = publicWMSUrl;

            XmlNode CapabilityNode = capabilities.CreateNode(XmlNodeType.Element, "Capability", wmsNamespaceURI);
            XmlNode RequestNode = capabilities.CreateNode(XmlNodeType.Element, "Request", wmsNamespaceURI);
            XmlNode GetCapabilitiesNode = capabilities.CreateNode(XmlNodeType.Element, "GetCapabilities",
                                                                  wmsNamespaceURI);
            //Set format of supported capabilities mime types (only text/xml supported)
            GetCapabilitiesNode.AppendChild(CreateElement("Format", "text/xml", capabilities, false, wmsNamespaceURI));
            GetCapabilitiesNode.AppendChild(GenerateDCPTypeNode(capabilities, OnlineResource));
            RequestNode.AppendChild(GetCapabilitiesNode);
            XmlNode GetFeatureInfoNode = capabilities.CreateNode(XmlNodeType.Element, "GetFeatureInfo", wmsNamespaceURI);
            GetFeatureInfoNode.AppendChild(CreateElement("Format", "text/plain", capabilities, false, wmsNamespaceURI));
            GetFeatureInfoNode.AppendChild(CreateElement("Format", "text/json", capabilities, false, wmsNamespaceURI));
            GetFeatureInfoNode.AppendChild(GenerateDCPTypeNode(capabilities, OnlineResource));
            RequestNode.AppendChild(GetFeatureInfoNode);
            XmlNode GetMapNode = capabilities.CreateNode(XmlNodeType.Element, "GetMap", wmsNamespaceURI);
            //Add supported fileformats. Return the ones that GDI+ supports
            foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders())
                GetMapNode.AppendChild(CreateElement("Format", encoder.MimeType, capabilities, false, wmsNamespaceURI));

            GetMapNode.AppendChild(GenerateDCPTypeNode(capabilities, OnlineResource));

            RequestNode.AppendChild(GetMapNode);
            CapabilityNode.AppendChild(RequestNode);
            XmlElement exceptionNode = capabilities.CreateElement("Exception", wmsNamespaceURI);
            exceptionNode.AppendChild(CreateElement("Format", "text/xml", capabilities, false, wmsNamespaceURI));
            CapabilityNode.AppendChild(exceptionNode); //Add supported exception types

            //Build layerlist

            XmlNode LayerRootNode = capabilities.CreateNode(XmlNodeType.Element, "Layer", wmsNamespaceURI);
            LayerRootNode.AppendChild(CreateElement("Title", "SharpMap", capabilities, false, wmsNamespaceURI));
            LayerRootNode.AppendChild(CreateElement("CRS", "EPSG:" + map.Layers[0].SRID, capabilities, false,
                                                    wmsNamespaceURI)); //TODO
            LayerRootNode.AppendChild(GenerateBoundingBoxElement(map.GetExtents(), map.Layers[0].SRID, capabilities));
                        
            XmlElement geoBox = capabilities.CreateElement("EX_GeographicBoundingBox", wmsNamespaceURI);

            //Using default values here. This should be changed when projection library is complete
            string minX = "-180";
            string minY = "-90";
            string maxX = "180";
            string maxY = "90";

            geoBox.AppendChild(CreateElement("westBoundLongitude", minX, capabilities, false, wmsNamespaceURI));
            geoBox.AppendChild(CreateElement("southBoundLatitude", minY, capabilities, false, wmsNamespaceURI));
            geoBox.AppendChild(CreateElement("eastBoundLongitude", maxX, capabilities, false, wmsNamespaceURI));
            geoBox.AppendChild(CreateElement("northBoundLatitude", maxY, capabilities, false, wmsNamespaceURI));

            //The above way to respresent the boundingbox is correct and replace the incorrect way below. 
            //For downward compatibility I will keep the old code.
            geoBox.Attributes.Append(CreateAttribute("minx", minX, capabilities));
            geoBox.Attributes.Append(CreateAttribute("miny", minY, capabilities));
            geoBox.Attributes.Append(CreateAttribute("maxx", maxX, capabilities));
            geoBox.Attributes.Append(CreateAttribute("maxy", maxY, capabilities));
            LayerRootNode.AppendChild(geoBox);

            foreach (ILayer layer in map.Layers)
                LayerRootNode.AppendChild(GetWmsLayerNode(layer, capabilities));

            CapabilityNode.AppendChild(LayerRootNode);

            return CapabilityNode;
        }