/// <summary>
        /// Converts this object to a WaterSupplyPoint object.
        /// </summary>
        /// <returns>A WaterSupplyPoint object.</returns>
        public WaterSupplyPoint ToWaterSupplyPoint()
        {
            var wsp = new WaterSupplyPoint
            {
                Connections = Connections,
                Coordinate  = new Coordinate(Latitude, Longitude),
                Distance    = (int)Math.Round(Distance, 0),
                Information = GetInformation(),
                Location    = WebUtility.HtmlDecode(Address),
                Size        = (int)Math.Round(NominalDiameter, 0),
            };

            return(wsp);
        }
Example #2
0
        /// <summary>
        /// Deserializes the stream using a custom structure.
        /// </summary>
        /// <param name="stream">The stream containing the watter supply point data.</param>
        /// <returns>A dictionary containing the water supply points and their corresponding distances to the origin.</returns>
        private static List <WaterSupplyPoint> DeserializeCustomData(Stream stream)
        {
            var waterSupplyPoints = new List <WaterSupplyPoint>();

            // Read data using XPath
            const string namespaceURI = "";
            var          nav          = new XPathDocument(stream).CreateNavigator();

            while (nav.MoveToFollowing("WaterSupplyPoint", namespaceURI))
            {
                int distance = 0;
                var point    = new WaterSupplyPoint();

                // Coordinate
                nav.MoveToFollowing("Latitude", namespaceURI);
                double lat = nav.ValueAsDouble;
                nav.MoveToFollowing("Longitude", namespaceURI);
                double lng = nav.ValueAsDouble;
                point.Coordinate = new Coordinate(lat, lng);

                // Kind
                bool found = nav.MoveToFollowing("Kind", namespaceURI);
                if (found)
                {
                    switch (nav.Value)
                    {
                    case "pillarhydrant":
                        point.Kind = WaterSupplyPointKind.PillarHydrant;
                        break;

                    case "undergroundhydrant":
                        point.Kind = WaterSupplyPointKind.UndergroundHydrant;
                        break;

                    case "fireextinguishingpool":
                        point.Kind = WaterSupplyPointKind.FireExtinguishingPool;
                        break;

                    case "suctionpoint":
                        point.Kind = WaterSupplyPointKind.SuctionPoint;
                        break;

                    default:
                        point.Kind = WaterSupplyPointKind.Undefined;
                        break;
                    }
                }

                found = nav.MoveToFollowing("Location", namespaceURI);
                if (found)
                {
                    point.Location = nav.Value;
                }

                found = nav.MoveToFollowing("Information", namespaceURI);
                if (found)
                {
                    point.Information = nav.Value;
                }

                found = nav.MoveToFollowing("Size", namespaceURI);
                if (found && !string.IsNullOrWhiteSpace(nav.Value))
                {
                    point.Size = nav.ValueAsInt;
                }

                found = nav.MoveToFollowing("Connections", namespaceURI);
                if (found)
                {
                    point.Connections = nav.Value;
                }

                found = nav.MoveToFollowing("Distance", namespaceURI);
                if (found && !string.IsNullOrWhiteSpace(nav.Value))
                {
                    distance = nav.ValueAsInt;
                }

                point.Distance = distance;

                waterSupplyPoints.Add(point);
            }

            return(waterSupplyPoints);
        }