/// <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)); }
public void DecodeBase64Test() { double delta = 0.0001; // define a base64 string. var stringData = Convert.FromBase64String("IwRbYyNGuw=="); // decode. Assert.IsTrue(GeoCoordinateLocationCodec.CanDecode(stringData)); var location = GeoCoordinateLocationCodec.Decode(stringData); Assert.IsNotNull(location); Assert.IsInstanceOf <GeoCoordinateLocation>(location); var geoCoordinate = (location as GeoCoordinateLocation); // check coordinate. Assert.IsNotNull(geoCoordinate.Coordinate); Assert.AreEqual(6.12699, geoCoordinate.Coordinate.Longitude, delta); // 6.12699° Assert.AreEqual(49.60728, geoCoordinate.Coordinate.Latitude, delta); // 49.60728° }