Exemplo n.º 1
0
        public Capability(XElement node, string @namespace)
        {
            var element = node.Element(XName.Get("Request", @namespace));
            if (element == null)
                throw WmsParsingException.ElementNotFound("Request");
            Request = new Request(element, @namespace);

            foreach (var el in node.Elements())
            {
                if (el.Name.LocalName == "Request" || el.Name.LocalName == "Layer")
                    continue;

                if (el.Name.LocalName == "Exception")
                {
                    Exception.Add(el.Value);
                    continue;
                }

                ExtendedCapabilities.Add(el.Name, el);
            }

            if (Exception.Count == 0)
                throw WmsParsingException.ElementNotFound("Exception");

            bool baseNodeCreated = false;
            foreach (var layerNode in node.Elements(XName.Get("Layer", @namespace)))
            {
                var layer = new Layer(layerNode, @namespace);
                if (_layerField == null)
                {
                    _layerField = layer;
                }

                else if (_layerField != null && !baseNodeCreated)
                {
                    var tmpLayer = new Layer();
                    tmpLayer.Title = "Root Layer";
                    tmpLayer.ChildLayers.Add(Layer);
                    tmpLayer.ChildLayers.Add(layer);
                    Layer = tmpLayer;
                    baseNodeCreated = true;
                }
                else
                {
                    _layerField.ChildLayers.Add(layer);
                }
            }
        }
Exemplo n.º 2
0
        public override void ReadXml(XmlReader reader)
        {
            if (CheckEmptyNode(reader, "Capability", string.Empty, true))
                throw WmsParsingException.ElementNotFound("Capability");

            bool baseLayerCreated = false;

            while (!reader.EOF)
            {
                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                        case "Request":
                            _requestField = new Request();
                            _requestField.ReadXml(reader.ReadSubtree());
                            break;

                        case "Exception":
                            if (_exceptionField == null)
                                _exceptionField = new List<string>();
                            var subReader = reader.ReadSubtree();
                            while (!subReader.EOF)
                            {
                                reader.ReadStartElement("Format");
                                var format = reader.ReadContentAsString();
                                reader.ReadEndElement();
                                _exceptionField.Add(format);
                            }
                            break;
                        case "Layer":
                            if (_layerField == null)
                            {
                                _layerField = new Layer();
                                _layerField.ReadXml(reader);
                            }
                            else
                            {
                                if (!baseLayerCreated)
                                {
                                    var tmp = _layerField;
                                    _layerField = new Layer();
                                    _layerField.Name = _layerField.Title = "Created base layer";
                                    _layerField.ChildLayers.Add(tmp);
                                    baseLayerCreated = true;
                                }
                                var layer = new Layer();
                                layer.ReadXml(reader);
                                _layerField.ChildLayers.Add(layer);
                            }
                            break;

                        default:
                            ExtendedCapabilities.Add(XName.Get(reader.LocalName, reader.NamespaceURI), XNode.ReadFrom(reader));
                            break;
                    }
                }
                else
                {
                    reader.Read();
                }
            }
        }