Ejemplo n.º 1
0
        public void DecodeBase64Test()
        {
            double delta = 0.0001;

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

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

            Assert.IsNotNull(location);
            Assert.IsInstanceOf <GridLocation>(location);
            var gridLocation = (location as GridLocation);

            // check coordinate.
            Assert.IsNotNull(gridLocation.LowerLeft);
            Assert.AreEqual(6.12555, gridLocation.LowerLeft.Longitude, delta);
            Assert.AreEqual(49.60586, gridLocation.LowerLeft.Latitude, delta);
            Assert.IsNotNull(gridLocation.UpperRight);
            Assert.AreEqual(6.126291, gridLocation.UpperRight.Longitude, delta);
            Assert.AreEqual(49.606170, gridLocation.UpperRight.Latitude, delta);
            Assert.AreEqual(5, gridLocation.Columns, delta);
            Assert.AreEqual(3, gridLocation.Rows, delta);
        }
Ejemplo n.º 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));
        }