diff --git a/README.md b/README.md index 5906c6c..3792c67 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ PS> Install-Package gmaps-api-net This project attempts to provide all the features available in the Google Maps API. It is being developed in C# for the Microsoft .NET including .Net Framework v4.6.1+ and .Net Standard v1.3+. *gmaps-api-net* is a fully featured API client library, providing strongly typed access to the API. ## Notable Upcoming -* Trying to achieve a formal v1.0 release for 2018. This is basically on-track for first week of January. File any major issues quickly to get addressed before v1.0! +* Trying to achieve a formal v1.0 release. File any major issues quickly to get addressed before v1.0! * Planning a slight namespace/usage change for v2.0 release soon thereafter to support dependency injection and mocking away the library in your own testing apparatus. Intention here is to isolate away the library returning values to returning known values during your testing. See branch [feat/support-dependency-injection](https://github.com/ericnewton76/gmaps-api-net/tree/feat/support-dependency-injection) * In relation to above, we will begin removing our tests for specific values, and testing instead for schema changes that Google is pushing through. @@ -41,12 +41,12 @@ Google is now requiring a proper API key for accessing the service. Create a key Let's suppose we want to search an address and get more information about it. We can write: ```c# -//always need to use YOUR_API_KEY for requests. Do this in App_Start. -GoogleSigned.AssignAllServices(new GoogleSigned("YOUR_API_KEY")); +//always need to use YOUR_API_KEY for requests. +var GMaps = new Google.Maps.Services("YOUR_API_KEY"); var request = new GeocodingRequest(); request.Address = "1600 Pennsylvania Ave NW, Washington, DC 20500"; -var response = new GeocodingService().GetResponse(request); +var response = GMaps.GeocodingService.GetResponse(request); //The GeocodingService class submits the request to the API web service, and returns the //response strongly typed as a GeocodeResponse object which may contain zero, one or more results. @@ -71,11 +71,12 @@ else Static Maps API support allows you to get a valid url or a streamed bitmap which you can use: ```c# -//always need to use YOUR_API_KEY for requests. Do this in App_Start. -GoogleSigned.AssignAllServices(new GoogleSigned("YOUR_API_KEY")); +//always need to use YOUR_API_KEY for requests. +var GMaps = new Google.Maps.Services("YOUR_API_KEY"); + var map = new StaticMapRequest(); map.Center = new Location("1600 Pennsylvania Ave NW, Washington, DC 20500"); -map.Size = new System.Drawing.Size(400, 400); +map.Size = new GSize(400, 400); map.Zoom = 14; ``` @@ -112,33 +113,35 @@ this.imageControl.Image = img; ```c# //enterprise users to use your supplied information for requests. Do this in App_Start. -GoogleSigned.AssignAllServices(new GoogleSigned("gme-your-client-id", "your-signing-key", signType: GoogleSignedType.Business)); +var GMaps = new Google.Maps.Services(new GoogleSigned("gme-your-client-id", "your-signing-key")); // Then do as many requests as you like... var request = new GeocodingRequest(); //... -var response = GeocodingService.GetResponse(request); +var response = GMaps.GeocodingService.GetResponse(request); ``` ### Using a Google Maps API key ```c# //always need to use YOUR_API_KEY for requests. Do this in App_Start. -GoogleSigned.AssignAllServices(new GoogleSigned("your-api-key")); +var GMaps = new Google.Maps.Services("YOUR_API_KEY"); // Then do as many requests as you like... var request = new GeocodingRequest(); //... -var response = GeocodingService.GetResponse(request); +var response = GMaps.GeocodingService.GetResponse(request); ``` You can also use a particular key for a single request: ```c# -const GoogleSigned apikey = new GoogleSigned("special_api_key_here"); +var GMaps = new Google.Maps.Services("YOUR_API_KEY"); + +var GMapsSecretKey = GMaps.WithSigningService(new GoogleApiSigningService(new GoogleSigned("special_api_key_here")); var request = new GeocodingRequest(); //... -var service = new GeocodingService(request, apikey); +var service = GMapsSecretKey.GeocodingService.GetResponse(request); ``` ## Contact @@ -150,6 +153,7 @@ Questions, comments and/or suggestions are welcome! Please raise an [issue](http ## Contributors A big thank you to all of our [contributors](https://github.com/ericnewton76/gmaps-api-net/graphs/contributors) including: +- [Luis Farzati](https://github.com/luisfarzati) - [Eric Newton](https://github.com/ericnewton76) - [Sheepzez](https://github.com/Sheepzez) - [Mieliespoor](https://github.com/mieliespoor) diff --git a/src/ConsoleApp1/Program.cs b/src/ConsoleApp1/Program.cs index d8231a8..0ddc89f 100644 --- a/src/ConsoleApp1/Program.cs +++ b/src/ConsoleApp1/Program.cs @@ -6,6 +6,7 @@ using Google.Maps; using Google.Maps.Geocoding; +using Google.Maps.Common; namespace ConsoleApp1 { @@ -27,11 +28,11 @@ static void Main(string[] args) static void README_QuickStart_Sample1() { //always need to use YOUR_API_KEY for requests. Do this in App_Start. - GoogleSigned.AssignAllServices(new GoogleSigned("YOUR_API_KEY")); + var GMaps = new Google.Maps.Services("YOUR_API_KEY"); var request = new GeocodingRequest(); request.Address = "1600 Pennsylvania Ave NW, Washington, DC 20500"; - var response = new GeocodingService().GetResponse(request); + var response = GMaps.GeocodingService.GetResponse(request); //The GeocodingService class submits the request to the API web service, and returns the //response strongly typed as a GeocodeResponse object which may contain zero, one or more results. @@ -83,8 +84,7 @@ static void DoRequestsLoop() static void DoGeocodeRequest() { //always need to use YOUR_API_KEY for requests. Do this in App_Start. - //GoogleSigned.AssignAllServices(new GoogleSigned("YOUR_API_KEY")); - //commented out in the loop + var GMaps = new Google.Maps.Services("YOUR_API_KEY"); Console.WriteLine(); Console.WriteLine("Enter an address to geocode: "); @@ -92,7 +92,7 @@ static void DoGeocodeRequest() var request = new GeocodingRequest(); request.Address = geocodeAddress; - var response = new GeocodingService().GetResponse(request); + var response = GMaps.GeocodingService.GetResponse(request); //The GeocodingService class submits the request to the API web service, and returns the //response strongly typed as a GeocodeResponse object which may contain zero, one or more results. diff --git a/src/Google.Maps.Test/Direction/DirectionRequestTests.cs b/src/Google.Maps.Test/Direction/DirectionRequestTests.cs index 2a00310..29e3938 100644 --- a/src/Google.Maps.Test/Direction/DirectionRequestTests.cs +++ b/src/Google.Maps.Test/Direction/DirectionRequestTests.cs @@ -3,6 +3,7 @@ using System.Collections.Specialized; using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps.Direction { diff --git a/src/Google.Maps.Test/Direction/DirectionServiceTests.cs b/src/Google.Maps.Test/Direction/DirectionServiceTests.cs index 7b5501b..3670f06 100644 --- a/src/Google.Maps.Test/Direction/DirectionServiceTests.cs +++ b/src/Google.Maps.Test/Direction/DirectionServiceTests.cs @@ -21,7 +21,9 @@ using NUnit.Framework; -using Google.Maps.Shared; +using Google.Maps.ApiCore; +using Google.Maps.Common; +using Google.Maps.Internal; namespace Google.Maps.Direction { @@ -32,7 +34,14 @@ class DirectionServiceTests DirectionService CreateService() { - var svc = new DirectionService(TestingApiKey); + var svc = new DirectionService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri:null); + return svc; } diff --git a/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs b/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs index 11d4426..f16074f 100644 --- a/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs +++ b/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.DistanceMatrix { @@ -12,7 +14,14 @@ public class DistanceMatrixServiceTests DistanceMatrixService CreateService() { - var svc = new DistanceMatrixService(TestingApiKey); + var svc = new DistanceMatrixService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri: null + ); return svc; } diff --git a/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs b/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs index bca3330..19c038c 100644 --- a/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs +++ b/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs @@ -18,6 +18,8 @@ using System; using NUnit.Framework; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.Elevation { @@ -28,7 +30,15 @@ public class ElevationServiceTests ElevationService CreateService() { - var svc = new ElevationService(TestingApiKey); + var svc = new ElevationService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri:null + ); + return svc; } diff --git a/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs index f8b1e4f..b32b5fa 100644 --- a/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs +++ b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs @@ -21,7 +21,9 @@ using NUnit.Framework; -using Google.Maps.Shared; +using Google.Maps.Common; +using Google.Maps.ApiCore; +using Google.Maps.Internal; namespace Google.Maps.Geocoding { @@ -32,7 +34,14 @@ class GeocodingServiceTests GeocodingService CreateService() { - var svc = new GeocodingService(TestingApiKey); + var svc = new GeocodingService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri: null + ); return svc; } @@ -230,7 +239,7 @@ public void Utf8_Request_And_Response() Address = "AL. GRUNWALDZKA 141, Gdańsk, 80 - 264, POLAND" }; - var response = new GeocodingService().GetResponse(request); + var response = CreateService().GetResponse(request); if(response.Status == ServiceResponseStatus.OverQueryLimit) { diff --git a/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs b/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs index b512be9..e6eaca2 100644 --- a/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs +++ b/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs @@ -3,6 +3,7 @@ using NUnit.Framework; using Google.Maps.Geocoding; +using Google.Maps.Common; namespace Google.Maps { @@ -21,6 +22,15 @@ namespace Google.Maps [Category("External Integrations")] class GoogleMapsForBusinessTests { + GoogleSigned TestingApiKey; + Google.Maps.Services GMaps; + + [OneTimeSetUp] + public void OneTimeSetup() + { + TestingApiKey = GetRealSigningInstance(); + } + private GoogleSigned GetRealSigningInstance() { #if NETSTANDARD1 @@ -53,8 +63,7 @@ public void Geocoding_Request_Signed_With_Private_Key() Address = "Stathern, UK" }; - GoogleSigned.AssignAllServices(GetRealSigningInstance()); - var response = new GeocodingService().GetResponse(request); + var response = GMaps.GeocodingService.GetResponse(request); Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); } @@ -64,8 +73,7 @@ public void Geocoding_Request_Signed_With_Private_Key() public void Geocoding_Request_Signed_With_Api_Key() { // Arrange - var sign = new GoogleSigned("AIzaSyDV-0ftj1tsjfd6GnEbtbxwHXnv6iR3UEU"); - GoogleSigned.AssignAllServices(sign); + var GMaps = new Google.Maps.Services("AIzaSyDV-0ftj1tsjfd6GnEbtbxwHXnv6iR3UEU"); var request = new GeocodingRequest { @@ -73,7 +81,7 @@ public void Geocoding_Request_Signed_With_Api_Key() }; // Act - var response = new GeocodingService().GetResponse(request); + var response = GMaps.GeocodingService.GetResponse(request); // Assert Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); diff --git a/src/Google.Maps.Test/LatLngComparerTests.cs b/src/Google.Maps.Test/LatLngComparerTests.cs index c4edf4e..ce75e1b 100644 --- a/src/Google.Maps.Test/LatLngComparerTests.cs +++ b/src/Google.Maps.Test/LatLngComparerTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.Maps.Internal; namespace Google.Maps { diff --git a/src/Google.Maps.Test/MapColorTests.cs b/src/Google.Maps.Test/MapColorTests.cs index afc4f98..ccc3a68 100644 --- a/src/Google.Maps.Test/MapColorTests.cs +++ b/src/Google.Maps.Test/MapColorTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps { @@ -8,9 +9,9 @@ public class MapColorTests [Test] public void IsUndefined_Works() { - var undefined = new MapColor(); - var definedName = MapColor.FromName("red"); - var definedRGB = MapColor.FromArgb(255,255,255); + var undefined = new GColor(); + var definedName = GColor.FromName("red"); + var definedRGB = GColor.FromArgb(255,255,255); Assert.AreEqual(true, undefined.IsUndefined); Assert.AreEqual(false, definedName.IsUndefined); @@ -20,9 +21,9 @@ public void IsUndefined_Works() [Test] public void To24BitColor_Works() { - var namedColor = MapColor.FromName("red"); - var rgbColor = MapColor.FromArgb(255, 0, 0); - var rgbaColor = MapColor.FromArgb(255, 255, 0, 0); + var namedColor = GColor.FromName("red"); + var rgbColor = GColor.FromArgb(255, 0, 0); + var rgbaColor = GColor.FromArgb(255, 255, 0, 0); Assert.AreEqual("red", namedColor.To24BitColorString()); Assert.AreEqual("0xFF0000", rgbColor.To24BitColorString()); @@ -32,9 +33,9 @@ public void To24BitColor_Works() [Test] public void To32BitColor_Works() { - var namedColor = MapColor.FromName("red"); - var rgbColor = MapColor.FromArgb(255, 0, 0); - var rgbaColor = MapColor.FromArgb(255, 255, 0, 0); + var namedColor = GColor.FromName("red"); + var rgbColor = GColor.FromArgb(255, 0, 0); + var rgbaColor = GColor.FromArgb(255, 255, 0, 0); Assert.AreEqual("red", namedColor.To32BitColorString()); Assert.AreEqual("0xFF0000FF", rgbColor.To32BitColorString()); diff --git a/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs b/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs index 003fbb0..407ec28 100644 --- a/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs +++ b/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs @@ -2,16 +2,32 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.Places.Details { [TestFixture] class PlaceDetailsServiceTests { + GoogleSigned TestingApiKey; + [OneTimeSetUp] public void OneTimeSetUp() { - GoogleSigned.AssignAllServices(SigningHelper.GetApiKey()); + TestingApiKey = SigningHelper.GetApiKey(); + } + + private PlaceDetailsService CreateService() + { + return new PlaceDetailsService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri: null + ); } [TestCase("ChIJN1t_tDeuEmsRUsoyG83frY4", "Google")] @@ -23,7 +39,7 @@ public void PlacesDetailsTest(string placeID, string placeName) { PlaceID = placeID }; - var response = new PlaceDetailsService().GetResponse(request); + var response = CreateService().GetResponse(request); if(response.Status == ServiceResponseStatus.OverQueryLimit) { diff --git a/src/Google.Maps.Test/Places/PlacesServiceTests.cs b/src/Google.Maps.Test/Places/PlacesServiceTests.cs index 8f88604..18278da 100644 --- a/src/Google.Maps.Test/Places/PlacesServiceTests.cs +++ b/src/Google.Maps.Test/Places/PlacesServiceTests.cs @@ -3,6 +3,8 @@ using System.Threading; using NUnit.Framework; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.Places { @@ -19,7 +21,14 @@ public void OneTimeSetUp() private PlacesService CreateService() { - return new PlacesService(TestingApiKey); + return new PlacesService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri: null + ); } [Test] @@ -88,7 +97,7 @@ public void PlacesTest_Text() Query = "New York, NY", Radius = 10000 }; - PlacesResponse response = new PlacesService().GetResponse(request); + PlacesResponse response = CreateService().GetResponse(request); if(response.Status == ServiceResponseStatus.OverQueryLimit) { diff --git a/src/Google.Maps.Test/PolylineEncodingTests.cs b/src/Google.Maps.Test/PolylineEncodingTests.cs index 10a511e..ba5917d 100644 --- a/src/Google.Maps.Test/PolylineEncodingTests.cs +++ b/src/Google.Maps.Test/PolylineEncodingTests.cs @@ -3,6 +3,7 @@ using System.Linq; using NUnit.Framework; +using Google.Maps.Internal; namespace Google.Maps { diff --git a/src/Google.Maps.Test/QuickExamplesTests.cs b/src/Google.Maps.Test/QuickExamplesTests.cs index 11f792d..b696ad2 100644 --- a/src/Google.Maps.Test/QuickExamplesTests.cs +++ b/src/Google.Maps.Test/QuickExamplesTests.cs @@ -7,6 +7,7 @@ using Google.Maps.Direction; using Google.Maps.Geocoding; using Google.Maps.StaticMaps; +using Google.Maps.Common; namespace Google.Maps { @@ -19,10 +20,10 @@ class QuickExamplesTests static GoogleSigned TestingApiKey; [OneTimeSetUp] - public void OneTimeSetUp() + public void OneTimeSetup() { - TestingApiKey = SigningHelper.GetApiKey(); - GoogleSigned.AssignAllServices(TestingApiKey); + this.TestingApiKey = SigningHelper.GetApiKey(); + this.GMaps = new Services(TestingApiKey); } [OneTimeTearDown] public void OneTimeTearDown() @@ -30,13 +31,18 @@ public void OneTimeTearDown() GoogleSigned.AssignAllServices(null); } + + Google.Maps.Services GMaps; + [Test] [Category("ValueTesting")] public void GeocodingRequest_Example() { + var GMaps = new Google.Maps.Services("YOUR_API_KEY"); + var request = new GeocodingRequest(); request.Address = "1600 Amphitheatre Parkway Mountain View, CA 94043"; - var response = new GeocodingService().GetResponse(request); + var response = GMaps.GeocodingService.GetResponse(request); // --break in the online version here-- // @@ -56,7 +62,7 @@ public void StaticMapRequest_Example() { var map = new StaticMapRequest(); map.Center = new Location("1600 Amphitheatre Parkway Mountain View, CA 94043"); - map.Size = new MapSize(400, 400); + map.Size = new GSize(400, 400); map.Zoom = 14; var imgTagSrc = map.ToUri(); @@ -76,7 +82,7 @@ public void PartialMatchTest() Origin = new Location("410 Beeeeeechwood Rd, NJ 07450"), Destination = new Location("204 Powell Ave, CA 94523") }; - var response = new DirectionService().GetResponse(request); + var response = GMaps.DirectionService.GetResponse(request); Assert.True(response.Waypoints.Any(wp => wp.PartialMatch)); } diff --git a/src/Google.Maps.Test/Roads/RoadsServiceTests.cs b/src/Google.Maps.Test/Roads/RoadsServiceTests.cs index 0e28f5f..5971196 100644 --- a/src/Google.Maps.Test/Roads/RoadsServiceTests.cs +++ b/src/Google.Maps.Test/Roads/RoadsServiceTests.cs @@ -17,6 +17,7 @@ using System; using NUnit.Framework; +using Google.Maps.ApiCore; namespace Google.Maps.Roads { @@ -33,7 +34,14 @@ public void OneTimeSetUp() private RoadsService CreateService() { - return new RoadsService(TestingApiKey); + return new RoadsService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri: null + ); } [Test] diff --git a/src/Google.Maps.Test/StaticMaps/StaticMapRequestTests.cs b/src/Google.Maps.Test/StaticMaps/StaticMapRequestTests.cs index 18bc89a..6f96bfb 100644 --- a/src/Google.Maps.Test/StaticMaps/StaticMapRequestTests.cs +++ b/src/Google.Maps.Test/StaticMaps/StaticMapRequestTests.cs @@ -1,6 +1,7 @@ using System; using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps.StaticMaps { @@ -14,7 +15,7 @@ public void Invalid_size_propert_set() { StaticMapRequest sm = new StaticMapRequest() { - Size = new MapSize(-1, -1) + Size = new GSize(-1, -1) }; }); } @@ -26,7 +27,7 @@ public void Invalid_size_max() { StaticMapRequest sm = new StaticMapRequest() { - Size = new MapSize(4097, 4097) + Size = new GSize(4097, 4097) }; }); } diff --git a/src/Google.Maps.Test/StaticMaps/StaticMap_Path_Tests.cs b/src/Google.Maps.Test/StaticMaps/StaticMap_Path_Tests.cs index 11a2bc5..ce3e9b8 100644 --- a/src/Google.Maps.Test/StaticMaps/StaticMap_Path_Tests.cs +++ b/src/Google.Maps.Test/StaticMaps/StaticMap_Path_Tests.cs @@ -2,6 +2,7 @@ using System.Text.RegularExpressions; using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps.StaticMaps { @@ -46,7 +47,7 @@ public void Path_NonstandardColor_EncodedProperly() var map = new StaticMapRequest(); map.Paths.Add(new Path(new LatLng(30.0, -60.0)) { - Color = MapColor.FromArgb(0x80, 0xA0, 0xC0) + Color = GColor.FromArgb(0x80, 0xA0, 0xC0) }); string color = ExtractColorFromUri(map.ToUri()); Assert.AreEqual("0X80A0C0FF", color.ToUpper()); @@ -89,7 +90,7 @@ private static Path GreenTriangleInAdaMN() new LatLng(47.3017, -96.5299) ) { - Color = MapColor.FromName("green") + Color = GColor.FromName("green") }; } @@ -102,7 +103,7 @@ private static Path RedTriangleNearAdaMN() new LatLng(47.3105, -96.5326) ) { - Color = MapColor.FromName("red") + Color = GColor.FromName("red") }; } diff --git a/src/Google.Maps.Test/StreetView/StreetViewRequestTests.cs b/src/Google.Maps.Test/StreetView/StreetViewRequestTests.cs index e2a5f6a..dc0481c 100644 --- a/src/Google.Maps.Test/StreetView/StreetViewRequestTests.cs +++ b/src/Google.Maps.Test/StreetView/StreetViewRequestTests.cs @@ -2,6 +2,7 @@ using NUnit.Framework; using Google.Maps.StreetView; +using Google.Maps.Common; namespace Google.Maps.StreetView { @@ -15,7 +16,7 @@ public void Invalid_size_propert_set() { StreetViewRequest sm = new StreetViewRequest() { - Size = new MapSize(-1, -1) + Size = new GSize(-1, -1) }; }); } @@ -27,7 +28,7 @@ public void Invalid_size_max() { StreetViewRequest sm = new StreetViewRequest() { - Size = new MapSize(4097, 4097) + Size = new GSize(4097, 4097) }; }); } diff --git a/src/Google.Maps.Test/StreetView/StreetView_uribuilding_Tests.cs b/src/Google.Maps.Test/StreetView/StreetView_uribuilding_Tests.cs index 493d123..6bf6628 100644 --- a/src/Google.Maps.Test/StreetView/StreetView_uribuilding_Tests.cs +++ b/src/Google.Maps.Test/StreetView/StreetView_uribuilding_Tests.cs @@ -6,6 +6,7 @@ using FluentAssertions.Collections; using FluentAssertions; using Google.Maps.Test; +using Google.Maps.Common; namespace Google.Maps.StreetView { @@ -24,7 +25,7 @@ public void BasicUri() StreetViewRequest sm = new StreetViewRequest() { Location = new LatLng(30.1, -60.2) - ,Size = new MapSize(512, 512) + ,Size = new GSize(512, 512) }; //act @@ -44,7 +45,7 @@ public void BasicUri_heading() StreetViewRequest sm = new StreetViewRequest() { Location = new LatLng(30.1, -60.2) - ,Size = new MapSize(512, 512) + ,Size = new GSize(512, 512) ,Heading = 15 }; @@ -65,7 +66,7 @@ public void BasicUri_pitch() StreetViewRequest sm = new StreetViewRequest() { Location = new LatLng(30.1, -60.2) - ,Size = new MapSize(512, 512) + ,Size = new GSize(512, 512) ,Pitch = 15 }; diff --git a/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs b/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs index 9ad90a9..fa17af8 100644 --- a/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs +++ b/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs @@ -19,6 +19,8 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.TimeZone { @@ -28,7 +30,14 @@ public class TimeZoneServiceTests TimeZoneService CreateService() { - var svc = new TimeZoneService(TestingApiKey); + var svc = new TimeZoneService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri: null + ); return svc; } diff --git a/src/Google.Maps.Test/ValueTextComparer_Tests.cs b/src/Google.Maps.Test/ValueTextComparer_Tests.cs index 273c541..8612682 100644 --- a/src/Google.Maps.Test/ValueTextComparer_Tests.cs +++ b/src/Google.Maps.Test/ValueTextComparer_Tests.cs @@ -5,6 +5,9 @@ using System.Text; using System.Threading.Tasks; +using Google.Maps.Internal; +using Google.Maps.Common; + namespace Google.Maps.Test { [TestFixture] diff --git a/src/Google.Maps/ApiCore/BaseGmapsService.cs b/src/Google.Maps/ApiCore/BaseGmapsService.cs new file mode 100644 index 0000000..197248a --- /dev/null +++ b/src/Google.Maps/ApiCore/BaseGmapsService.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Google.Maps.ApiCore; + +namespace Google.Maps.ApiCore +{ + public abstract class BaseGmapsService + where TRequest : BaseRequest + { + public IHttpService HttpService { get; protected set; } + public Uri BaseUri { get; protected set; } + + + public void Dispose() + { + if(HttpService != null) + { + var disposable = HttpService as IDisposable; + if(disposable != null) + { + disposable.Dispose(); + } + + HttpService = null; + } + } + + } + +} diff --git a/src/Google.Maps/ApiCore/BaseGmapsServiceTypedResponse.cs b/src/Google.Maps/ApiCore/BaseGmapsServiceTypedResponse.cs new file mode 100644 index 0000000..aa4cf61 --- /dev/null +++ b/src/Google.Maps/ApiCore/BaseGmapsServiceTypedResponse.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Google.Maps.ApiCore; + +namespace Google.Maps.ApiCore +{ + + public abstract class BaseGmapsServiceTypedResponse : + BaseGmapsService, + IGmapsService + where TRequest : BaseRequest + where TResponse : class + { + public virtual TResponse GetResponse(TRequest request) + { + var url = new Uri(BaseUri, request.ToUri()); + + return HttpService.Get(url); + } + + public async Task GetResponseAsync(TRequest request) + { + var url = new Uri(BaseUri, request.ToUri()); + + return await HttpService.GetAsync(url); + } + + } + +} diff --git a/src/Google.Maps/BaseRequest.cs b/src/Google.Maps/ApiCore/BaseRequest.cs similarity index 91% rename from src/Google.Maps/BaseRequest.cs rename to src/Google.Maps/ApiCore/BaseRequest.cs index 243ccff..d884aae 100644 --- a/src/Google.Maps/BaseRequest.cs +++ b/src/Google.Maps/ApiCore/BaseRequest.cs @@ -1,30 +1,30 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Google.Maps -{ - public abstract class BaseRequest - { - [Obsolete("The Google Maps API no longer requires this parameter and it will be removed in the next release")] - public bool? Sensor { get; set; } - - /// - /// Converts the current request parameters to a uri - /// - /// - public abstract Uri ToUri(); - - /// - /// Returns the Uri as a string. - /// - /// - public string ToUriString() - { - return this.ToUri().ToString(); - } - - - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Google.Maps.ApiCore +{ + public abstract class BaseRequest + { + [Obsolete("The Google Maps API no longer requires this parameter and it will be removed in the next release")] + public bool? Sensor { get; set; } + + /// + /// Converts the current request parameters to a uri + /// + /// + public abstract Uri ToUri(); + + /// + /// Returns the Uri as a string. + /// + /// + public string ToUriString() + { + return this.ToUri().ToString(); + } + + + } +} \ No newline at end of file diff --git a/src/Google.Maps/ApiCore/BaseServiceBuilder.cs b/src/Google.Maps/ApiCore/BaseServiceBuilder.cs new file mode 100644 index 0000000..6010c05 --- /dev/null +++ b/src/Google.Maps/ApiCore/BaseServiceBuilder.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.Maps.ApiCore +{ + public abstract class BaseServiceBuilder : IServiceBuilder + { + + public BaseServiceBuilder() + { + } + + public IHttpService HttpService { get; protected set; } + public ISigningService SigningService { get; protected set; } + public Uri BaseUri { get; protected set; } + + public IServiceBuilder WithHttpService(IHttpService httpService) + { + this.HttpService = httpService; + return this; + } + + public IServiceBuilder WithSigningService(ISigningService signingService) + { + this.SigningService = signingService; + return this; + } + + public abstract TService Create(); + } +} diff --git a/src/Google.Maps/ApiCore/GoogleApiSigningService.cs b/src/Google.Maps/ApiCore/GoogleApiSigningService.cs new file mode 100644 index 0000000..77a46cd --- /dev/null +++ b/src/Google.Maps/ApiCore/GoogleApiSigningService.cs @@ -0,0 +1,25 @@ +using Google.Maps; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.Maps.ApiCore +{ + public class GoogleApiSigningService : ISigningService + { + public GoogleApiSigningService(Google.Maps.GoogleSigned signingInstance) + { + if(signingInstance == null) throw new ArgumentNullException("signingInstance"); + this._SigningInstance = signingInstance; + } + + private GoogleSigned _SigningInstance; + + public Uri GetSignedUri(Uri value) + { + return new Uri(_SigningInstance.GetSignedUri(value)); + } + } +} diff --git a/src/Google.Maps/ApiCore/IGMapsService.cs b/src/Google.Maps/ApiCore/IGMapsService.cs new file mode 100644 index 0000000..1067da8 --- /dev/null +++ b/src/Google.Maps/ApiCore/IGMapsService.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Google.Maps.ApiCore; + +namespace Google.Maps.ApiCore +{ + public interface IGmapsService + { + + TResponse GetResponse(TRequest request); + } + + +} diff --git a/src/Google.Maps/ApiCore/IHttpService.cs b/src/Google.Maps/ApiCore/IHttpService.cs new file mode 100644 index 0000000..3bdc032 --- /dev/null +++ b/src/Google.Maps/ApiCore/IHttpService.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.Maps.ApiCore +{ + public interface IHttpService + { + Task GetAsync(Uri uri) where T : class; + + T Get(Uri uri) where T : class; + + Task GetStreamAsync(Uri uri); + + System.IO.Stream GetStream(Uri uri); + + } + +} diff --git a/src/Google.Maps/ApiCore/IServiceBuilder.cs b/src/Google.Maps/ApiCore/IServiceBuilder.cs new file mode 100644 index 0000000..2f3cac3 --- /dev/null +++ b/src/Google.Maps/ApiCore/IServiceBuilder.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.Maps.ApiCore +{ + + public interface IServiceBuilder + { + + TService Create(); + + IServiceBuilder WithHttpService(IHttpService httpService); + + IServiceBuilder WithSigningService(ISigningService httpService); + + } +} diff --git a/src/Google.Maps/ApiCore/ISigningService.cs b/src/Google.Maps/ApiCore/ISigningService.cs new file mode 100644 index 0000000..49e8de4 --- /dev/null +++ b/src/Google.Maps/ApiCore/ISigningService.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.Maps.ApiCore +{ + public interface ISigningService + { + Uri GetSignedUri(Uri value); + + } +} diff --git a/src/Google.Maps/Shared/AddressComponent.cs b/src/Google.Maps/Common/AddressComponent.cs similarity index 98% rename from src/Google.Maps/Shared/AddressComponent.cs rename to src/Google.Maps/Common/AddressComponent.cs index 5c91891..bebcc2a 100644 --- a/src/Google.Maps/Shared/AddressComponent.cs +++ b/src/Google.Maps/Common/AddressComponent.cs @@ -18,7 +18,7 @@ using Newtonsoft.Json; using System; -namespace Google.Maps.Shared +namespace Google.Maps.Common { public class AddressComponent : IEquatable { diff --git a/src/Google.Maps/Shared/AddressType.cs b/src/Google.Maps/Common/AddressType.cs similarity index 99% rename from src/Google.Maps/Shared/AddressType.cs rename to src/Google.Maps/Common/AddressType.cs index c66a6a9..47c0d14 100644 --- a/src/Google.Maps/Shared/AddressType.cs +++ b/src/Google.Maps/Common/AddressType.cs @@ -15,7 +15,7 @@ * limitations under the License. */ -namespace Google.Maps.Shared +namespace Google.Maps.Common { public enum AddressType { diff --git a/src/Google.Maps/Avoid.cs b/src/Google.Maps/Common/Avoid.cs similarity index 94% rename from src/Google.Maps/Avoid.cs rename to src/Google.Maps/Common/Avoid.cs index dbd32d8..59f7d14 100644 --- a/src/Google.Maps/Avoid.cs +++ b/src/Google.Maps/Common/Avoid.cs @@ -1,6 +1,6 @@ using System; -namespace Google.Maps +namespace Google.Maps.Common { /// /// Directions may be calculated that adhere to certain restrictions. diff --git a/src/Google.Maps/ComponentFilter.cs b/src/Google.Maps/Common/ComponentFilter.cs similarity index 99% rename from src/Google.Maps/ComponentFilter.cs rename to src/Google.Maps/Common/ComponentFilter.cs index 3a9d029..f849f25 100644 --- a/src/Google.Maps/ComponentFilter.cs +++ b/src/Google.Maps/Common/ComponentFilter.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace Google.Maps +namespace Google.Maps.Common { /// /// In a geocoding response, the Google Maps Geocoding API can return address results restricted to a specific area. diff --git a/src/Google.Maps/Constants.cs b/src/Google.Maps/Common/Constants.cs similarity index 96% rename from src/Google.Maps/Constants.cs rename to src/Google.Maps/Common/Constants.cs index 4997844..694bd3a 100644 --- a/src/Google.Maps/Constants.cs +++ b/src/Google.Maps/Common/Constants.cs @@ -1,100 +1,100 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Google.Maps -{ - internal static class Constants - { - public const int SIZE_WIDTH_MIN = 1; - public const int SIZE_HEIGHT_MIN = 1; - public const int SIZE_WIDTH_MAX = 4096; - public const int SIZE_HEIGHT_MAX = 4096; - - public const int ZOOM_LEVEL_MIN = 0; - - public const string PATH_ENCODED_PREFIX = "enc:"; - public const string PIPE_URL_ENCODED = "%7C"; - - public const string expectedColors = "black, brown, green, purple, yellow, blue, gray, orange, red, white"; //pasted straight from the website. - - private static string[] S_ExpectedNamedColors; - public static bool IsExpectedNamedColor(string value) - { - if(value == null) return false; - return (Contains(S_ExpectedNamedColors, value, true)); - } - - private static int[] S_ExpectedScaleValues; - public static bool IsExpectedScaleValue(int value, bool throwIfOutOfRange) - { - if(Contains(S_ExpectedScaleValues, value) == true) return true; - - if(throwIfOutOfRange) - throw new ArgumentOutOfRangeException("Scale value can only be " + ListValues(S_ExpectedScaleValues)); - else - return false; - } - - static Constants() - { - S_ExpectedNamedColors = expectedColors.Replace(", ", ",").Split(','); //since we paste straight from the website, we remove spaces, and convert to an array. - S_ExpectedScaleValues = new int[] { 1, 2, 4 }; - } - - #region Pre-Framework v3.0 support - private static bool Contains(string[] array, string value, bool ignoreCase) - { - //TODO: rewrite for speed somehow - for(int i = 0; i < array.Length; i++) - { - if(string.Compare(array[i], value, ignoreCase) == 0) return true; - } - - return false; - } - private static bool Contains(int[] array, int value) - { - //TODO: rewrite for speed somehow - for(int i = 0; i < array.Length; i++) - { - if(array[i] == value) return true; - } - - return false; - } - private static string ListValues(int[] array) - { - //TODO: rewrite for speed somehow - System.Text.StringBuilder sb = new StringBuilder(); - for(int i = 0; i < array.Length; i++) - { - if(sb.Length > 0) sb.Append(","); - sb.Append(array[i]); - } - return sb.ToString(); - } - - internal static void CheckHeadingRange(short value, string parameterName) - { - const string HEADING_PARAMETER_RANGE = "Heading value must be greater or equal to 0 and less than or equal to 360"; - if(value < 0) throw new ArgumentOutOfRangeException(parameterName, HEADING_PARAMETER_RANGE); - if(value > 360) throw new ArgumentOutOfRangeException(parameterName, HEADING_PARAMETER_RANGE); - } - - internal static void CheckPitchRange(short value, string parameterName) - { - const string PITCH_PARAMETER_RANGE = "Pitch value must be greater or equal to -90 and less than or equal to 90."; - if(value < -90 || value > 90) throw new ArgumentOutOfRangeException(PITCH_PARAMETER_RANGE, parameterName); - } - - internal static void CheckFieldOfViewRange(short value, string parameterName) - { - const string FIELD_OF_VIEW_PARAMETER_RANGE = "Field of view value must be greater or equal to 1 and less than or equal to 120."; - if (value < 1 || value > 120) throw new ArgumentOutOfRangeException(FIELD_OF_VIEW_PARAMETER_RANGE, parameterName); - } - - #endregion - - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace Google.Maps.Common +{ + internal static class Constants + { + public const int SIZE_WIDTH_MIN = 1; + public const int SIZE_HEIGHT_MIN = 1; + public const int SIZE_WIDTH_MAX = 4096; + public const int SIZE_HEIGHT_MAX = 4096; + + public const int ZOOM_LEVEL_MIN = 0; + + public const string PATH_ENCODED_PREFIX = "enc:"; + public const string PIPE_URL_ENCODED = "%7C"; + + public const string expectedColors = "black, brown, green, purple, yellow, blue, gray, orange, red, white"; //pasted straight from the website. + + private static string[] S_ExpectedNamedColors; + public static bool IsExpectedNamedColor(string value) + { + if(value == null) return false; + return (Contains(S_ExpectedNamedColors, value, true)); + } + + private static int[] S_ExpectedScaleValues; + public static bool IsExpectedScaleValue(int value, bool throwIfOutOfRange) + { + if(Contains(S_ExpectedScaleValues, value) == true) return true; + + if(throwIfOutOfRange) + throw new ArgumentOutOfRangeException("Scale value can only be " + ListValues(S_ExpectedScaleValues)); + else + return false; + } + + static Constants() + { + S_ExpectedNamedColors = expectedColors.Replace(", ", ",").Split(','); //since we paste straight from the website, we remove spaces, and convert to an array. + S_ExpectedScaleValues = new int[] { 1, 2, 4 }; + } + + #region Pre-Framework v3.0 support + private static bool Contains(string[] array, string value, bool ignoreCase) + { + //TODO: rewrite for speed somehow + for(int i = 0; i < array.Length; i++) + { + if(string.Compare(array[i], value, ignoreCase) == 0) return true; + } + + return false; + } + private static bool Contains(int[] array, int value) + { + //TODO: rewrite for speed somehow + for(int i = 0; i < array.Length; i++) + { + if(array[i] == value) return true; + } + + return false; + } + private static string ListValues(int[] array) + { + //TODO: rewrite for speed somehow + System.Text.StringBuilder sb = new StringBuilder(); + for(int i = 0; i < array.Length; i++) + { + if(sb.Length > 0) sb.Append(","); + sb.Append(array[i]); + } + return sb.ToString(); + } + + internal static void CheckHeadingRange(short value, string parameterName) + { + const string HEADING_PARAMETER_RANGE = "Heading value must be greater or equal to 0 and less than or equal to 360"; + if(value < 0) throw new ArgumentOutOfRangeException(parameterName, HEADING_PARAMETER_RANGE); + if(value > 360) throw new ArgumentOutOfRangeException(parameterName, HEADING_PARAMETER_RANGE); + } + + internal static void CheckPitchRange(short value, string parameterName) + { + const string PITCH_PARAMETER_RANGE = "Pitch value must be greater or equal to -90 and less than or equal to 90."; + if(value < -90 || value > 90) throw new ArgumentOutOfRangeException(PITCH_PARAMETER_RANGE, parameterName); + } + + internal static void CheckFieldOfViewRange(short value, string parameterName) + { + const string FIELD_OF_VIEW_PARAMETER_RANGE = "Field of view value must be greater or equal to 1 and less than or equal to 120."; + if (value < 1 || value > 120) throw new ArgumentOutOfRangeException(FIELD_OF_VIEW_PARAMETER_RANGE, parameterName); + } + + #endregion + + } +} diff --git a/src/Google.Maps/MapColor.cs b/src/Google.Maps/Common/GColor.cs similarity index 75% rename from src/Google.Maps/MapColor.cs rename to src/Google.Maps/Common/GColor.cs index 79bd294..f1d7464 100644 --- a/src/Google.Maps/MapColor.cs +++ b/src/Google.Maps/Common/GColor.cs @@ -1,11 +1,11 @@ using System; -namespace Google.Maps +namespace Google.Maps.Common { /// /// Represents a Google Maps color. /// - public struct MapColor + public struct GColor { UInt32 value; string colorName; @@ -35,9 +35,9 @@ public string To32BitColorString() /// /// Create a color froma CSS3 color name /// - public static MapColor FromName(string cssColor) + public static GColor FromName(string cssColor) { - var color = new MapColor(); + var color = new GColor(); color.colorName = cssColor.ToLower(); return color; } @@ -45,7 +45,7 @@ public static MapColor FromName(string cssColor) /// /// Create a color from RGB values and a fully opaque alpha /// - public static MapColor FromArgb(int red, int green, int blue) + public static GColor FromArgb(int red, int green, int blue) { return FromArgb(255, red, green, blue); } @@ -53,29 +53,29 @@ public static MapColor FromArgb(int red, int green, int blue) /// /// Create a color from RGB and alpha values /// - public static MapColor FromArgb(int alpha, int red, int green, int blue) + public static GColor FromArgb(int alpha, int red, int green, int blue) { - var color = new MapColor(); + var color = new GColor(); color.value = (uint)(((uint)red << 24) + (green << 16) + (blue << 8) + alpha); return color; } - public static bool operator ==(MapColor a, MapColor b) + public static bool operator ==(GColor a, GColor b) { if (a.isNamedColor && b.isNamedColor) return a.colorName == b.colorName; if (a.isNamedColor ^ b.isNamedColor) return false; return a.value == b.value; } - public static bool operator !=(MapColor a, MapColor b) + public static bool operator !=(GColor a, GColor b) { return a != b; } public override bool Equals(object obj) { - if (!(obj is MapColor)) return false; - var o = (MapColor)obj; + if (!(obj is GColor)) return false; + var o = (GColor)obj; return this == o; } @@ -86,7 +86,7 @@ public override int GetHashCode() } #if HAS_SYSTEMDRAWING - public static implicit operator MapColor(System.Drawing.Color systemColor) + public static implicit operator GColor(System.Drawing.Color systemColor) { return FromArgb(systemColor.A, systemColor.R, systemColor.G, systemColor.B); } diff --git a/src/Google.Maps/Common/GSize.cs b/src/Google.Maps/Common/GSize.cs new file mode 100644 index 0000000..29b946b --- /dev/null +++ b/src/Google.Maps/Common/GSize.cs @@ -0,0 +1,23 @@ +namespace Google.Maps.Common +{ + public struct GSize + { + public GSize(int width, int height) + { + this.Width = width; + this.Height = height; + } + + public int Width { get; set; } + + public int Height { get; set; } + +#if HAS_SYSTEMDRAWING + public static implicit operator GSize(System.Drawing.Size systemSize) + { + return new GSize(systemSize.Width, systemSize.Height); + } +#endif + + } +} \ No newline at end of file diff --git a/src/Google.Maps/Shared/Geometry.cs b/src/Google.Maps/Common/Geometry.cs similarity index 98% rename from src/Google.Maps/Shared/Geometry.cs rename to src/Google.Maps/Common/Geometry.cs index f38039a..b00799c 100644 --- a/src/Google.Maps/Shared/Geometry.cs +++ b/src/Google.Maps/Common/Geometry.cs @@ -18,7 +18,7 @@ using Newtonsoft.Json; using System; -namespace Google.Maps.Shared +namespace Google.Maps.Common { [JsonObject(MemberSerialization.OptIn)] public class Geometry diff --git a/src/Google.Maps/Shared/LocationType.cs b/src/Google.Maps/Common/LocationType.cs similarity index 98% rename from src/Google.Maps/Shared/LocationType.cs rename to src/Google.Maps/Common/LocationType.cs index 7a47ea7..d4d0f1d 100644 --- a/src/Google.Maps/Shared/LocationType.cs +++ b/src/Google.Maps/Common/LocationType.cs @@ -15,7 +15,7 @@ * limitations under the License. */ -namespace Google.Maps.Shared +namespace Google.Maps.Common { public enum LocationType { diff --git a/src/Google.Maps/GMapsImageFormats.cs b/src/Google.Maps/Common/MapImageFormats.cs similarity index 89% rename from src/Google.Maps/GMapsImageFormats.cs rename to src/Google.Maps/Common/MapImageFormats.cs index 159b41f..749ed98 100644 --- a/src/Google.Maps/GMapsImageFormats.cs +++ b/src/Google.Maps/Common/MapImageFormats.cs @@ -1,38 +1,38 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Google.Maps -{ - /// - /// Represents the different image formats available from the Google Maps API. - /// - public enum GMapsImageFormats - { - Unspecified = 0, - /// - /// (default) specifies the 8-bit PNG format - /// - PNG = 1, - /// - /// specifies the 8-bit PNG format - /// - PNG8 = 1, - /// - /// specifies the 32-bit PNG format - /// - PNG32 = 2, - /// - /// specifies the GIF format - /// - GIF = 4, - /// - /// specifies the JPEG compression format - /// - JPG = 5, - /// - /// specifies a non-progressive JPEG compression format - /// - JPGbaseline = 6 - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace Google.Maps.Common +{ + /// + /// Represents the different image formats available from the Google Maps API. + /// + public enum MapImageFormats + { + Unspecified = 0, + /// + /// (default) specifies the 8-bit PNG format + /// + PNG = 1, + /// + /// specifies the 8-bit PNG format + /// + PNG8 = 1, + /// + /// specifies the 32-bit PNG format + /// + PNG32 = 2, + /// + /// specifies the GIF format + /// + GIF = 4, + /// + /// specifies the JPEG compression format + /// + JPG = 5, + /// + /// specifies a non-progressive JPEG compression format + /// + JPGbaseline = 6 + } +} diff --git a/src/Google.Maps/RankBy.cs b/src/Google.Maps/Common/RankBy.cs similarity index 94% rename from src/Google.Maps/RankBy.cs rename to src/Google.Maps/Common/RankBy.cs index a3f0433..3319fe2 100644 --- a/src/Google.Maps/RankBy.cs +++ b/src/Google.Maps/Common/RankBy.cs @@ -1,31 +1,31 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Google.Maps -{ - public enum RankBy - { - Prominence, - Distance - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Google.Maps.Common +{ + public enum RankBy + { + Prominence, + Distance + } +} diff --git a/src/Google.Maps/ServiceResponseStatus.cs b/src/Google.Maps/Common/ServiceResponseStatus.cs similarity index 95% rename from src/Google.Maps/ServiceResponseStatus.cs rename to src/Google.Maps/Common/ServiceResponseStatus.cs index 98e69e6..671681d 100644 --- a/src/Google.Maps/ServiceResponseStatus.cs +++ b/src/Google.Maps/Common/ServiceResponseStatus.cs @@ -1,64 +1,64 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace Google.Maps -{ - public enum ServiceResponseStatus - { - Unknown = 0, - - /// - /// Indicates that no errors occurred; the address was successfully - /// parsed and at least one geocode was returned. - /// - Ok = -1, - - /// - /// Indicating the service request was malformed. - /// - InvalidRequest = 1, - - /// - /// Indicates that the geocode was successful but returned no results. - /// This may occur if the geocode was passed a non-existent address or - /// a latlng in a remote location. - /// - ZeroResults = 2, - - /// - /// Indicates that you are over your quota. - /// - OverQueryLimit = 3, - - /// - /// Indicates that your request was denied. - /// - RequestDenied = 4, - - /// - /// At least one of the provided locations in the request could not - /// be geocoded. - /// - NotFound = 5, - - /// - /// Indicates that too many waypoints were provided in the request. - /// Without an API key the maximum number is 8. - /// - MaxWaypointsExceeded = 6 - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Google.Maps.Common +{ + public enum ServiceResponseStatus + { + Unknown = 0, + + /// + /// Indicates that no errors occurred; the address was successfully + /// parsed and at least one geocode was returned. + /// + Ok = -1, + + /// + /// Indicating the service request was malformed. + /// + InvalidRequest = 1, + + /// + /// Indicates that the geocode was successful but returned no results. + /// This may occur if the geocode was passed a non-existent address or + /// a latlng in a remote location. + /// + ZeroResults = 2, + + /// + /// Indicates that you are over your quota. + /// + OverQueryLimit = 3, + + /// + /// Indicates that your request was denied. + /// + RequestDenied = 4, + + /// + /// At least one of the provided locations in the request could not + /// be geocoded. + /// + NotFound = 5, + + /// + /// Indicates that too many waypoints were provided in the request. + /// Without an API key the maximum number is 8. + /// + MaxWaypointsExceeded = 6 + } +} diff --git a/src/Google.Maps/TravelMode.cs b/src/Google.Maps/Common/TravelMode.cs similarity index 95% rename from src/Google.Maps/TravelMode.cs rename to src/Google.Maps/Common/TravelMode.cs index 87ec14f..cf0a838 100644 --- a/src/Google.Maps/TravelMode.cs +++ b/src/Google.Maps/Common/TravelMode.cs @@ -1,34 +1,34 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Google.Maps -{ - /// - /// When you calculate directions, you may specify which transportation mode to use. By default, directions are calculated as driving directions. The following travel modes are currently supported: - /// Note: Both walking and bicycling directions may sometimes not include clear pedestrian or bicycling paths, so these directions will return warnings in the returned result which you must display to the user. - /// - /// - public enum TravelMode - { - /// - /// (default) indicates standard driving directions using the road network. - /// - driving, - - /// - /// requests walking directions via pedestrian paths and sidewalks (where available). - /// - walking, - - /// - /// requests bicycling directions via bicycle paths and preferred streets (currently only available in the US). - /// - bicycling, - - /// - /// requests public transportation directions (where available). - /// - transit - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace Google.Maps.Common +{ + /// + /// When you calculate directions, you may specify which transportation mode to use. By default, directions are calculated as driving directions. The following travel modes are currently supported: + /// Note: Both walking and bicycling directions may sometimes not include clear pedestrian or bicycling paths, so these directions will return warnings in the returned result which you must display to the user. + /// + /// + public enum TravelMode + { + /// + /// (default) indicates standard driving directions using the road network. + /// + driving, + + /// + /// requests walking directions via pedestrian paths and sidewalks (where available). + /// + walking, + + /// + /// requests bicycling directions via bicycle paths and preferred streets (currently only available in the US). + /// + bicycling, + + /// + /// requests public transportation directions (where available). + /// + transit + } +} diff --git a/src/Google.Maps/Units.cs b/src/Google.Maps/Common/Units.cs similarity index 92% rename from src/Google.Maps/Units.cs rename to src/Google.Maps/Common/Units.cs index 67f7d43..9e3d20e 100644 --- a/src/Google.Maps/Units.cs +++ b/src/Google.Maps/Common/Units.cs @@ -1,23 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Google.Maps -{ - /// - /// When you calculate Directions Matrix, you may specify which Unit system mode to use. - /// By default, directions are showes as metric. The following units system modes are currently supported: - /// - public enum Units - { - /// - /// (default) Returns distances in kilometers and meters - /// - metric, - - /// - /// returns distances in miles and feet - /// - imperial - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace Google.Maps.Common +{ + /// + /// When you calculate Directions Matrix, you may specify which Unit system mode to use. + /// By default, directions are showes as metric. The following units system modes are currently supported: + /// + public enum Units + { + /// + /// (default) Returns distances in kilometers and meters + /// + metric, + + /// + /// returns distances in miles and feet + /// + imperial + } +} diff --git a/src/Google.Maps/ValueText.cs b/src/Google.Maps/Common/ValueText.cs similarity index 93% rename from src/Google.Maps/ValueText.cs rename to src/Google.Maps/Common/ValueText.cs index 5afe2d0..d990954 100644 --- a/src/Google.Maps/ValueText.cs +++ b/src/Google.Maps/Common/ValueText.cs @@ -3,7 +3,7 @@ using System.Text; using Newtonsoft.Json; -namespace Google.Maps +namespace Google.Maps.Common { [JsonObject(MemberSerialization.OptIn)] public class ValueText diff --git a/src/Google.Maps/Shared/Viewport.cs b/src/Google.Maps/Common/Viewport.cs similarity index 97% rename from src/Google.Maps/Shared/Viewport.cs rename to src/Google.Maps/Common/Viewport.cs index 34a1840..1a2c091 100644 --- a/src/Google.Maps/Shared/Viewport.cs +++ b/src/Google.Maps/Common/Viewport.cs @@ -18,7 +18,7 @@ using Newtonsoft.Json; using System; -namespace Google.Maps.Shared +namespace Google.Maps.Common { [JsonObject(MemberSerialization.OptIn)] public class Viewport diff --git a/src/Google.Maps/Direction/DirectionLeg.cs b/src/Google.Maps/Direction/DirectionLeg.cs index 7c0e832..b708d18 100644 --- a/src/Google.Maps/Direction/DirectionLeg.cs +++ b/src/Google.Maps/Direction/DirectionLeg.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Text; + using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.Direction { diff --git a/src/Google.Maps/Direction/DirectionRequest.cs b/src/Google.Maps/Direction/DirectionRequest.cs index 0e130be..aff35d6 100644 --- a/src/Google.Maps/Direction/DirectionRequest.cs +++ b/src/Google.Maps/Direction/DirectionRequest.cs @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; using System.Text; -using Google.Maps; using System.ComponentModel; +using Google.Maps.ApiCore; +using Google.Maps.Common; +using Google.Maps.Internal; + namespace Google.Maps.Direction { public class DirectionRequest : BaseRequest diff --git a/src/Google.Maps/Direction/DirectionService.cs b/src/Google.Maps/Direction/DirectionService.cs index 8a9ce8b..2dde4d7 100644 --- a/src/Google.Maps/Direction/DirectionService.cs +++ b/src/Google.Maps/Direction/DirectionService.cs @@ -18,45 +18,20 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.Direction { - public class DirectionService : IDisposable + + public class DirectionService : BaseGmapsServiceTypedResponse, IDisposable { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/directions/"); - public static readonly Uri HttpUri = new Uri("http://maps.google.com/maps/api/directions/"); - - Uri baseUri; - MapsHttp http; - public DirectionService(GoogleSigned signingSvc = null, Uri baseUri = null) + public DirectionService(IHttpService httpService, Uri baseUri) { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); - } - - public DirectionResponse GetResponse(DirectionRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return http.Get(url); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } - public async Task GetResponseAsync(DirectionRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return await http.GetAsync(url); - } - - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/Direction/DirectionStep.cs b/src/Google.Maps/Direction/DirectionStep.cs index bc580b9..55ca475 100644 --- a/src/Google.Maps/Direction/DirectionStep.cs +++ b/src/Google.Maps/Direction/DirectionStep.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; using System.Text; + using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.Direction { diff --git a/src/Google.Maps/Direction/GeocodedWaypoint.cs b/src/Google.Maps/Direction/GeocodedWaypoint.cs index dc6157f..c7f03e3 100644 --- a/src/Google.Maps/Direction/GeocodedWaypoint.cs +++ b/src/Google.Maps/Direction/GeocodedWaypoint.cs @@ -1,10 +1,11 @@ -using Google.Maps.Shared; -using Newtonsoft.Json; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; +using Google.Maps.Common; + namespace Google.Maps.Direction { public class GeocodedWaypoint diff --git a/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs index e7b3cdf..29fde90 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs @@ -18,10 +18,13 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using Google.Maps; using System.Text; using System.Linq; +using Google.Maps.ApiCore; +using Google.Maps.Common; +using Google.Maps.Internal; + namespace Google.Maps.DistanceMatrix { /// diff --git a/src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs index f40b005..a9d1486 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; + using Newtonsoft.Json; using Google.Maps.Common; diff --git a/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs index 2f08f46..97aae05 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs @@ -18,6 +18,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.DistanceMatrix { @@ -27,42 +28,15 @@ namespace Google.Maps.DistanceMatrix /// This service does not return detailed route information. Route information can be obtained by passing the desired single origin and destination to the Directions API. /// /// - public class DistanceMatrixService : IDisposable + public class DistanceMatrixService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/distancematrix/"); - public static readonly Uri HttpUri = new Uri("http://maps.google.com/maps/api/distancematrix/"); - Uri baseUri; - MapsHttp http; - - public DistanceMatrixService(GoogleSigned signingSvc = null, Uri baseUri = null) - { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); - } - - public DistanceMatrixResponse GetResponse(DistanceMatrixRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return http.Get(url); - } - - public async Task GetResponseAsync(DistanceMatrixRequest request) + public DistanceMatrixService(IHttpService httpService, Uri baseUri) { - var url = new Uri(baseUri, request.ToUri()); - - return await http.GetAsync(url); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/Elevation/ElevationRequest.cs b/src/Google.Maps/Elevation/ElevationRequest.cs index 0d46084..59e69b5 100644 --- a/src/Google.Maps/Elevation/ElevationRequest.cs +++ b/src/Google.Maps/Elevation/ElevationRequest.cs @@ -16,6 +16,8 @@ */ using System; using System.Collections.Generic; + +using Google.Maps.ApiCore; using Google.Maps.Internal; namespace Google.Maps.Elevation diff --git a/src/Google.Maps/Elevation/ElevationResponse.cs b/src/Google.Maps/Elevation/ElevationResponse.cs index 2c675f2..664562d 100644 --- a/src/Google.Maps/Elevation/ElevationResponse.cs +++ b/src/Google.Maps/Elevation/ElevationResponse.cs @@ -17,6 +17,7 @@ using Google.Maps.Common; using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.Elevation { diff --git a/src/Google.Maps/Elevation/ElevationService.cs b/src/Google.Maps/Elevation/ElevationService.cs index f4f9784..b6ad230 100644 --- a/src/Google.Maps/Elevation/ElevationService.cs +++ b/src/Google.Maps/Elevation/ElevationService.cs @@ -18,6 +18,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.Elevation { @@ -27,49 +28,15 @@ namespace Google.Maps.Elevation /// using the four nearest locations. /// /// - public class ElevationService : IDisposable + public class ElevationService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/elevation/"); - public static readonly Uri HttpUri = new Uri("http://maps.google.com/maps/api/elevation/"); - Uri baseUri; - MapsHttp http; - - public ElevationService(GoogleSigned signingSvc = null, Uri baseUri = null) - { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); - } - - /// - /// Sends the specified request to the Google Maps Elevation web - /// service and parses the response as an ElevationResponse - /// object. - /// - /// - /// - public ElevationResponse GetResponse(ElevationRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return http.Get(url); - } - - public async Task GetResponseAsync(ElevationRequest request) + public ElevationService(IHttpService httpService, Uri baseUri) { - var url = new Uri(baseUri, request.ToUri()); - - return await http.GetAsync(url); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/Geocoding/GeocodeResponse.cs b/src/Google.Maps/Geocoding/GeocodeResponse.cs index 2cd62ef..8064f36 100644 --- a/src/Google.Maps/Geocoding/GeocodeResponse.cs +++ b/src/Google.Maps/Geocoding/GeocodeResponse.cs @@ -15,9 +15,10 @@ * limitations under the License. */ +using System; using Google.Maps.Common; using Newtonsoft.Json; -using System; +using Google.Maps.Common; namespace Google.Maps.Geocoding { diff --git a/src/Google.Maps/Geocoding/GeocodingRequest.cs b/src/Google.Maps/Geocoding/GeocodingRequest.cs index 4ed8efb..1401916 100644 --- a/src/Google.Maps/Geocoding/GeocodingRequest.cs +++ b/src/Google.Maps/Geocoding/GeocodingRequest.cs @@ -17,7 +17,8 @@ using System; -using Google.Maps.Shared; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.Geocoding { diff --git a/src/Google.Maps/Geocoding/GeocodingService.cs b/src/Google.Maps/Geocoding/GeocodingService.cs index 46898e6..fd71fb3 100644 --- a/src/Google.Maps/Geocoding/GeocodingService.cs +++ b/src/Google.Maps/Geocoding/GeocodingService.cs @@ -19,6 +19,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.Geocoding { @@ -28,49 +29,15 @@ namespace Google.Maps.Geocoding /// (turning coordinates into addresses); this process is known as /// "reverse geocoding." /// - public class GeocodingService : IDisposable + public class GeocodingService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/geocode/"); - public static readonly Uri HttpUri = new Uri("http://maps.google.com/maps/api/geocode/"); - Uri baseUri; - MapsHttp http; - - public GeocodingService(GoogleSigned signingSvc = null, Uri baseUri = null) - { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); - } - - /// - /// Sends the specified request to the Google Maps Geocoding web - /// service and parses the response as an GeocodingResponse - /// object. - /// - /// - /// - public GeocodeResponse GetResponse(GeocodingRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return http.Get(url); - } - - public async Task GetResponseAsync(GeocodingRequest request) + public GeocodingService(IHttpService httpService, Uri baseUri) { - var url = new Uri(baseUri, request.ToUri()); - - return await http.GetAsync(url); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/Geocoding/Result.cs b/src/Google.Maps/Geocoding/Result.cs index 7ea5404..80cd24d 100644 --- a/src/Google.Maps/Geocoding/Result.cs +++ b/src/Google.Maps/Geocoding/Result.cs @@ -17,7 +17,7 @@ using Newtonsoft.Json; using System; -using Google.Maps.Shared; +using Google.Maps.Common; namespace Google.Maps.Geocoding { diff --git a/src/Google.Maps/Google.Maps.csproj b/src/Google.Maps/Google.Maps.csproj index 8510a41..f366345 100644 --- a/src/Google.Maps/Google.Maps.csproj +++ b/src/Google.Maps/Google.Maps.csproj @@ -9,6 +9,11 @@ HAS_SYSTEMDRAWING + + + + + diff --git a/src/Google.Maps/AvoidHelper.cs b/src/Google.Maps/Internal/AvoidHelper.cs similarity index 88% rename from src/Google.Maps/AvoidHelper.cs rename to src/Google.Maps/Internal/AvoidHelper.cs index 2b54214..655e678 100644 --- a/src/Google.Maps/AvoidHelper.cs +++ b/src/Google.Maps/Internal/AvoidHelper.cs @@ -3,7 +3,9 @@ using System.Linq; using System.Text; -namespace Google.Maps +using Google.Maps.Common; + +namespace Google.Maps.Internal { internal static class AvoidHelper { diff --git a/src/Google.Maps/LatLngComparer.cs b/src/Google.Maps/Internal/LatLngComparer.cs similarity index 97% rename from src/Google.Maps/LatLngComparer.cs rename to src/Google.Maps/Internal/LatLngComparer.cs index e75a457..1c5c5a5 100644 --- a/src/Google.Maps/LatLngComparer.cs +++ b/src/Google.Maps/Internal/LatLngComparer.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace Google.Maps +namespace Google.Maps.Internal { public class LatLngComparer : IEqualityComparer { diff --git a/src/Google.Maps/Internal/MapsHttp.cs b/src/Google.Maps/Internal/MapsHttp.cs index 14058a2..7ee1c46 100644 --- a/src/Google.Maps/Internal/MapsHttp.cs +++ b/src/Google.Maps/Internal/MapsHttp.cs @@ -22,19 +22,25 @@ using System.Net.Http; using System.Threading.Tasks; +using Google.Maps.ApiCore; +using Google.Maps.Internal.Serialization; + namespace Google.Maps.Internal { - public class MapsHttp : IDisposable + public class MapsHttp : IHttpService, IDisposable { JsonSerializerSettings settings = new JsonSerializerSettings { - Converters = new List { new JsonEnumTypeConverter(), new JsonLocationConverter() } + Converters = new List { + new JsonEnumTypeConverter(), + new JsonLatLngConverter() + } }; - GoogleSigned signingSvc; + ISigningService signingSvc; HttpClient client; - public MapsHttp(GoogleSigned signingSvc) + public MapsHttp(ISigningService signingSvc) { this.signingSvc = signingSvc; this.client = new HttpClient(); @@ -47,7 +53,10 @@ public MapsHttp(GoogleSigned signingSvc) public async Task GetAsync(Uri uri) where T : class { - uri = SignUri(uri); + if(this.signingSvc != null) + { + uri = signingSvc.GetSignedUri(uri); + } var json = await client.GetStringAsync(uri).ConfigureAwait(false); @@ -63,7 +72,10 @@ public T Get(Uri uri) where T : class public async Task GetStreamAsync(Uri uri) { - uri = SignUri(uri); + if(this.signingSvc != null) + { + uri = signingSvc.GetSignedUri(uri); + } return await client.GetStreamAsync(uri).ConfigureAwait(false); } @@ -73,13 +85,6 @@ public Stream GetStream(Uri uri) return GetStreamAsync(uri).GetAwaiter().GetResult(); } - Uri SignUri(Uri uri) - { - if (signingSvc == null) return uri; - - return new Uri(signingSvc.GetSignedUri(uri)); - } - public void Dispose() { if (client != null) diff --git a/src/Google.Maps/PolylineEncoder.cs b/src/Google.Maps/Internal/PolylineEncoder.cs similarity index 96% rename from src/Google.Maps/PolylineEncoder.cs rename to src/Google.Maps/Internal/PolylineEncoder.cs index adb6c65..32de408 100644 --- a/src/Google.Maps/PolylineEncoder.cs +++ b/src/Google.Maps/Internal/PolylineEncoder.cs @@ -1,145 +1,145 @@ -/* code reused from SoulSolutions */ -/* retrieved from http://briancaos.wordpress.com/2009/10/16/google-maps-polyline-encoding-in-c/ */ -/* implements the Polyline Encoding Algorithm as defined at - * http://code.google.com/apis/maps/documentation/utilities/polylinealgorithm.html - */ - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Google.Maps -{ - public class PolylineEncoder - { - /// - /// Encodes the list of coordinates to a Google Maps encoded coordinate string. - /// - /// The coordinates. - /// Encoded coordinate string - public static string EncodeCoordinates(IEnumerable coordinates) - { - double oneEFive = Convert.ToDouble(1e5); - - int plat = 0; - int plng = 0; - StringBuilder encodedCoordinates = new StringBuilder(); - - foreach(LatLng coordinate in coordinates) - { - // Round to 5 decimal places and drop the decimal - int late5 = (int)(coordinate.Latitude * oneEFive); - int lnge5 = (int)(coordinate.Longitude * oneEFive); - - // Encode the differences between the coordinates - encodedCoordinates.Append(EncodeSignedNumber(late5 - plat)); - encodedCoordinates.Append(EncodeSignedNumber(lnge5 - plng)); - - // Store the current coordinates - plat = late5; - plng = lnge5; - } - - return encodedCoordinates.ToString(); - } - - /// - /// Decode encoded polyline information to a collection of instances. - /// - /// ASCII string - /// - public static IEnumerable Decode(string value) - { - //decode algorithm adapted from saboor awan via codeproject: - //http://www.codeproject.com/Tips/312248/Google-Maps-Direction-API-V3-Polyline-Decoder - //note the Code Project Open License at http://www.codeproject.com/info/cpol10.aspx - - if(value == null || value == "") return new List(0); - - char[] polylinechars = value.ToCharArray(); - int index = 0; - - int currentLat = 0; - int currentLng = 0; - int next5bits; - int sum; - int shifter; - - List poly = new List(); - - while(index < polylinechars.Length) - { - // calculate next latitude - sum = 0; - shifter = 0; - do - { - next5bits = (int)polylinechars[index++] - 63; - sum |= (next5bits & 31) << shifter; - shifter += 5; - } while(next5bits >= 32 && index < polylinechars.Length); - - if(index >= polylinechars.Length) - break; - - currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1); - - //calculate next longitude - sum = 0; - shifter = 0; - do - { - next5bits = (int)polylinechars[index++] - 63; - sum |= (next5bits & 31) << shifter; - shifter += 5; - } while(next5bits >= 32 && index < polylinechars.Length); - - if(index >= polylinechars.Length && next5bits >= 32) - break; - - currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1); - LatLng point = new LatLng( - latitude: Convert.ToDouble(currentLat) / 100000.0, - longitude: Convert.ToDouble(currentLng) / 100000.0 - ); - poly.Add(point); - } - - return poly; - } - - /// - /// Encode a signed number in the encode format. - /// - /// The signed number - /// The encoded string - private static string EncodeSignedNumber(int num) - { - int sgn_num = num << 1; //shift the binary value - if(num < 0) //if negative invert - { - sgn_num = ~(sgn_num); - } - return (EncodeNumber(sgn_num)); - } - - /// - /// Encode an unsigned number in the encode format. - /// - /// The unsigned number - /// The encoded string - private static string EncodeNumber(int num) - { - StringBuilder encodeString = new StringBuilder(); - while(num >= 0x20) - { - encodeString.Append((char)((0x20 | (num & 0x1f)) + 63)); - num >>= 5; - } - encodeString.Append((char)(num + 63)); - // All backslashes needs to be replaced with double backslashes - // before being used in a Javascript string. - return encodeString.ToString(); - } - } -} +/* code reused from SoulSolutions */ +/* retrieved from http://briancaos.wordpress.com/2009/10/16/google-maps-polyline-encoding-in-c/ */ +/* implements the Polyline Encoding Algorithm as defined at + * http://code.google.com/apis/maps/documentation/utilities/polylinealgorithm.html + */ + +using System; +using System.Collections.Generic; +using System.Text; + +namespace Google.Maps.Internal +{ + public class PolylineEncoder + { + /// + /// Encodes the list of coordinates to a Google Maps encoded coordinate string. + /// + /// The coordinates. + /// Encoded coordinate string + public static string EncodeCoordinates(IEnumerable coordinates) + { + double oneEFive = Convert.ToDouble(1e5); + + int plat = 0; + int plng = 0; + StringBuilder encodedCoordinates = new StringBuilder(); + + foreach(LatLng coordinate in coordinates) + { + // Round to 5 decimal places and drop the decimal + int late5 = (int)(coordinate.Latitude * oneEFive); + int lnge5 = (int)(coordinate.Longitude * oneEFive); + + // Encode the differences between the coordinates + encodedCoordinates.Append(EncodeSignedNumber(late5 - plat)); + encodedCoordinates.Append(EncodeSignedNumber(lnge5 - plng)); + + // Store the current coordinates + plat = late5; + plng = lnge5; + } + + return encodedCoordinates.ToString(); + } + + /// + /// Decode encoded polyline information to a collection of instances. + /// + /// ASCII string + /// + public static IEnumerable Decode(string value) + { + //decode algorithm adapted from saboor awan via codeproject: + //http://www.codeproject.com/Tips/312248/Google-Maps-Direction-API-V3-Polyline-Decoder + //note the Code Project Open License at http://www.codeproject.com/info/cpol10.aspx + + if(value == null || value == "") return new List(0); + + char[] polylinechars = value.ToCharArray(); + int index = 0; + + int currentLat = 0; + int currentLng = 0; + int next5bits; + int sum; + int shifter; + + List poly = new List(); + + while(index < polylinechars.Length) + { + // calculate next latitude + sum = 0; + shifter = 0; + do + { + next5bits = (int)polylinechars[index++] - 63; + sum |= (next5bits & 31) << shifter; + shifter += 5; + } while(next5bits >= 32 && index < polylinechars.Length); + + if(index >= polylinechars.Length) + break; + + currentLat += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1); + + //calculate next longitude + sum = 0; + shifter = 0; + do + { + next5bits = (int)polylinechars[index++] - 63; + sum |= (next5bits & 31) << shifter; + shifter += 5; + } while(next5bits >= 32 && index < polylinechars.Length); + + if(index >= polylinechars.Length && next5bits >= 32) + break; + + currentLng += (sum & 1) == 1 ? ~(sum >> 1) : (sum >> 1); + LatLng point = new LatLng( + latitude: Convert.ToDouble(currentLat) / 100000.0, + longitude: Convert.ToDouble(currentLng) / 100000.0 + ); + poly.Add(point); + } + + return poly; + } + + /// + /// Encode a signed number in the encode format. + /// + /// The signed number + /// The encoded string + private static string EncodeSignedNumber(int num) + { + int sgn_num = num << 1; //shift the binary value + if(num < 0) //if negative invert + { + sgn_num = ~(sgn_num); + } + return (EncodeNumber(sgn_num)); + } + + /// + /// Encode an unsigned number in the encode format. + /// + /// The unsigned number + /// The encoded string + private static string EncodeNumber(int num) + { + StringBuilder encodeString = new StringBuilder(); + while(num >= 0x20) + { + encodeString.Append((char)((0x20 | (num & 0x1f)) + 63)); + num >>= 5; + } + encodeString.Append((char)(num + 63)); + // All backslashes needs to be replaced with double backslashes + // before being used in a Javascript string. + return encodeString.ToString(); + } + } +} diff --git a/src/Google.Maps/Internal/RequestUtils.cs b/src/Google.Maps/Internal/RequestUtils.cs index 467bcca..ed8e1ab 100644 --- a/src/Google.Maps/Internal/RequestUtils.cs +++ b/src/Google.Maps/Internal/RequestUtils.cs @@ -3,6 +3,8 @@ using System.Linq; using System.Text; +using Google.Maps.Common; + namespace Google.Maps.Internal { internal static class RequestUtils diff --git a/src/Google.Maps/JsonCreationConverter.cs b/src/Google.Maps/Internal/Serialization/JsonCreationConverter.cs similarity index 75% rename from src/Google.Maps/JsonCreationConverter.cs rename to src/Google.Maps/Internal/Serialization/JsonCreationConverter.cs index d498832..2d2e2c6 100644 --- a/src/Google.Maps/JsonCreationConverter.cs +++ b/src/Google.Maps/Internal/Serialization/JsonCreationConverter.cs @@ -4,7 +4,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace Google.Maps +namespace Google.Maps.Internal.Serialization { public abstract class JsonCreationConverter : JsonConverter { @@ -31,11 +31,5 @@ public override void WriteJson(JsonWriter writer, object value, } } - public class JsonLocationConverter : JsonCreationConverter - { - protected override Location Create(Type objectType, JObject jsonObject) - { - return new LatLng(jsonObject.Value("lat"), jsonObject.Value("lng")); - } - } + } diff --git a/src/Google.Maps/JsonEnumTypeConverter.cs b/src/Google.Maps/Internal/Serialization/JsonEnumTypeConverter.cs similarity index 95% rename from src/Google.Maps/JsonEnumTypeConverter.cs rename to src/Google.Maps/Internal/Serialization/JsonEnumTypeConverter.cs index 905bec7..3d85396 100644 --- a/src/Google.Maps/JsonEnumTypeConverter.cs +++ b/src/Google.Maps/Internal/Serialization/JsonEnumTypeConverter.cs @@ -1,586 +1,587 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -using System; -using Google.Maps.Geocoding; -using Google.Maps.Shared; -using Newtonsoft.Json; - -namespace Google.Maps -{ - - public class JsonEnumTypeConverter : JsonConverter - { - public static ServiceResponseStatus AsResponseStatus(string s) - { - var result = ServiceResponseStatus.Unknown; - - switch(s) - { - case "OK": - result = ServiceResponseStatus.Ok; - break; - case "ZERO_RESULTS": - result = ServiceResponseStatus.ZeroResults; - break; - case "OVER_QUERY_LIMIT": - result = ServiceResponseStatus.OverQueryLimit; - break; - case "REQUEST_DENIED": - result = ServiceResponseStatus.RequestDenied; - break; - case "INVALID_REQUEST": - result = ServiceResponseStatus.InvalidRequest; - break; - case "MAX_WAYPOINTS_EXCEEDED": - result = ServiceResponseStatus.MaxWaypointsExceeded; - break; - case "NOT_FOUND": - result = ServiceResponseStatus.NotFound; - break; - } - - return result; - } - - public static AddressType AsAddressType(string s) - { - var result = AddressType.Unknown; - - switch(s) - { - case "street_address": - result = AddressType.StreetAddress; - break; - case "route": - result = AddressType.Route; - break; - case "intersection": - result = AddressType.Intersection; - break; - case "political": - result = AddressType.Political; - break; - case "country": - result = AddressType.Country; - break; - case "administrative_area_level_1": - result = AddressType.AdministrativeAreaLevel1; - break; - case "administrative_area_level_2": - result = AddressType.AdministrativeAreaLevel2; - break; - case "administrative_area_level_3": - result = AddressType.AdministrativeAreaLevel3; - break; - case "colloquial_area": - result = AddressType.ColloquialArea; - break; - case "locality": - result = AddressType.Locality; - break; - case "sublocality": - result = AddressType.Sublocality; - break; - case "sublocality_level_1": - result = AddressType.SublocalityLevel1; - break; - case "sublocality_level_2": - result = AddressType.SublocalityLevel2; - break; - case "sublocality_level_3": - result = AddressType.SublocalityLevel3; - break; - case "sublocality_level_4": - result = AddressType.SublocalityLevel4; - break; - case "sublocality_level_5": - result = AddressType.SublocalityLevel5; - break; - case "neighborhood": - result = AddressType.Neighborhood; - break; - case "premise": - result = AddressType.Premise; - break; - case "subpremise": - result = AddressType.Subpremise; - break; - case "postal_code": - result = AddressType.PostalCode; - break; - case "postal_town": - result = AddressType.PostalTown; - break; - case "postal_code_prefix": - result = AddressType.PostalCodePrefix; - break; - case "postal_code_suffix": - result = AddressType.PostalCodeSuffix; - break; - case "natural_feature": - result = AddressType.NaturalFeature; - break; - case "airport": - result = AddressType.Airport; - break; - case "park": - result = AddressType.Park; - break; - case "point_of_interest": - result = AddressType.PointOfInterest; - break; - case "post_box": - result = AddressType.PostBox; - break; - case "street_number": - result = AddressType.StreetNumber; - break; - case "floor": - result = AddressType.Floor; - break; - case "room": - result = AddressType.Room; - break; - } - - return result; - } - - private static Places.PlaceType AsPlaceType(string s) - { - var result = Places.PlaceType.Unknown; - switch(s) - { - case "accounting": - result = Places.PlaceType.Accounting; - break; - case "airport": - result = Places.PlaceType.Airport; - break; - case "amusement_park": - result = Places.PlaceType.AmusementPark; - break; - case "aquarium": - result = Places.PlaceType.Aquarium; - break; - case "art_gallery": - result = Places.PlaceType.ArtGallery; - break; - case "atm": - result = Places.PlaceType.ATM; - break; - case "bakery": - result = Places.PlaceType.Bakery; - break; - case "bank": - result = Places.PlaceType.Bank; - break; - case "bar": - result = Places.PlaceType.Bar; - break; - case "beauty_salon": - result = Places.PlaceType.BeautySalon; - break; - case "bicycle_store": - result = Places.PlaceType.BicycleStore; - break; - case "book_store": - result = Places.PlaceType.BookStore; - break; - case "bowling_alley": - result = Places.PlaceType.BowlingAlley; - break; - case "bus_station": - result = Places.PlaceType.BusStation; - break; - case "cafe": - result = Places.PlaceType.Cafe; - break; - case "campground": - result = Places.PlaceType.Campground; - break; - case "car_dealer": - result = Places.PlaceType.CarDealer; - break; - case "car_rental": - result = Places.PlaceType.CarRental; - break; - case "car_repair": - result = Places.PlaceType.CarRepair; - break; - case "car_wash": - result = Places.PlaceType.CarRepair; - break; - case "casino": - result = Places.PlaceType.Casino; - break; - case "cemetery": - result = Places.PlaceType.Cemetery; - break; - case "church": - result = Places.PlaceType.Church; - break; - case "city_hall": - result = Places.PlaceType.CityHall; - break; - case "clothing_store": - result = Places.PlaceType.ClothingStore; - break; - case "convenience_store": - result = Places.PlaceType.ConvenienceStore; - break; - case "courthouse": - result = Places.PlaceType.CourtHouse; - break; - case "dentist": - result = Places.PlaceType.Dentist; - break; - case "department_store": - result = Places.PlaceType.DepartmentStore; - break; - case "doctor": - result = Places.PlaceType.Doctor; - break; - case "electrician": - result = Places.PlaceType.Electrician; - break; - case "electronics_store": - result = Places.PlaceType.ElectronicsStore; - break; - case "embassy": - result = Places.PlaceType.Embassy; - break; - case "fire_station": - result = Places.PlaceType.FireStation; - break; - case "florist": - result = Places.PlaceType.Florist; - break; - case "funeral_home": - result = Places.PlaceType.FuneralHome; - break; - case "furniture_store": - result = Places.PlaceType.FurnitureStore; - break; - case "gas_station": - result = Places.PlaceType.GasStation; - break; - case "gym": - result = Places.PlaceType.Gym; - break; - case "hair_care": - result = Places.PlaceType.HairCare; - break; - case "hardware_store": - result = Places.PlaceType.HardwareStore; - break; - case "hindu_temple": - result = Places.PlaceType.HinduTemple; - break; - case "home_goods_store": - result = Places.PlaceType.HomeGoodsStore; - break; - case "hospital": - result = Places.PlaceType.Hospital; - break; - case "insurance_agency": - result = Places.PlaceType.InsuranceAgency; - break; - case "jewelry_store": - result = Places.PlaceType.JewelryStore; - break; - case "laundry": - result = Places.PlaceType.Laundry; - break; - case "lawyer": - result = Places.PlaceType.Lawyer; - break; - case "library": - result = Places.PlaceType.Library; - break; - case "liquor_store": - result = Places.PlaceType.LiquorStore; - break; - case "local_government_office": - result = Places.PlaceType.LocalGovermentOffice; - break; - case "locksmith": - result = Places.PlaceType.Locksmith; - break; - case "lodging": - result = Places.PlaceType.Lodging; - break; - case "meal_delivery": - result = Places.PlaceType.MealDelivery; - break; - case "meal_takeaway": - result = Places.PlaceType.MealTakeaway; - break; - case "mosque": - result = Places.PlaceType.Mosque; - break; - case "movie_rental": - result = Places.PlaceType.MovieRental; - break; - case "movie_theater": - result = Places.PlaceType.MovieTheater; - break; - case "moving_company": - result = Places.PlaceType.MovingCompany; - break; - case "museum": - result = Places.PlaceType.Museum; - break; - case "night_club": - result = Places.PlaceType.NightClub; - break; - case "painter": - result = Places.PlaceType.Painter; - break; - case "park": - result = Places.PlaceType.Park; - break; - case "parking": - result = Places.PlaceType.Parking; - break; - case "pet_store": - result = Places.PlaceType.PetStore; - break; - case "pharmacy": - result = Places.PlaceType.Pharmacy; - break; - case "physiotherapist": - result = Places.PlaceType.Physiotherapist; - break; - case "plumber": - result = Places.PlaceType.Plumber; - break; - case "police": - result = Places.PlaceType.Police; - break; - case "post_office": - result = Places.PlaceType.PostOffice; - break; - case "real_estate_agency": - result = Places.PlaceType.RealEstateAgency; - break; - case "restaurant": - result = Places.PlaceType.Restaurant; - break; - case "roofing_contractor": - result = Places.PlaceType.RoofingContractor; - break; - case "rv_park": - result = Places.PlaceType.RVPark; - break; - case "school": - result = Places.PlaceType.School; - break; - case "shoe_store": - result = Places.PlaceType.ShoeStore; - break; - case "shopping_mall": - result = Places.PlaceType.ShoppingMall; - break; - case "spa": - result = Places.PlaceType.Spa; - break; - case "stadium": - result = Places.PlaceType.Stadium; - break; - case "storage": - result = Places.PlaceType.Storage; - break; - case "store": - result = Places.PlaceType.Store; - break; - case "subway_station": - result = Places.PlaceType.SubwayStation; - break; - case "synagogue": - result = Places.PlaceType.Synagogue; - break; - case "taxi_stand": - result = Places.PlaceType.TaxiStand; - break; - case "train_station": - result = Places.PlaceType.TrainStation; - break; - case "travel_agency": - result = Places.PlaceType.TravelAgency; - break; - case "university": - result = Places.PlaceType.University; - break; - case "veterinary_care": - result = Places.PlaceType.VeterinaryCare; - break; - case "zoo": - result = Places.PlaceType.Zoo; - break; - case "administrative_area_level_1": - result = Places.PlaceType.AdministrativeAreaLevel1; - break; - case "administrative_area_level_2": - result = Places.PlaceType.AdministrativeAreaLevel2; - break; - case "administrative_area_level_3": - result = Places.PlaceType.AdministrativeAreaLevel3; - break; - case "colloquial_area": - result = Places.PlaceType.ColloquialArea; - break; - case "country": - result = Places.PlaceType.Country; - break; - case "floor": - result = Places.PlaceType.Floor; - break; - case "geocode": - result = Places.PlaceType.Geocode; - break; - case "intersection": - result = Places.PlaceType.Intersection; - break; - case "locality": - result = Places.PlaceType.Locality; - break; - case "natural_feature": - result = Places.PlaceType.NaturalFeature; - break; - case "neighborhood": - result = Places.PlaceType.Neighborhood; - break; - case "political": - result = Places.PlaceType.Political; - break; - case "point_of_interest": - result = Places.PlaceType.PointOfInterest; - break; - case "post_box": - result = Places.PlaceType.PostBox; - break; - case "postal_code": - result = Places.PlaceType.PostalCode; - break; - case "postal_code_prefix": - result = Places.PlaceType.PostalCodePrefix; - break; - case "postal_town": - result = Places.PlaceType.PostalTown; - break; - case "premise": - result = Places.PlaceType.Premise; - break; - case "room": - result = Places.PlaceType.Room; - break; - case "route": - result = Places.PlaceType.Route; - break; - case "street_address": - result = Places.PlaceType.StreetAddress; - break; - case "street_number": - result = Places.PlaceType.StreetNumber; - break; - case "sublocality": - result = Places.PlaceType.Sublocality; - break; - case "sublocality_level_4": - result = Places.PlaceType.SublocalityLevel4; - break; - case "sublocality_level_5": - result = Places.PlaceType.SublocalityLevel5; - break; - case "sublocality_level_3": - result = Places.PlaceType.SublocalityLevel3; - break; - case "sublocality_level_2": - result = Places.PlaceType.SublocalityLevel2; - break; - case "sublocality_level_1": - result = Places.PlaceType.SublocalityLevel1; - break; - case "subpremise": - result = Places.PlaceType.Subpremise; - break; - case "transit_station": - result = Places.PlaceType.TransitStation; - break; - } - return result; - } - - public static LocationType AsLocationType(string s) - { - var result = LocationType.Unknown; - - switch(s) - { - case "ROOFTOP": - result = LocationType.Rooftop; - break; - case "RANGE_INTERPOLATED": - result = LocationType.RangeInterpolated; - break; - case "GEOMETRIC_CENTER": - result = LocationType.GeometricCenter; - break; - case "APPROXIMATE": - result = LocationType.Approximate; - break; - } - - return result; - } - - public override bool CanConvert(Type objectType) - { - return - objectType == typeof(ServiceResponseStatus) - || objectType == typeof(AddressType) - || objectType == typeof(LocationType) - || objectType == typeof(Places.PlaceType); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - object result = null; - - if(objectType == typeof(ServiceResponseStatus)) - result = AsResponseStatus(reader.Value.ToString()); - - if(objectType == typeof(AddressType)) - result = AsAddressType(reader.Value.ToString()); - - if(objectType == typeof(LocationType)) - result = AsLocationType(reader.Value.ToString()); - - if(objectType == typeof(Places.PlaceType)) - result = AsPlaceType(reader.Value.ToString()); - - return result; - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new System.NotImplementedException(); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +using Newtonsoft.Json; +using Google.Maps; +using Google.Maps.Common; + +namespace Google.Maps.Internal.Serialization +{ + + public class JsonEnumTypeConverter : JsonConverter + { + public static ServiceResponseStatus AsResponseStatus(string s) + { + var result = ServiceResponseStatus.Unknown; + + switch(s) + { + case "OK": + result = ServiceResponseStatus.Ok; + break; + case "ZERO_RESULTS": + result = ServiceResponseStatus.ZeroResults; + break; + case "OVER_QUERY_LIMIT": + result = ServiceResponseStatus.OverQueryLimit; + break; + case "REQUEST_DENIED": + result = ServiceResponseStatus.RequestDenied; + break; + case "INVALID_REQUEST": + result = ServiceResponseStatus.InvalidRequest; + break; + case "MAX_WAYPOINTS_EXCEEDED": + result = ServiceResponseStatus.MaxWaypointsExceeded; + break; + case "NOT_FOUND": + result = ServiceResponseStatus.NotFound; + break; + } + + return result; + } + + public static AddressType AsAddressType(string s) + { + var result = AddressType.Unknown; + + switch(s) + { + case "street_address": + result = AddressType.StreetAddress; + break; + case "route": + result = AddressType.Route; + break; + case "intersection": + result = AddressType.Intersection; + break; + case "political": + result = AddressType.Political; + break; + case "country": + result = AddressType.Country; + break; + case "administrative_area_level_1": + result = AddressType.AdministrativeAreaLevel1; + break; + case "administrative_area_level_2": + result = AddressType.AdministrativeAreaLevel2; + break; + case "administrative_area_level_3": + result = AddressType.AdministrativeAreaLevel3; + break; + case "colloquial_area": + result = AddressType.ColloquialArea; + break; + case "locality": + result = AddressType.Locality; + break; + case "sublocality": + result = AddressType.Sublocality; + break; + case "sublocality_level_1": + result = AddressType.SublocalityLevel1; + break; + case "sublocality_level_2": + result = AddressType.SublocalityLevel2; + break; + case "sublocality_level_3": + result = AddressType.SublocalityLevel3; + break; + case "sublocality_level_4": + result = AddressType.SublocalityLevel4; + break; + case "sublocality_level_5": + result = AddressType.SublocalityLevel5; + break; + case "neighborhood": + result = AddressType.Neighborhood; + break; + case "premise": + result = AddressType.Premise; + break; + case "subpremise": + result = AddressType.Subpremise; + break; + case "postal_code": + result = AddressType.PostalCode; + break; + case "postal_town": + result = AddressType.PostalTown; + break; + case "postal_code_prefix": + result = AddressType.PostalCodePrefix; + break; + case "postal_code_suffix": + result = AddressType.PostalCodeSuffix; + break; + case "natural_feature": + result = AddressType.NaturalFeature; + break; + case "airport": + result = AddressType.Airport; + break; + case "park": + result = AddressType.Park; + break; + case "point_of_interest": + result = AddressType.PointOfInterest; + break; + case "post_box": + result = AddressType.PostBox; + break; + case "street_number": + result = AddressType.StreetNumber; + break; + case "floor": + result = AddressType.Floor; + break; + case "room": + result = AddressType.Room; + break; + } + + return result; + } + + private static Places.PlaceType AsPlaceType(string s) + { + var result = Places.PlaceType.Unknown; + switch(s) + { + case "accounting": + result = Places.PlaceType.Accounting; + break; + case "airport": + result = Places.PlaceType.Airport; + break; + case "amusement_park": + result = Places.PlaceType.AmusementPark; + break; + case "aquarium": + result = Places.PlaceType.Aquarium; + break; + case "art_gallery": + result = Places.PlaceType.ArtGallery; + break; + case "atm": + result = Places.PlaceType.ATM; + break; + case "bakery": + result = Places.PlaceType.Bakery; + break; + case "bank": + result = Places.PlaceType.Bank; + break; + case "bar": + result = Places.PlaceType.Bar; + break; + case "beauty_salon": + result = Places.PlaceType.BeautySalon; + break; + case "bicycle_store": + result = Places.PlaceType.BicycleStore; + break; + case "book_store": + result = Places.PlaceType.BookStore; + break; + case "bowling_alley": + result = Places.PlaceType.BowlingAlley; + break; + case "bus_station": + result = Places.PlaceType.BusStation; + break; + case "cafe": + result = Places.PlaceType.Cafe; + break; + case "campground": + result = Places.PlaceType.Campground; + break; + case "car_dealer": + result = Places.PlaceType.CarDealer; + break; + case "car_rental": + result = Places.PlaceType.CarRental; + break; + case "car_repair": + result = Places.PlaceType.CarRepair; + break; + case "car_wash": + result = Places.PlaceType.CarRepair; + break; + case "casino": + result = Places.PlaceType.Casino; + break; + case "cemetery": + result = Places.PlaceType.Cemetery; + break; + case "church": + result = Places.PlaceType.Church; + break; + case "city_hall": + result = Places.PlaceType.CityHall; + break; + case "clothing_store": + result = Places.PlaceType.ClothingStore; + break; + case "convenience_store": + result = Places.PlaceType.ConvenienceStore; + break; + case "courthouse": + result = Places.PlaceType.CourtHouse; + break; + case "dentist": + result = Places.PlaceType.Dentist; + break; + case "department_store": + result = Places.PlaceType.DepartmentStore; + break; + case "doctor": + result = Places.PlaceType.Doctor; + break; + case "electrician": + result = Places.PlaceType.Electrician; + break; + case "electronics_store": + result = Places.PlaceType.ElectronicsStore; + break; + case "embassy": + result = Places.PlaceType.Embassy; + break; + case "fire_station": + result = Places.PlaceType.FireStation; + break; + case "florist": + result = Places.PlaceType.Florist; + break; + case "funeral_home": + result = Places.PlaceType.FuneralHome; + break; + case "furniture_store": + result = Places.PlaceType.FurnitureStore; + break; + case "gas_station": + result = Places.PlaceType.GasStation; + break; + case "gym": + result = Places.PlaceType.Gym; + break; + case "hair_care": + result = Places.PlaceType.HairCare; + break; + case "hardware_store": + result = Places.PlaceType.HardwareStore; + break; + case "hindu_temple": + result = Places.PlaceType.HinduTemple; + break; + case "home_goods_store": + result = Places.PlaceType.HomeGoodsStore; + break; + case "hospital": + result = Places.PlaceType.Hospital; + break; + case "insurance_agency": + result = Places.PlaceType.InsuranceAgency; + break; + case "jewelry_store": + result = Places.PlaceType.JewelryStore; + break; + case "laundry": + result = Places.PlaceType.Laundry; + break; + case "lawyer": + result = Places.PlaceType.Lawyer; + break; + case "library": + result = Places.PlaceType.Library; + break; + case "liquor_store": + result = Places.PlaceType.LiquorStore; + break; + case "local_government_office": + result = Places.PlaceType.LocalGovermentOffice; + break; + case "locksmith": + result = Places.PlaceType.Locksmith; + break; + case "lodging": + result = Places.PlaceType.Lodging; + break; + case "meal_delivery": + result = Places.PlaceType.MealDelivery; + break; + case "meal_takeaway": + result = Places.PlaceType.MealTakeaway; + break; + case "mosque": + result = Places.PlaceType.Mosque; + break; + case "movie_rental": + result = Places.PlaceType.MovieRental; + break; + case "movie_theater": + result = Places.PlaceType.MovieTheater; + break; + case "moving_company": + result = Places.PlaceType.MovingCompany; + break; + case "museum": + result = Places.PlaceType.Museum; + break; + case "night_club": + result = Places.PlaceType.NightClub; + break; + case "painter": + result = Places.PlaceType.Painter; + break; + case "park": + result = Places.PlaceType.Park; + break; + case "parking": + result = Places.PlaceType.Parking; + break; + case "pet_store": + result = Places.PlaceType.PetStore; + break; + case "pharmacy": + result = Places.PlaceType.Pharmacy; + break; + case "physiotherapist": + result = Places.PlaceType.Physiotherapist; + break; + case "plumber": + result = Places.PlaceType.Plumber; + break; + case "police": + result = Places.PlaceType.Police; + break; + case "post_office": + result = Places.PlaceType.PostOffice; + break; + case "real_estate_agency": + result = Places.PlaceType.RealEstateAgency; + break; + case "restaurant": + result = Places.PlaceType.Restaurant; + break; + case "roofing_contractor": + result = Places.PlaceType.RoofingContractor; + break; + case "rv_park": + result = Places.PlaceType.RVPark; + break; + case "school": + result = Places.PlaceType.School; + break; + case "shoe_store": + result = Places.PlaceType.ShoeStore; + break; + case "shopping_mall": + result = Places.PlaceType.ShoppingMall; + break; + case "spa": + result = Places.PlaceType.Spa; + break; + case "stadium": + result = Places.PlaceType.Stadium; + break; + case "storage": + result = Places.PlaceType.Storage; + break; + case "store": + result = Places.PlaceType.Store; + break; + case "subway_station": + result = Places.PlaceType.SubwayStation; + break; + case "synagogue": + result = Places.PlaceType.Synagogue; + break; + case "taxi_stand": + result = Places.PlaceType.TaxiStand; + break; + case "train_station": + result = Places.PlaceType.TrainStation; + break; + case "travel_agency": + result = Places.PlaceType.TravelAgency; + break; + case "university": + result = Places.PlaceType.University; + break; + case "veterinary_care": + result = Places.PlaceType.VeterinaryCare; + break; + case "zoo": + result = Places.PlaceType.Zoo; + break; + case "administrative_area_level_1": + result = Places.PlaceType.AdministrativeAreaLevel1; + break; + case "administrative_area_level_2": + result = Places.PlaceType.AdministrativeAreaLevel2; + break; + case "administrative_area_level_3": + result = Places.PlaceType.AdministrativeAreaLevel3; + break; + case "colloquial_area": + result = Places.PlaceType.ColloquialArea; + break; + case "country": + result = Places.PlaceType.Country; + break; + case "floor": + result = Places.PlaceType.Floor; + break; + case "geocode": + result = Places.PlaceType.Geocode; + break; + case "intersection": + result = Places.PlaceType.Intersection; + break; + case "locality": + result = Places.PlaceType.Locality; + break; + case "natural_feature": + result = Places.PlaceType.NaturalFeature; + break; + case "neighborhood": + result = Places.PlaceType.Neighborhood; + break; + case "political": + result = Places.PlaceType.Political; + break; + case "point_of_interest": + result = Places.PlaceType.PointOfInterest; + break; + case "post_box": + result = Places.PlaceType.PostBox; + break; + case "postal_code": + result = Places.PlaceType.PostalCode; + break; + case "postal_code_prefix": + result = Places.PlaceType.PostalCodePrefix; + break; + case "postal_town": + result = Places.PlaceType.PostalTown; + break; + case "premise": + result = Places.PlaceType.Premise; + break; + case "room": + result = Places.PlaceType.Room; + break; + case "route": + result = Places.PlaceType.Route; + break; + case "street_address": + result = Places.PlaceType.StreetAddress; + break; + case "street_number": + result = Places.PlaceType.StreetNumber; + break; + case "sublocality": + result = Places.PlaceType.Sublocality; + break; + case "sublocality_level_4": + result = Places.PlaceType.SublocalityLevel4; + break; + case "sublocality_level_5": + result = Places.PlaceType.SublocalityLevel5; + break; + case "sublocality_level_3": + result = Places.PlaceType.SublocalityLevel3; + break; + case "sublocality_level_2": + result = Places.PlaceType.SublocalityLevel2; + break; + case "sublocality_level_1": + result = Places.PlaceType.SublocalityLevel1; + break; + case "subpremise": + result = Places.PlaceType.Subpremise; + break; + case "transit_station": + result = Places.PlaceType.TransitStation; + break; + } + return result; + } + + public static LocationType AsLocationType(string s) + { + var result = LocationType.Unknown; + + switch(s) + { + case "ROOFTOP": + result = LocationType.Rooftop; + break; + case "RANGE_INTERPOLATED": + result = LocationType.RangeInterpolated; + break; + case "GEOMETRIC_CENTER": + result = LocationType.GeometricCenter; + break; + case "APPROXIMATE": + result = LocationType.Approximate; + break; + } + + return result; + } + + public override bool CanConvert(Type objectType) + { + return + objectType == typeof(ServiceResponseStatus) + || objectType == typeof(AddressType) + || objectType == typeof(LocationType) + || objectType == typeof(Places.PlaceType); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + object result = null; + + if(objectType == typeof(ServiceResponseStatus)) + result = AsResponseStatus(reader.Value.ToString()); + + if(objectType == typeof(AddressType)) + result = AsAddressType(reader.Value.ToString()); + + if(objectType == typeof(LocationType)) + result = AsLocationType(reader.Value.ToString()); + + if(objectType == typeof(Places.PlaceType)) + result = AsPlaceType(reader.Value.ToString()); + + return result; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/src/Google.Maps/Internal/Serialization/JsonLocationConverter.cs b/src/Google.Maps/Internal/Serialization/JsonLocationConverter.cs new file mode 100644 index 0000000..46111ac --- /dev/null +++ b/src/Google.Maps/Internal/Serialization/JsonLocationConverter.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Newtonsoft.Json.Linq; + +namespace Google.Maps.Internal.Serialization +{ + public class JsonLatLngConverter : JsonCreationConverter + { + protected override Location Create(Type objectType, JObject jsonObject) + { + return new LatLng(jsonObject.Value("lat"), jsonObject.Value("lng")); + } + } + +} diff --git a/src/Google.Maps/Internal/ValueTextComparer.cs b/src/Google.Maps/Internal/ValueTextComparer.cs index 1dc5a15..aea1af9 100644 --- a/src/Google.Maps/Internal/ValueTextComparer.cs +++ b/src/Google.Maps/Internal/ValueTextComparer.cs @@ -3,7 +3,10 @@ using System.Linq; using System.Text; -namespace Google.Maps +using Newtonsoft.Json; +using Google.Maps.Common; + +namespace Google.Maps.Internal { public class ValueTextComparer : IComparer { diff --git a/src/Google.Maps/MapMarker.cs b/src/Google.Maps/MapMarker.cs index d89aaf4..e01e5b6 100644 --- a/src/Google.Maps/MapMarker.cs +++ b/src/Google.Maps/MapMarker.cs @@ -3,6 +3,8 @@ using System.Text; using System.ComponentModel; +using Google.Maps.Common; + namespace Google.Maps { @@ -45,7 +47,7 @@ public MapMarkers(params Location[] locations) /// or a predefined color from the set {black, brown, green, purple, yellow, blue, gray, orange, red, white}. /// (optional) /// - public MapColor Color { get; set; } + public GColor Color { get; set; } /// diff --git a/src/Google.Maps/MapSize.cs b/src/Google.Maps/MapSize.cs deleted file mode 100644 index b909e38..0000000 --- a/src/Google.Maps/MapSize.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Google.Maps -{ - public struct MapSize - { - public MapSize(int width, int height) - { - this.Width = width; - this.Height = height; - } - - public int Width { get; set; } - - public int Height { get; set; } - -#if HAS_SYSTEMDRAWING - public static implicit operator MapSize(System.Drawing.Size systemSize) - { - return new MapSize(systemSize.Width, systemSize.Height); - } -#endif - - } -} \ No newline at end of file diff --git a/src/Google.Maps/MapTypes.cs b/src/Google.Maps/MapTypes.cs index f795241..dedaab3 100644 --- a/src/Google.Maps/MapTypes.cs +++ b/src/Google.Maps/MapTypes.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Google.Maps +namespace Google.Maps.Common { /// /// The available map types for the current Google Maps API. diff --git a/src/Google.Maps/MarkerSizes.cs b/src/Google.Maps/MarkerSizes.cs index 31e49e7..698b8f9 100644 --- a/src/Google.Maps/MarkerSizes.cs +++ b/src/Google.Maps/MarkerSizes.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Google.Maps +namespace Google.Maps.Common { /// /// The set of marker sizes available for the current Google Maps API. diff --git a/src/Google.Maps/Path.cs b/src/Google.Maps/Path.cs index f67eddb..1195274 100644 --- a/src/Google.Maps/Path.cs +++ b/src/Google.Maps/Path.cs @@ -3,6 +3,8 @@ using System.Text; using System.ComponentModel; +using Google.Maps.Common; + namespace Google.Maps { public class Path @@ -31,7 +33,7 @@ public Path(params Location[] locations) /// (optional) specifies a color either as a 24-bit (example: color=0xFFFFCC) or 32-bit hexadecimal value (example: color=0xFFFFCCFF), /// or from the set {black, brown, green, purple, yellow, blue, gray, orange, red, white}. Default opacity appears to be 50%. /// - public MapColor Color { get; set; } + public GColor Color { get; set; } /// /// indicates both that the path marks off a polygonal area and specifies the fill color to use as an overlay within that area. The @@ -39,7 +41,7 @@ public Path(params Location[] locations) /// Note, however, that any stroke on the exterior of the filled area will not be closed unless you specifically provide the same /// beginning and end location. /// - public MapColor FillColor { get; set; } + public GColor FillColor { get; set; } /// /// Gets or sets the collection of points for this path diff --git a/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs b/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs index 5f0e9e8..48b663a 100644 --- a/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs +++ b/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs @@ -4,6 +4,8 @@ using System.Text; using Google.Maps.Internal; +using Google.Maps.ApiCore; + namespace Google.Maps.Places { public class AutocompleteRequest : BaseRequest { diff --git a/src/Google.Maps/Places/Autocomplete/AutocompleteResponse.cs b/src/Google.Maps/Places/Autocomplete/AutocompleteResponse.cs index 9b72a35..64b7959 100644 --- a/src/Google.Maps/Places/Autocomplete/AutocompleteResponse.cs +++ b/src/Google.Maps/Places/Autocomplete/AutocompleteResponse.cs @@ -1,9 +1,11 @@ -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; +using Newtonsoft.Json; +using Google.Maps.Common; + namespace Google.Maps.Places { public class AutocompleteResponse diff --git a/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs b/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs index 9184627..db2794d 100644 --- a/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs +++ b/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs @@ -3,6 +3,8 @@ using System.Linq; using System.Text; +using Google.Maps.ApiCore; + namespace Google.Maps.Places.Details { public class PlaceDetailsRequest : BaseRequest diff --git a/src/Google.Maps/Places/Details/PlaceDetailsResponse.cs b/src/Google.Maps/Places/Details/PlaceDetailsResponse.cs index 4a64671..69b26bf 100644 --- a/src/Google.Maps/Places/Details/PlaceDetailsResponse.cs +++ b/src/Google.Maps/Places/Details/PlaceDetailsResponse.cs @@ -1,9 +1,11 @@ -using Newtonsoft.Json; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; +using Newtonsoft.Json; +using Google.Maps.Common; + namespace Google.Maps.Places.Details { public class PlaceDetailsResponse diff --git a/src/Google.Maps/Places/Details/PlaceDetailsResult.cs b/src/Google.Maps/Places/Details/PlaceDetailsResult.cs index bd135ad..17a9ae0 100644 --- a/src/Google.Maps/Places/Details/PlaceDetailsResult.cs +++ b/src/Google.Maps/Places/Details/PlaceDetailsResult.cs @@ -1,5 +1,6 @@ -using Google.Maps.Shared; + using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.Places.Details { diff --git a/src/Google.Maps/Places/Details/PlaceDetailsService.cs b/src/Google.Maps/Places/Details/PlaceDetailsService.cs index f4cfe40..47d1d83 100644 --- a/src/Google.Maps/Places/Details/PlaceDetailsService.cs +++ b/src/Google.Maps/Places/Details/PlaceDetailsService.cs @@ -18,55 +18,22 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.Places.Details { /// /// Provides a direct way to access Places Details via an HTTP request. /// - public class PlaceDetailsService : IDisposable + public class PlaceDetailsService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.googleapis.com/maps/api/place/details/"); - Uri baseUri; - MapsHttp http; - - public PlaceDetailsService(GoogleSigned signingSvc = null, Uri baseUri = null) + public PlaceDetailsService(IHttpService httpService, Uri baseUri) { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); - } - - - /// - /// Sends the specified request to the Google Maps Places web - /// service and parses the response as an PlaceDetailsResponse - /// object. - /// - /// - /// - public PlaceDetailsResponse GetResponse(PlaceDetailsRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return http.Get(url); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } - public async Task GetResponseAsync(PlaceDetailsRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return await http.GetAsync(url); - } - - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/Places/NearbySearchRequest.cs b/src/Google.Maps/Places/NearbySearchRequest.cs index fec1359..c4ed36e 100644 --- a/src/Google.Maps/Places/NearbySearchRequest.cs +++ b/src/Google.Maps/Places/NearbySearchRequest.cs @@ -18,6 +18,8 @@ using System; using System.Linq; +using Google.Maps.Common; + namespace Google.Maps.Places { /// @@ -77,7 +79,7 @@ public override Uri ToUri() qsb.Append("location", Location.GetAsUrlParameter()); - if(RankBy.GetValueOrDefault(Maps.RankBy.Prominence) != Maps.RankBy.Distance) + if(RankBy.GetValueOrDefault(Google.Maps.Common.RankBy.Prominence) != Google.Maps.Common.RankBy.Distance) { // Note that radius must not be included if rankby=distance qsb.Append("radius", Radius.ToString()); @@ -142,11 +144,11 @@ protected override void ValidateRequest() if(Location == null) throw new InvalidOperationException("Location property is not set"); - if(RankBy != null && RankBy != Maps.RankBy.Distance) + if(RankBy != null && RankBy != Google.Maps.Common.RankBy.Distance) { if(!Radius.HasValue) throw new ArgumentException("Radius property is not set."); } - else if(RankBy != null && RankBy == Maps.RankBy.Distance) + else if(RankBy != null && RankBy == Google.Maps.Common.RankBy.Distance) { if(string.IsNullOrEmpty(Keyword) && string.IsNullOrEmpty(Name) && (Types == null || !Types.Any())) { diff --git a/src/Google.Maps/Places/PlacesRequest.cs b/src/Google.Maps/Places/PlacesRequest.cs index 3fe23ca..c33f704 100644 --- a/src/Google.Maps/Places/PlacesRequest.cs +++ b/src/Google.Maps/Places/PlacesRequest.cs @@ -18,6 +18,9 @@ using System; using System.Linq; +using Google.Maps.ApiCore; + + namespace Google.Maps.Places { public abstract class PlacesRequest : BaseRequest diff --git a/src/Google.Maps/Places/PlacesResponse.cs b/src/Google.Maps/Places/PlacesResponse.cs index 0e8c2e5..855fb5f 100644 --- a/src/Google.Maps/Places/PlacesResponse.cs +++ b/src/Google.Maps/Places/PlacesResponse.cs @@ -17,6 +17,7 @@ using Google.Maps.Common; using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.Places { diff --git a/src/Google.Maps/Places/PlacesResult.cs b/src/Google.Maps/Places/PlacesResult.cs index 315948c..41cf49c 100644 --- a/src/Google.Maps/Places/PlacesResult.cs +++ b/src/Google.Maps/Places/PlacesResult.cs @@ -15,9 +15,9 @@ * limitations under the License. */ -using Google.Maps.Shared; using Newtonsoft.Json; using System; +using Google.Maps.Common; namespace Google.Maps.Places { diff --git a/src/Google.Maps/Places/PlacesService.cs b/src/Google.Maps/Places/PlacesService.cs index d890bc1..70fe880 100644 --- a/src/Google.Maps/Places/PlacesService.cs +++ b/src/Google.Maps/Places/PlacesService.cs @@ -18,6 +18,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.Places { @@ -27,41 +28,19 @@ namespace Google.Maps.Places /// points of interest, geographic locations, and more. You can search /// for places either by proximity or a text string. /// - public class PlacesService : IDisposable + public class PlacesService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.googleapis.com/maps/api/place/"); - public static readonly Uri HttpUri = new Uri("http://maps.googleapis.com/maps/api/place/"); Uri baseUri; MapsHttp http; - public PlacesService(GoogleSigned signingSvc = null, Uri baseUri = null) + public PlacesService(IHttpService httpService, Uri baseUri) { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } - /// - /// Sends the specified request to the Google Maps Geocoding web - /// service and parses the response as an GeocodingResponse - /// object. - /// - /// - /// - public PlacesResponse GetResponse(TRequest request) where TRequest : PlacesRequest - { - var url = new Uri(baseUri, request.ToUri()); - - return http.Get(url); - } - - public async Task GetResponseAsync(TRequest request) where TRequest : PlacesRequest - { - var url = new Uri(baseUri, request.ToUri()); - - return await http.GetAsync(url); - } /// /// Sends the specified request to the Google Maps Places Autocomplate web @@ -84,13 +63,5 @@ public async Task GetAutocompleteResponseAsync(Autocomplet return await http.GetAsync(url); } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/Places/TextSearchRequest.cs b/src/Google.Maps/Places/TextSearchRequest.cs index 7baed48..519c23f 100644 --- a/src/Google.Maps/Places/TextSearchRequest.cs +++ b/src/Google.Maps/Places/TextSearchRequest.cs @@ -18,6 +18,9 @@ using System; using System.Linq; +using Google.Maps; +using Google.Maps.Common; + namespace Google.Maps.Places { /// diff --git a/src/Google.Maps/Roads/RoadsService.cs b/src/Google.Maps/Roads/RoadsService.cs index 1f314b3..376e786 100644 --- a/src/Google.Maps/Roads/RoadsService.cs +++ b/src/Google.Maps/Roads/RoadsService.cs @@ -2,44 +2,21 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.Roads { - public class RoadsService : IDisposable + + public class RoadsService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://roads.googleapis.com/v1/"); - Uri baseUri; - MapsHttp http; - - public RoadsService(GoogleSigned signingSvc = null, Uri baseUri = null) - { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); - } - - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } - - public SnapToRoadsResponse GetResponse(SnapToRoadsRequest request) + public RoadsService(IHttpService httpService, Uri baseUri) { - var url = new Uri(baseUri, request.ToUri()); - - return http.Get(url); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } - public async Task GetResponseAsync(SnapToRoadsRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return await http.GetAsync(url); - } } + } \ No newline at end of file diff --git a/src/Google.Maps/Roads/SnapToRoadsRequest.cs b/src/Google.Maps/Roads/SnapToRoadsRequest.cs index 2beefc0..b3c7784 100644 --- a/src/Google.Maps/Roads/SnapToRoadsRequest.cs +++ b/src/Google.Maps/Roads/SnapToRoadsRequest.cs @@ -1,10 +1,12 @@ using System; using System.Linq; +using Google.Maps.ApiCore; + namespace Google.Maps.Roads { public class SnapToRoadsRequest: BaseRequest - { + { /// /// The path to be snapped. /// diff --git a/src/Google.Maps/StaticMaps/StaticMapRequest.cs b/src/Google.Maps/StaticMaps/StaticMapRequest.cs index 17f29e4..40626e4 100644 --- a/src/Google.Maps/StaticMaps/StaticMapRequest.cs +++ b/src/Google.Maps/StaticMaps/StaticMapRequest.cs @@ -20,6 +20,8 @@ using System.Collections.Generic; using Google.Maps.Internal; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.StaticMaps { @@ -34,7 +36,7 @@ public class StaticMapRequest : BaseRequest { public StaticMapRequest() { - this.Size = new MapSize(512, 512); //default size is 512x512 + this.Size = new GSize(512, 512); //default size is 512x512 this.Visible = new List(1); this.Markers = new MapMarkersCollection(); this.Paths = new List(); @@ -82,7 +84,7 @@ public int? Zoom /// create a static map that is 100 pixels wide or smaller, the /// "Powered by Google" logo is automatically reduced in size. (required) /// - public MapSize Size + public GSize Size { get { return _size; } set @@ -94,7 +96,7 @@ public MapSize Size this._size = value; } } - private MapSize _size; + private GSize _size; /// /// affects the number of pixels that are returned. scale=2 returns twice as many pixels as scale=1 @@ -126,7 +128,7 @@ public int? Scale /// greater compression, while GIF and PNG provide greater detail. (optional) /// /// http://code.google.com/apis/maps/documentation/staticmaps/#ImageFormats - public GMapsImageFormats Format { get; set; } + public MapImageFormats Format { get; set; } /// /// Defines the type of map to construct. There are several possible @@ -205,8 +207,8 @@ public override Uri ToUri() string formatStr = null; switch(this.Format) { - case GMapsImageFormats.Unspecified: break; - case GMapsImageFormats.JPGbaseline: formatStr = "jpg-baseline"; break; + case MapImageFormats.Unspecified: break; + case MapImageFormats.JPGbaseline: formatStr = "jpg-baseline"; break; default: formatStr = this.Format.ToString().ToLower(); break; } diff --git a/src/Google.Maps/StaticMaps/StaticMapService.cs b/src/Google.Maps/StaticMaps/StaticMapService.cs index 467c4ee..b6e27c8 100644 --- a/src/Google.Maps/StaticMaps/StaticMapService.cs +++ b/src/Google.Maps/StaticMaps/StaticMapService.cs @@ -19,6 +19,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.StaticMaps { @@ -28,19 +29,14 @@ namespace Google.Maps.StaticMaps /// map as an image you can display on your web page. /// /// - public class StaticMapService : IDisposable + public class StaticMapService : ApiCore.BaseGmapsService { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api"); - public static readonly Uri HttpUri = new Uri("http://maps.google.com/maps/api"); - Uri baseUri; - MapsHttp http; - - public StaticMapService(GoogleSigned signingSvc = null, Uri baseUri = null) + public StaticMapService(IHttpService httpService, Uri baseUri) { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } public byte[] GetImage(StaticMapRequest request) @@ -59,16 +55,16 @@ public async Task GetImageAsync(StaticMapRequest request) public Stream GetStream(StaticMapRequest request) { - var uri = new Uri(baseUri, request.ToUri()); + var uri = new Uri(BaseUri, request.ToUri()); - return http.GetStream(uri); + return HttpService.GetStream(uri); } public Task GetStreamAsync(StaticMapRequest request) { - var uri = new Uri(baseUri, request.ToUri()); + var uri = new Uri(BaseUri, request.ToUri()); - return http.GetStreamAsync(uri); + return HttpService.GetStreamAsync(uri); } Byte[] StreamToArray(Stream inputStream) @@ -91,13 +87,5 @@ Byte[] StreamToArray(Stream inputStream) return result; } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/StreetView/StreetViewRequest.cs b/src/Google.Maps/StreetView/StreetViewRequest.cs index 619f644..0719d75 100644 --- a/src/Google.Maps/StreetView/StreetViewRequest.cs +++ b/src/Google.Maps/StreetView/StreetViewRequest.cs @@ -19,9 +19,12 @@ using System.Linq; using System.Collections.Generic; +using Google.Maps.ApiCore; +using Google.Maps.Common; using Google.Maps.Internal; using System.ComponentModel; + namespace Google.Maps.StreetView { /// @@ -35,14 +38,14 @@ public class StreetViewRequest : StreetViewBase { public StreetViewRequest() { - this.Size = new MapSize(512, 512); //default size is 512x512 + this.Size = new GSize(512, 512); //default size is 512x512 } /// /// Size specifies the output size of the image in pixels. /// For example Size = new MapSize(600,400) returns an image 600 pixels wide, and 400 high. /// - public MapSize Size + public GSize Size { get { return _size; } set @@ -54,7 +57,7 @@ public MapSize Size this._size = value; } } - private MapSize _size; + private GSize _size; /// /// Defines the format of the resulting image. By default, the Static @@ -64,7 +67,7 @@ public MapSize Size /// greater compression, while GIF and PNG provide greater detail. (optional) /// /// http://code.google.com/apis/maps/documentation/staticmaps/#ImageFormats - public GMapsImageFormats Format { get; set; } + public MapImageFormats Format { get; set; } /// /// Heading indicates the compass heading of the camera. Accepted values are from 0 to 360 @@ -178,8 +181,8 @@ private void WriteBitmapOutputParameters(QueryStringBuilder qs) string formatStr = null; switch(this.Format) { - case GMapsImageFormats.Unspecified: break; - case GMapsImageFormats.JPGbaseline: formatStr = "jpg-baseline"; break; + case MapImageFormats.Unspecified: break; + case MapImageFormats.JPGbaseline: formatStr = "jpg-baseline"; break; default: formatStr = this.Format.ToString().ToLower(); break; } diff --git a/src/Google.Maps/StreetView/StreetViewService.cs b/src/Google.Maps/StreetView/StreetViewService.cs index da7b277..191e93d 100644 --- a/src/Google.Maps/StreetView/StreetViewService.cs +++ b/src/Google.Maps/StreetView/StreetViewService.cs @@ -22,26 +22,17 @@ namespace Google.Maps.StreetView { + /// /// The Google Street View Image API lets you embed a static (non-interactive) Street View panorama or thumbnail /// into your web page, without the use of JavaScript. The viewport is defined with URL parameters sent through /// a standard HTTP request, and is returned as a static image. /// /// - public class StreetViewService : IDisposable + public class StreetViewService : ApiCore.BaseGmapsService { public static readonly Uri HttpsUri = new Uri("https://maps.googleapis.com/maps/api/streetview"); - Uri baseUri; - MapsHttp http; - - public StreetViewService(GoogleSigned signingSvc = null, Uri baseUri = null) - { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); - } - public byte[] GetImage(StreetViewRequest request) { var stream = GetStream(request); @@ -65,16 +56,16 @@ public StreetViewMetadataResponse GetMetadataResponse(StreetViewMetadataRequest public Stream GetStream(StreetViewRequest request) { - var uri = new Uri(baseUri, request.ToUri()); + var uri = new Uri(BaseUri, request.ToUri()); - return http.GetStream(uri); + return HttpService.GetStream(uri); } public Task GetStreamAsync(StreetViewRequest request) { - var uri = new Uri(baseUri, request.ToUri()); + var uri = new Uri(BaseUri, request.ToUri()); - return http.GetStreamAsync(uri); + return HttpService.GetStreamAsync(uri); } Byte[] StreamToArray(Stream inputStream) @@ -97,13 +88,5 @@ Byte[] StreamToArray(Stream inputStream) return result; } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/TimeZone/TimeZoneRequest.cs b/src/Google.Maps/TimeZone/TimeZoneRequest.cs index e4c65fb..0fec422 100644 --- a/src/Google.Maps/TimeZone/TimeZoneRequest.cs +++ b/src/Google.Maps/TimeZone/TimeZoneRequest.cs @@ -16,6 +16,8 @@ */ using System; +using Google.Maps.ApiCore; + namespace Google.Maps.TimeZone { /// diff --git a/src/Google.Maps/TimeZone/TimeZoneResponse.cs b/src/Google.Maps/TimeZone/TimeZoneResponse.cs index e28636c..dc04dd9 100644 --- a/src/Google.Maps/TimeZone/TimeZoneResponse.cs +++ b/src/Google.Maps/TimeZone/TimeZoneResponse.cs @@ -15,10 +15,12 @@ * limitations under the License. */ -using Newtonsoft.Json; using System; using Google.Maps.Common; +using Newtonsoft.Json; +using Google.Maps.Common; + namespace Google.Maps.TimeZone { [JsonObject(MemberSerialization.OptIn)] diff --git a/src/Google.Maps/TimeZone/TimeZoneService.cs b/src/Google.Maps/TimeZone/TimeZoneService.cs index 7a7df04..040b1d0 100644 --- a/src/Google.Maps/TimeZone/TimeZoneService.cs +++ b/src/Google.Maps/TimeZone/TimeZoneService.cs @@ -18,54 +18,22 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; namespace Google.Maps.TimeZone { /// /// Provides a direct way to access a time zone service via an HTTP request. /// - public class TimeZoneService : IDisposable + public class TimeZoneService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.googleapis.com/maps/api/timezone/outputFormat?parameters"); - Uri baseUri; - MapsHttp http; - - public TimeZoneService(GoogleSigned signingSvc = null, Uri baseUri = null) - { - this.baseUri = baseUri ?? HttpsUri; - - this.http = new MapsHttp(signingSvc ?? GoogleSigned.SigningInstance); - } - - /// - /// Sends the specified request to the Google Maps Time Zone web - /// service and parses the response as an TimeZoneResponse - /// object. - /// - /// - /// - public TimeZoneResponse GetResponse(TimeZoneRequest request) - { - var url = new Uri(baseUri, request.ToUri()); - - return http.Get(url); - } - - public async Task GetResponseAsync(TimeZoneRequest request) + public TimeZoneService(IHttpService httpService, Uri baseUri) { - var url = new Uri(baseUri, request.ToUri()); - - return await http.GetAsync(url); + this.HttpService = httpService; + this.BaseUri = (baseUri != null ? baseUri : HttpsUri); } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/_Services.cs b/src/Google.Maps/_Services.cs new file mode 100644 index 0000000..a42df08 --- /dev/null +++ b/src/Google.Maps/_Services.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Google.Maps.ApiCore; + +namespace Google.Maps +{ + + /// + /// Easy to use facade for all the services + /// + public class Services + { + public Services(string apiKey) : this(new GoogleSigned(apiKey)) + { + } + + public Services(GoogleSigned signingInstance) + { + this._SigningService = new GoogleApiSigningService(signingInstance); + this._HttpService = new Google.Maps.Internal.MapsHttp(this._SigningService); + } + + public Services WithSigningService(ISigningService signingService) + { + this._SigningService = signingService; + return this; + } + public Services WithHttpService(IHttpService httpService) + { + this._HttpService = httpService; + return this; + } + + private GoogleSigned _signingInstance; + private ISigningService _SigningService; + private IHttpService _HttpService; + + public ISigningService SigningService { get { return this._SigningService; } } + public IHttpService HttpService { get { return this._HttpService; } } + + + public Direction.DirectionService DirectionService + { + get { return new Direction.DirectionService(HttpService, null); } + } + public Geocoding.GeocodingService GeocodingService + { + get { return new Geocoding.GeocodingService(HttpService, null); } + } + public StaticMaps.StaticMapService StaticMapsService + { + get { return new StaticMaps.StaticMapService(HttpService, null); } + } + + + } +} diff --git a/src/Samples/SearchAddressMap/Window1.xaml.cs b/src/Samples/SearchAddressMap/Window1.xaml.cs index 5b305a5..07ea3de 100644 --- a/src/Samples/SearchAddressMap/Window1.xaml.cs +++ b/src/Samples/SearchAddressMap/Window1.xaml.cs @@ -12,6 +12,8 @@ using System.Net.Http; using System.IO; +using Google.Maps.Common; + namespace SearchAddressMap { /// @@ -46,12 +48,12 @@ private void refreshMap(Location location, Image imageControl) { Center = location ,Zoom = Convert.ToInt32(zoomSlider.Value) - ,Size = new MapSize(Convert.ToInt32(imageControl.Width), Convert.ToInt32(imageControl.Height)) + ,Size = new GSize(Convert.ToInt32(imageControl.Width), Convert.ToInt32(imageControl.Height)) ,MapType = (MapTypes)Enum.Parse(typeof(MapTypes), ((ComboBoxItem)mapTypeComboBox.SelectedItem).Content.ToString(), true) }; request.Markers.Add(request.Center); - var mapSvc = new StaticMapService(); + var mapSvc = GMaps.StaticMapsService; var imageSource = new BitmapImage(); imageSource.BeginInit(); @@ -68,7 +70,7 @@ private void refreshStreetView(Location location, Image imageControl) { Location = location //,Zoom = Convert.ToInt32(zoomSlider.Value), - , Size = new MapSize(Convert.ToInt32(imageControl.Width), Convert.ToInt32(imageControl.Height)) + , Size = new GSize(Convert.ToInt32(imageControl.Width), Convert.ToInt32(imageControl.Height)) //,MapType = (MapTypes)Enum.Parse(typeof(MapTypes), ((ComboBoxItem)mapTypeComboBox.SelectedItem).Content.ToString(), true) , Heading = Convert.ToInt16(Convert.ToInt16(headingSlider.Value) + 180) , Pitch = Convert.ToInt16(Convert.ToInt16(pitchSlider.Value)) @@ -95,7 +97,7 @@ private async void searchButton_Click(object sender, RoutedEventArgs e) var request = new GeocodingRequest(); request.Address = searchTextBox.Text; - var response = await new GeocodingService().GetResponseAsync(request); + var response = await GMaps.GeocodingService.GetResponseAsync(request); if(response.Status == ServiceResponseStatus.Ok) { @@ -149,9 +151,11 @@ private void headingSlider_MouseDoubleClick(object sender, System.Windows.Input. private void txtGoogleApiKey_LostFocus(object sender, RoutedEventArgs e) { - GoogleSigned.AssignAllServices(new GoogleSigned(txtGoogleApiKey.Text)); + GMaps = new Services(txtGoogleApiKey.Text); } + Google.Maps.Services GMaps = new Services("YOUR_API_KEY"); + private void btnTestUrl_Click(object sender, RoutedEventArgs e) { System.Text.RegularExpressions.Regex keyRegex = new System.Text.RegularExpressions.Regex(@"key=([^&]*)");