Пример #1
0
        /// <summary>
        /// Decodes the given string.
        /// </summary>
        public override ILocation Decode(string encoded)
        {
            if (encoded == null)
            {
                throw new ArgumentNullException("encoded");
            }

            // the data in a binary decoder should be a base64 string.
            byte[] binaryData = null;
            try
            {
                binaryData = Convert.FromBase64String(encoded);
            }
            catch (FormatException ex)
            { // not a base64 string.
                throw ex;
            }

            if (CircleLocationCodec.CanDecode(binaryData))
            {
                return(CircleLocationCodec.Decode(binaryData));
            }
            if (ClosedLineLocationCodec.CanDecode(binaryData))
            {
                return(ClosedLineLocationCodec.Decode(binaryData));
            }
            if (GeoCoordinateLocationCodec.CanDecode(binaryData))
            {
                return(GeoCoordinateLocationCodec.Decode(binaryData));
            }
            if (GridLocationCodec.CanDecode(binaryData))
            {
                return(GridLocationCodec.Decode(binaryData));
            }
            if (LineLocationCodec.CanDecode(binaryData))
            {
                return(LineLocationCodec.Decode(binaryData));
            }
            if (PointAlongLineLocationCodec.CanDecode(binaryData))
            {
                return(PointAlongLineLocationCodec.Decode(binaryData));
            }
            if (PoiWithAccessPointLocationCodec.CanDecode(binaryData))
            {
                return(PoiWithAccessPointLocationCodec.Decode(binaryData));
            }
            if (PolygonLocationCodec.CanDecode(binaryData))
            {
                return(PolygonLocationCodec.Decode(binaryData));
            }
            if (RectangleLocationCodec.CanDecode(binaryData))
            {
                return(RectangleLocationCodec.Decode(binaryData));
            }
            throw new ArgumentException(string.Format("Cannot decode string, no codec found: {0}", encoded));
        }
Пример #2
0
        public void DecodeBase64Test()
        {
            double delta = 0.0001;

            // define a base64 string.
            var stringData = Convert.FromBase64String("QwRbICNGeQFAAH0=");

            // decode.
            Assert.IsTrue(RectangleLocationCodec.CanDecode(stringData));
            var location = RectangleLocationCodec.Decode(stringData);

            Assert.IsNotNull(location);
            Assert.IsInstanceOf <RectangleLocation>(location);
            var rectangleLocation = (location as RectangleLocation);

            // check coordinate.
            Assert.IsNotNull(rectangleLocation);
            Assert.IsNotNull(rectangleLocation.LowerLeft);
            Assert.AreEqual(6.12555, rectangleLocation.LowerLeft.Longitude, delta);  // 6.12555°
            Assert.AreEqual(49.60586, rectangleLocation.LowerLeft.Latitude, delta);  // 49.60586°
            Assert.IsNotNull(rectangleLocation.UpperRight);
            Assert.AreEqual(6.12875, rectangleLocation.UpperRight.Longitude, delta); // 6.12875°
            Assert.AreEqual(49.60711, rectangleLocation.UpperRight.Latitude, delta); // 49.60711°
        }