示例#1
0
        public void DecodeBase64Test()
        {
            double delta = 0.0001;

            // define a base64 string we are sure is a line location.
            var stringData = Convert.FromBase64String("EwRbHSNGdQFiAA//XADz/64AJP9b/7U=");

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

            Assert.IsNotNull(location);
            Assert.IsInstanceOf <PolygonLocation>(location);
            var polygonLocation = (location as PolygonLocation);

            Assert.IsNotNull(polygonLocation);
            Assert.IsNotNull(polygonLocation.Coordinates);

            Assert.AreEqual(6.12549, polygonLocation.Coordinates[0].Longitude, delta);
            Assert.AreEqual(49.60577, polygonLocation.Coordinates[0].Latitude, delta);

            Assert.AreEqual(6.12903, polygonLocation.Coordinates[1].Longitude, delta);
            Assert.AreEqual(49.60592, polygonLocation.Coordinates[1].Latitude, delta);

            Assert.AreEqual(6.12739, polygonLocation.Coordinates[2].Longitude, delta);
            Assert.AreEqual(49.60835, polygonLocation.Coordinates[2].Latitude, delta);

            Assert.AreEqual(6.12658, polygonLocation.Coordinates[3].Longitude, delta);
            Assert.AreEqual(49.60871, polygonLocation.Coordinates[3].Latitude, delta);

            Assert.AreEqual(6.12493, polygonLocation.Coordinates[4].Longitude, delta);
            Assert.AreEqual(49.60796, polygonLocation.Coordinates[4].Latitude, delta);
        }
示例#2
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));
        }