From e7b55d34eca11a36d2e35dd46db9b0653d2096c2 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 13:02:12 -0400 Subject: [PATCH 01/24] removed sensor property --- src/Google.Maps/BaseRequest.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Google.Maps/BaseRequest.cs b/src/Google.Maps/BaseRequest.cs index 21c3799..ef63572 100644 --- a/src/Google.Maps/BaseRequest.cs +++ b/src/Google.Maps/BaseRequest.cs @@ -7,9 +7,6 @@ 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; } - public abstract Uri ToUri(); } } From 040977d6b0014e7dcfa236d34175ffed47294b18 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 13:10:41 -0400 Subject: [PATCH 02/24] moved types in Shared to Common --- .../{Shared => Common}/AddressComponent.cs | 2 +- .../{Shared => Common}/AddressType.cs | 2 +- src/Google.Maps/{ => Common}/BaseRequest.cs | 24 +++++++++---------- .../{Shared => Common}/Geometry.cs | 2 +- .../{Shared => Common}/LocationType.cs | 2 +- .../{Shared => Common}/Viewport.cs | 2 +- src/Google.Maps/Direction/DirectionRequest.cs | 4 +++- src/Google.Maps/Direction/GeocodedWaypoint.cs | 5 ++-- .../DistanceMatrix/DistanceMatrixRequest.cs | 4 +++- src/Google.Maps/Elevation/ElevationRequest.cs | 3 +++ src/Google.Maps/Geocoding/GeocodingRequest.cs | 3 ++- src/Google.Maps/Geocoding/Result.cs | 2 +- src/Google.Maps/Google.Maps.csproj | 3 +++ src/Google.Maps/JsonEnumTypeConverter.cs | 5 ++-- .../Autocomplete/AutocompleteRequest.cs | 3 +++ .../Places/Details/PlaceDetailsRequest.cs | 3 +++ .../Places/Details/PlaceDetailsResult.cs | 3 ++- src/Google.Maps/Places/PlacesRequest.cs | 4 ++++ src/Google.Maps/Places/PlacesResult.cs | 2 +- src/Google.Maps/Places/TextSearchRequest.cs | 3 +++ src/Google.Maps/Roads/SnapToRoadsRequest.cs | 5 +++- .../StaticMaps/StaticMapRequest.cs | 2 ++ .../StreetView/StreetViewRequest.cs | 3 +++ src/Google.Maps/TimeZone/TimeZoneRequest.cs | 3 +++ 24 files changed, 66 insertions(+), 28 deletions(-) rename src/Google.Maps/{Shared => Common}/AddressComponent.cs (98%) rename src/Google.Maps/{Shared => Common}/AddressType.cs (99%) rename src/Google.Maps/{ => Common}/BaseRequest.cs (83%) rename src/Google.Maps/{Shared => Common}/Geometry.cs (98%) rename src/Google.Maps/{Shared => Common}/LocationType.cs (98%) rename src/Google.Maps/{Shared => Common}/Viewport.cs (97%) 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 818ee8b..493d4da 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/BaseRequest.cs b/src/Google.Maps/Common/BaseRequest.cs similarity index 83% rename from src/Google.Maps/BaseRequest.cs rename to src/Google.Maps/Common/BaseRequest.cs index ef63572..11268db 100644 --- a/src/Google.Maps/BaseRequest.cs +++ b/src/Google.Maps/Common/BaseRequest.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Google.Maps -{ - public abstract class BaseRequest - { - public abstract Uri ToUri(); - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Google.Maps.Common +{ + public abstract class BaseRequest + { + public abstract Uri ToUri(); + } +} 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/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/DirectionRequest.cs b/src/Google.Maps/Direction/DirectionRequest.cs index 444814f..83dbf7b 100644 --- a/src/Google.Maps/Direction/DirectionRequest.cs +++ b/src/Google.Maps/Direction/DirectionRequest.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Text; -using Google.Maps; using System.ComponentModel; +using Google.Maps; +using Google.Maps.Common; + namespace Google.Maps.Direction { public class DirectionRequest : BaseRequest 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..e22f54a 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs @@ -18,10 +18,12 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using Google.Maps; using System.Text; using System.Linq; +using Google.Maps; +using Google.Maps.Common; + namespace Google.Maps.DistanceMatrix { /// diff --git a/src/Google.Maps/Elevation/ElevationRequest.cs b/src/Google.Maps/Elevation/ElevationRequest.cs index 0d46084..b7f64de 100644 --- a/src/Google.Maps/Elevation/ElevationRequest.cs +++ b/src/Google.Maps/Elevation/ElevationRequest.cs @@ -16,6 +16,9 @@ */ using System; using System.Collections.Generic; + +using Google.Maps; +using Google.Maps.Common; using Google.Maps.Internal; namespace Google.Maps.Elevation diff --git a/src/Google.Maps/Geocoding/GeocodingRequest.cs b/src/Google.Maps/Geocoding/GeocodingRequest.cs index cdf8303..c337976 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; +using Google.Maps.Common; namespace Google.Maps.Geocoding { 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..0be71f3 100644 --- a/src/Google.Maps/Google.Maps.csproj +++ b/src/Google.Maps/Google.Maps.csproj @@ -15,4 +15,7 @@ + + + \ No newline at end of file diff --git a/src/Google.Maps/JsonEnumTypeConverter.cs b/src/Google.Maps/JsonEnumTypeConverter.cs index 31de9c0..3116b0e 100644 --- a/src/Google.Maps/JsonEnumTypeConverter.cs +++ b/src/Google.Maps/JsonEnumTypeConverter.cs @@ -16,9 +16,10 @@ */ using System; -using Google.Maps.Geocoding; -using Google.Maps.Shared; + using Newtonsoft.Json; +using Google.Maps; +using Google.Maps.Common; namespace Google.Maps { diff --git a/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs b/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs index 32a7ec1..3add1b1 100644 --- a/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs +++ b/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs @@ -3,6 +3,9 @@ using System.Linq; using System.Text; +using Google.Maps; +using Google.Maps.Common; + namespace Google.Maps.Places { public class AutocompleteRequest : BaseRequest diff --git a/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs b/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs index 0f9f8b8..f6f557f 100644 --- a/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs +++ b/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs @@ -3,6 +3,9 @@ using System.Linq; using System.Text; +using Google.Maps; +using Google.Maps.Common; + namespace Google.Maps.Places.Details { public class PlaceDetailsRequest : BaseRequest 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/PlacesRequest.cs b/src/Google.Maps/Places/PlacesRequest.cs index 3fe23ca..ab41469 100644 --- a/src/Google.Maps/Places/PlacesRequest.cs +++ b/src/Google.Maps/Places/PlacesRequest.cs @@ -18,6 +18,10 @@ using System; using System.Linq; +using Google.Maps; +using Google.Maps.Common; + + namespace Google.Maps.Places { public abstract class PlacesRequest : BaseRequest 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/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/SnapToRoadsRequest.cs b/src/Google.Maps/Roads/SnapToRoadsRequest.cs index 2beefc0..7de659d 100644 --- a/src/Google.Maps/Roads/SnapToRoadsRequest.cs +++ b/src/Google.Maps/Roads/SnapToRoadsRequest.cs @@ -1,10 +1,13 @@ using System; using System.Linq; +using Google.Maps; +using Google.Maps.Common; + 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 1a6a60c..1dad8ed 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; +using Google.Maps.Common; namespace Google.Maps.StaticMaps { diff --git a/src/Google.Maps/StreetView/StreetViewRequest.cs b/src/Google.Maps/StreetView/StreetViewRequest.cs index 17f3d52..61ce612 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; +using Google.Maps.Common; using Google.Maps.Internal; using System.ComponentModel; + namespace Google.Maps.StreetView { /// diff --git a/src/Google.Maps/TimeZone/TimeZoneRequest.cs b/src/Google.Maps/TimeZone/TimeZoneRequest.cs index e4c65fb..f0e4231 100644 --- a/src/Google.Maps/TimeZone/TimeZoneRequest.cs +++ b/src/Google.Maps/TimeZone/TimeZoneRequest.cs @@ -16,6 +16,9 @@ */ using System; +using Google.Maps; +using Google.Maps.Common; + namespace Google.Maps.TimeZone { /// From 577439ab9777c3b6e8e9569258c88ba713867c3a Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 13:14:04 -0400 Subject: [PATCH 03/24] moved serialization helpers into Internal.Serialization --- src/Google.Maps/Internal/MapsHttp.cs | 7 +- .../Serialization}/JsonCreationConverter.cs | 10 +- .../Serialization}/JsonEnumTypeConverter.cs | 1138 ++++++++--------- .../Serialization/JsonLocationConverter.cs | 19 + 4 files changed, 596 insertions(+), 578 deletions(-) rename src/Google.Maps/{ => Internal/Serialization}/JsonCreationConverter.cs (75%) rename src/Google.Maps/{ => Internal/Serialization}/JsonEnumTypeConverter.cs (96%) create mode 100644 src/Google.Maps/Internal/Serialization/JsonLocationConverter.cs diff --git a/src/Google.Maps/Internal/MapsHttp.cs b/src/Google.Maps/Internal/MapsHttp.cs index 9b68bc5..7653dd8 100644 --- a/src/Google.Maps/Internal/MapsHttp.cs +++ b/src/Google.Maps/Internal/MapsHttp.cs @@ -22,6 +22,7 @@ using System.IO; using Newtonsoft.Json; +using Google.Maps.Internal.Serialization; namespace Google.Maps.Internal { @@ -29,7 +30,11 @@ public class MapsHttp : IDisposable { JsonSerializerSettings settings = new JsonSerializerSettings { - Converters = new List { new JsonEnumTypeConverter(), new JsonLocationConverter() } + Converters = new List + { + new JsonEnumTypeConverter(), + new JsonLatLngConverter() + } }; GoogleSigned signingSvc; 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 96% rename from src/Google.Maps/JsonEnumTypeConverter.cs rename to src/Google.Maps/Internal/Serialization/JsonEnumTypeConverter.cs index 3116b0e..9f6d9b4 100644 --- a/src/Google.Maps/JsonEnumTypeConverter.cs +++ b/src/Google.Maps/Internal/Serialization/JsonEnumTypeConverter.cs @@ -1,569 +1,569 @@ -/* - * 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 -{ - - 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 "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 "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 "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 "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")); + } + } + +} From f74d34039f9ca0a302ace930626f5787eb53153b Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 13:25:56 -0400 Subject: [PATCH 04/24] namespace changes --- src/ConsoleApp1/Program.cs | 1 + .../Direction/DirectionServiceTests.cs | 3 +- .../Geocoding/GeocodingServiceTests.cs | 3 +- .../ValueTextComparer_Tests.cs | 3 + .../{ => Common}/ComponentFilter.cs | 2 +- src/Google.Maps/{ => Common}/Constants.cs | 188 ++++++------ src/Google.Maps/{ => Common}/RankBy.cs | 62 ++-- .../{ => Common}/ServiceResponseStatus.cs | 128 ++++---- src/Google.Maps/{ => Common}/TravelMode.cs | 68 ++-- src/Google.Maps/{ => Common}/ValueText.cs | 2 +- src/Google.Maps/Direction/DirectionLeg.cs | 2 + .../Direction/DirectionResponse.cs | 1 + src/Google.Maps/Direction/DirectionStep.cs | 2 + .../DistanceMatrix/DistanceMatrixResponse.cs | 2 + .../Elevation/ElevationResponse.cs | 1 + src/Google.Maps/Geocoding/GeocodeResponse.cs | 4 +- src/Google.Maps/{ => Internal}/AvoidHelper.cs | 0 .../{ => Internal}/LatLngComparer.cs | 2 +- .../{ => Internal}/PolylineEncoder.cs | 290 +++++++++--------- src/Google.Maps/Internal/RequestUtils.cs | 2 + src/Google.Maps/Internal/ValueTextComparer.cs | 5 +- src/Google.Maps/MapMarker.cs | 2 + .../Autocomplete/AutocompleteResponse.cs | 6 +- .../Places/Details/PlaceDetailsResponse.cs | 6 +- src/Google.Maps/Places/NearbySearchRequest.cs | 8 +- src/Google.Maps/Places/PlacesResponse.cs | 1 + src/Google.Maps/TimeZone/TimeZoneResponse.cs | 4 +- src/Samples/SearchAddressMap/Window1.xaml.cs | 2 + 28 files changed, 417 insertions(+), 383 deletions(-) rename src/Google.Maps/{ => Common}/ComponentFilter.cs (99%) rename src/Google.Maps/{ => Common}/Constants.cs (96%) rename src/Google.Maps/{ => Common}/RankBy.cs (94%) rename src/Google.Maps/{ => Common}/ServiceResponseStatus.cs (95%) rename src/Google.Maps/{ => Common}/TravelMode.cs (95%) rename src/Google.Maps/{ => Common}/ValueText.cs (93%) rename src/Google.Maps/{ => Internal}/AvoidHelper.cs (100%) rename src/Google.Maps/{ => Internal}/LatLngComparer.cs (97%) rename src/Google.Maps/{ => Internal}/PolylineEncoder.cs (96%) diff --git a/src/ConsoleApp1/Program.cs b/src/ConsoleApp1/Program.cs index d8231a8..74f6458 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 { diff --git a/src/Google.Maps.Test/Direction/DirectionServiceTests.cs b/src/Google.Maps.Test/Direction/DirectionServiceTests.cs index a0f3664..4175f46 100644 --- a/src/Google.Maps.Test/Direction/DirectionServiceTests.cs +++ b/src/Google.Maps.Test/Direction/DirectionServiceTests.cs @@ -21,7 +21,8 @@ using NUnit.Framework; -using Google.Maps.Shared; +using Google.Maps.Common; +using Google.Maps.Internal; namespace Google.Maps.Direction { diff --git a/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs index bae3183..aac6653 100644 --- a/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs +++ b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs @@ -21,7 +21,8 @@ using NUnit.Framework; -using Google.Maps.Shared; +using Google.Maps.Common; +using Google.Maps.Internal; namespace Google.Maps.Geocoding { 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/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 7b4b9f7..c971798 100644 --- a/src/Google.Maps/Constants.cs +++ b/src/Google.Maps/Common/Constants.cs @@ -1,94 +1,94 @@ -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); - } - - #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); + } + + #endregion + + } +} 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/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/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/DirectionResponse.cs b/src/Google.Maps/Direction/DirectionResponse.cs index 6f09436..27d6e07 100644 --- a/src/Google.Maps/Direction/DirectionResponse.cs +++ b/src/Google.Maps/Direction/DirectionResponse.cs @@ -3,6 +3,7 @@ using System.Text; using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.Direction { diff --git a/src/Google.Maps/Direction/DirectionStep.cs b/src/Google.Maps/Direction/DirectionStep.cs index 1c90057..a8843f2 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/DistanceMatrix/DistanceMatrixResponse.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs index 32f0ffa..8ac9593 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixResponse.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; + using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.DistanceMatrix { diff --git a/src/Google.Maps/Elevation/ElevationResponse.cs b/src/Google.Maps/Elevation/ElevationResponse.cs index d151a9a..045c94f 100644 --- a/src/Google.Maps/Elevation/ElevationResponse.cs +++ b/src/Google.Maps/Elevation/ElevationResponse.cs @@ -16,6 +16,7 @@ */ using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.Elevation { diff --git a/src/Google.Maps/Geocoding/GeocodeResponse.cs b/src/Google.Maps/Geocoding/GeocodeResponse.cs index 421c2e9..0c08424 100644 --- a/src/Google.Maps/Geocoding/GeocodeResponse.cs +++ b/src/Google.Maps/Geocoding/GeocodeResponse.cs @@ -15,9 +15,11 @@ * limitations under the License. */ -using Newtonsoft.Json; using System; +using Newtonsoft.Json; +using Google.Maps.Common; + namespace Google.Maps.Geocoding { [JsonObject(MemberSerialization.OptIn)] diff --git a/src/Google.Maps/AvoidHelper.cs b/src/Google.Maps/Internal/AvoidHelper.cs similarity index 100% rename from src/Google.Maps/AvoidHelper.cs rename to src/Google.Maps/Internal/AvoidHelper.cs 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/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/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..3eea709 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 { 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/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/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/PlacesResponse.cs b/src/Google.Maps/Places/PlacesResponse.cs index f921737..4ea41f7 100644 --- a/src/Google.Maps/Places/PlacesResponse.cs +++ b/src/Google.Maps/Places/PlacesResponse.cs @@ -16,6 +16,7 @@ */ using Newtonsoft.Json; +using Google.Maps.Common; namespace Google.Maps.Places { diff --git a/src/Google.Maps/TimeZone/TimeZoneResponse.cs b/src/Google.Maps/TimeZone/TimeZoneResponse.cs index 7043fa4..1bf774b 100644 --- a/src/Google.Maps/TimeZone/TimeZoneResponse.cs +++ b/src/Google.Maps/TimeZone/TimeZoneResponse.cs @@ -15,9 +15,11 @@ * limitations under the License. */ -using Newtonsoft.Json; using System; +using Newtonsoft.Json; +using Google.Maps.Common; + namespace Google.Maps.TimeZone { [JsonObject(MemberSerialization.OptIn)] diff --git a/src/Samples/SearchAddressMap/Window1.xaml.cs b/src/Samples/SearchAddressMap/Window1.xaml.cs index 5b305a5..6b10891 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 { /// From f26e118bf6f18e897971051940b96f5a720f0d0d Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 13:32:45 -0400 Subject: [PATCH 05/24] more namespace changes --- .../Direction/DirectionRequestTests.cs | 1 + .../DistanceMatrixServiceTests.cs | 1 + .../Elevation/ElevationServiceTests.cs | 1 + .../GoogleMapsForBusinessTests.cs | 1 + src/Google.Maps.Test/LatLngComparerTests.cs | 1 + .../Places/PlaceDetailsServiceTests.cs | 1 + .../Places/PlacesServiceTests.cs | 1 + src/Google.Maps.Test/PolylineEncodingTests.cs | 1 + .../TimeZone/TimeZoneServiceTests.cs | 1 + src/Google.Maps/{ => Common}/Avoid.cs | 2 +- .../MapImageFormats.cs} | 76 +++++++++---------- src/Google.Maps/{ => Common}/Units.cs | 46 +++++------ src/Google.Maps/Direction/DirectionRequest.cs | 1 + .../DistanceMatrix/DistanceMatrixRequest.cs | 1 + src/Google.Maps/Internal/AvoidHelper.cs | 4 +- src/Google.Maps/MapTypes.cs | 2 +- src/Google.Maps/MarkerSizes.cs | 2 +- .../StaticMaps/StaticMapRequest.cs | 6 +- .../StreetView/StreetViewRequest.cs | 6 +- 19 files changed, 84 insertions(+), 71 deletions(-) rename src/Google.Maps/{ => Common}/Avoid.cs (94%) rename src/Google.Maps/{GMapsImageFormats.cs => Common/MapImageFormats.cs} (89%) rename src/Google.Maps/{ => Common}/Units.cs (92%) 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/DistanceMatrix/DistanceMatrixServiceTests.cs b/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs index a38f6f4..6acd222 100644 --- a/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs +++ b/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps.DistanceMatrix { diff --git a/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs b/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs index 20fb602..906dbe7 100644 --- a/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs +++ b/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs @@ -18,6 +18,7 @@ using System; using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps.Elevation { diff --git a/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs b/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs index b512be9..7612afd 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 { 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/Places/PlaceDetailsServiceTests.cs b/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs index 3b19293..5a79a4d 100644 --- a/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs +++ b/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps.Places.Details { diff --git a/src/Google.Maps.Test/Places/PlacesServiceTests.cs b/src/Google.Maps.Test/Places/PlacesServiceTests.cs index e623727..f55c6d3 100644 --- a/src/Google.Maps.Test/Places/PlacesServiceTests.cs +++ b/src/Google.Maps.Test/Places/PlacesServiceTests.cs @@ -3,6 +3,7 @@ using System.Threading; using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps.Places { 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/TimeZone/TimeZoneServiceTests.cs b/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs index 5861b56..9d6fcd2 100644 --- a/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs +++ b/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.Maps.Common; namespace Google.Maps.TimeZone { 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/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/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/Direction/DirectionRequest.cs b/src/Google.Maps/Direction/DirectionRequest.cs index 83dbf7b..eb0b6c5 100644 --- a/src/Google.Maps/Direction/DirectionRequest.cs +++ b/src/Google.Maps/Direction/DirectionRequest.cs @@ -5,6 +5,7 @@ using Google.Maps; using Google.Maps.Common; +using Google.Maps.Internal; namespace Google.Maps.Direction { diff --git a/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs index e22f54a..906b52b 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs @@ -23,6 +23,7 @@ using Google.Maps; using Google.Maps.Common; +using Google.Maps.Internal; namespace Google.Maps.DistanceMatrix { diff --git a/src/Google.Maps/Internal/AvoidHelper.cs b/src/Google.Maps/Internal/AvoidHelper.cs index 2b54214..655e678 100644 --- a/src/Google.Maps/Internal/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/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/StaticMaps/StaticMapRequest.cs b/src/Google.Maps/StaticMaps/StaticMapRequest.cs index 1dad8ed..c13ae4e 100644 --- a/src/Google.Maps/StaticMaps/StaticMapRequest.cs +++ b/src/Google.Maps/StaticMaps/StaticMapRequest.cs @@ -128,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 @@ -207,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/StreetView/StreetViewRequest.cs b/src/Google.Maps/StreetView/StreetViewRequest.cs index 61ce612..c37ce64 100644 --- a/src/Google.Maps/StreetView/StreetViewRequest.cs +++ b/src/Google.Maps/StreetView/StreetViewRequest.cs @@ -83,7 +83,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 @@ -183,8 +183,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; } From b2d466c28530a9028d11bde05743f68fe569fa76 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 14:03:44 -0400 Subject: [PATCH 06/24] rename MapColor/MapSize to GColor/GSize and move into Common namespace --- src/Google.Maps.Test/MapColorTests.cs | 19 ++++++++------- src/Google.Maps.Test/QuickExamplesTests.cs | 3 ++- .../StaticMaps/StaticMapRequestTests.cs | 5 ++-- .../StaticMaps/StaticMap_Path_Tests.cs | 7 +++--- .../StreetView/StreetViewRequestTests.cs | 5 ++-- .../StreetView_uribuilding_Tests.cs | 7 +++--- .../{MapColor.cs => Common/GColor.cs} | 24 +++++++++---------- src/Google.Maps/Common/GSize.cs | 23 ++++++++++++++++++ src/Google.Maps/Google.Maps.csproj | 8 ++++--- src/Google.Maps/MapMarker.cs | 2 +- src/Google.Maps/MapSize.cs | 23 ------------------ src/Google.Maps/Path.cs | 6 +++-- .../StaticMaps/StaticMapRequest.cs | 6 ++--- .../StreetView/StreetViewRequest.cs | 6 ++--- src/Samples/SearchAddressMap/Window1.xaml.cs | 4 ++-- 15 files changed, 79 insertions(+), 69 deletions(-) rename src/Google.Maps/{MapColor.cs => Common/GColor.cs} (75%) create mode 100644 src/Google.Maps/Common/GSize.cs delete mode 100644 src/Google.Maps/MapSize.cs 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/QuickExamplesTests.cs b/src/Google.Maps.Test/QuickExamplesTests.cs index 4acccbf..637cf44 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 { @@ -40,7 +41,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(); 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 26a518e..ba009e9 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/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/Google.Maps.csproj b/src/Google.Maps/Google.Maps.csproj index 0be71f3..f366345 100644 --- a/src/Google.Maps/Google.Maps.csproj +++ b/src/Google.Maps/Google.Maps.csproj @@ -10,12 +10,14 @@ HAS_SYSTEMDRAWING - + + + - + - + \ No newline at end of file diff --git a/src/Google.Maps/MapMarker.cs b/src/Google.Maps/MapMarker.cs index 3eea709..e01e5b6 100644 --- a/src/Google.Maps/MapMarker.cs +++ b/src/Google.Maps/MapMarker.cs @@ -47,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/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/StaticMaps/StaticMapRequest.cs b/src/Google.Maps/StaticMaps/StaticMapRequest.cs index c13ae4e..0af1a3f 100644 --- a/src/Google.Maps/StaticMaps/StaticMapRequest.cs +++ b/src/Google.Maps/StaticMaps/StaticMapRequest.cs @@ -36,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(); @@ -84,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 @@ -96,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 diff --git a/src/Google.Maps/StreetView/StreetViewRequest.cs b/src/Google.Maps/StreetView/StreetViewRequest.cs index c37ce64..0bdf810 100644 --- a/src/Google.Maps/StreetView/StreetViewRequest.cs +++ b/src/Google.Maps/StreetView/StreetViewRequest.cs @@ -38,7 +38,7 @@ public class StreetViewRequest : BaseRequest { public StreetViewRequest() { - this.Size = new MapSize(512, 512); //default size is 512x512 + this.Size = new GSize(512, 512); //default size is 512x512 } /// @@ -61,7 +61,7 @@ public StreetViewRequest() /// 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 @@ -73,7 +73,7 @@ public MapSize Size this._size = value; } } - private MapSize _size; + private GSize _size; /// /// Defines the format of the resulting image. By default, the Static diff --git a/src/Samples/SearchAddressMap/Window1.xaml.cs b/src/Samples/SearchAddressMap/Window1.xaml.cs index 6b10891..7c54140 100644 --- a/src/Samples/SearchAddressMap/Window1.xaml.cs +++ b/src/Samples/SearchAddressMap/Window1.xaml.cs @@ -48,7 +48,7 @@ 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); @@ -70,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)) From cf052614d90ed81cc6db971abf3045cd5633e1e8 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 14:10:21 -0400 Subject: [PATCH 07/24] Fixed reference to MapSize=>GSize --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 04a8db4..932cd19 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,14 @@ else Static Maps API support allows you to get a valid url or a streamed bitmap which you can use: ```c# +using Google.Maps; +using Google.Maps.Common; + //always need to use YOUR_API_KEY for requests. Do this in App_Start. GoogleSigned.AssignAllServices(new GoogleSigned("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; ``` @@ -143,6 +146,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) From d62bc3399527ba0588e915fb17dda11491138843 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 20:12:29 -0400 Subject: [PATCH 08/24] created base set of interfaces for DI containers --- .../ApiCore/GMaps_BaseGmapsService.cs | 47 +++++++++++++++++++ .../ApiCore/GMaps_BaseServiceBuilder.cs | 34 ++++++++++++++ .../ApiCore/GMaps_IGMapsService.cs | 18 +++++++ .../ApiCore/GoogleApiSigningService.cs | 21 +++++++++ src/Google.Maps/ApiCore/IHttpService.cs | 21 +++++++++ src/Google.Maps/ApiCore/IServiceBuilder.cs | 20 ++++++++ src/Google.Maps/ApiCore/ISigningService.cs | 14 ++++++ 7 files changed, 175 insertions(+) create mode 100644 src/Google.Maps/ApiCore/GMaps_BaseGmapsService.cs create mode 100644 src/Google.Maps/ApiCore/GMaps_BaseServiceBuilder.cs create mode 100644 src/Google.Maps/ApiCore/GMaps_IGMapsService.cs create mode 100644 src/Google.Maps/ApiCore/GoogleApiSigningService.cs create mode 100644 src/Google.Maps/ApiCore/IHttpService.cs create mode 100644 src/Google.Maps/ApiCore/IServiceBuilder.cs create mode 100644 src/Google.Maps/ApiCore/ISigningService.cs diff --git a/src/Google.Maps/ApiCore/GMaps_BaseGmapsService.cs b/src/Google.Maps/ApiCore/GMaps_BaseGmapsService.cs new file mode 100644 index 0000000..52f3b71 --- /dev/null +++ b/src/Google.Maps/ApiCore/GMaps_BaseGmapsService.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Google.ApiCore; + +namespace Google.Maps.ApiCore +{ + public abstract class BaseGmapsService : IGmapsService + where TRequest : BaseRequest + where TResponse : class + { + public IHttpService HttpService { get; protected set; } + public Uri BaseUri { get; protected set; } + + 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); + } + + 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/GMaps_BaseServiceBuilder.cs b/src/Google.Maps/ApiCore/GMaps_BaseServiceBuilder.cs new file mode 100644 index 0000000..21f9ecc --- /dev/null +++ b/src/Google.Maps/ApiCore/GMaps_BaseServiceBuilder.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.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/GMaps_IGMapsService.cs b/src/Google.Maps/ApiCore/GMaps_IGMapsService.cs new file mode 100644 index 0000000..df97189 --- /dev/null +++ b/src/Google.Maps/ApiCore/GMaps_IGMapsService.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Google.ApiCore; + +namespace Google.Maps.ApiCore +{ + public interface IGmapsService + { + + TResponse GetResponse(TRequest request); + } + + +} diff --git a/src/Google.Maps/ApiCore/GoogleApiSigningService.cs b/src/Google.Maps/ApiCore/GoogleApiSigningService.cs new file mode 100644 index 0000000..31de2ca --- /dev/null +++ b/src/Google.Maps/ApiCore/GoogleApiSigningService.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.ApiCore +{ + public class GoogleApiSigningService : ISigningService + { + public GoogleApiSigningService(Google.Maps.GoogleSigned signInfo) + { + + } + + public Uri GetSignedUri(Uri value) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Google.Maps/ApiCore/IHttpService.cs b/src/Google.Maps/ApiCore/IHttpService.cs new file mode 100644 index 0000000..bcf7c68 --- /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.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..e957bd7 --- /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.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..2756ae4 --- /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.ApiCore +{ + public interface ISigningService + { + Uri GetSignedUri(Uri value); + + } +} From 1146df480fb93b981a8248594771c4bc210acf7e Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 20:14:15 -0400 Subject: [PATCH 09/24] created default facade for easiest access to the services without using DI container --- src/Google.Maps/_Services.cs | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Google.Maps/_Services.cs diff --git a/src/Google.Maps/_Services.cs b/src/Google.Maps/_Services.cs new file mode 100644 index 0000000..5a73f2e --- /dev/null +++ b/src/Google.Maps/_Services.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Google.ApiCore; + +namespace Google.Maps +{ + + /// + /// Easy to use facade for all the services + /// + public class Services + { + public Services(string apiKey) + { + this._SigningService = new GoogleApiSigningService(new GoogleSigned(apiKey)); + 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; } } + + } +} From 46ad33b31eef9cfafab9f55eeb01e8d87abe76d3 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 20:40:19 -0400 Subject: [PATCH 10/24] updated MapsHttp to be an IHttpService --- src/Google.Maps/Internal/MapsHttp.cs | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Google.Maps/Internal/MapsHttp.cs b/src/Google.Maps/Internal/MapsHttp.cs index 9b68bc5..6737ab5 100644 --- a/src/Google.Maps/Internal/MapsHttp.cs +++ b/src/Google.Maps/Internal/MapsHttp.cs @@ -22,20 +22,24 @@ using System.IO; using Newtonsoft.Json; +using Google.ApiCore; 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 JsonLocationConverter() + } }; - GoogleSigned signingSvc; + ISigningService signingSvc; HttpClient client; - public MapsHttp(GoogleSigned signingSvc) + public MapsHttp(ISigningService signingSvc) { this.signingSvc = signingSvc; this.client = new HttpClient(); @@ -43,7 +47,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); @@ -59,7 +66,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); } @@ -69,13 +79,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) From d3033bd40db91a66f6eb14db5aa189c7ceb54897 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 20:42:16 -0400 Subject: [PATCH 11/24] updated GeocodingService and updated the ConsoleSample program --- src/ConsoleApp1/Program.cs | 9 ++-- src/Google.Maps/Geocoding/GeocodingService.cs | 44 +++---------------- src/Google.Maps/_Services.cs | 7 +++ 3 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/ConsoleApp1/Program.cs b/src/ConsoleApp1/Program.cs index d8231a8..42e7b9e 100644 --- a/src/ConsoleApp1/Program.cs +++ b/src/ConsoleApp1/Program.cs @@ -27,11 +27,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 +83,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 +91,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/Geocoding/GeocodingService.cs b/src/Google.Maps/Geocoding/GeocodingService.cs index 46898e6..b0f795d 100644 --- a/src/Google.Maps/Geocoding/GeocodingService.cs +++ b/src/Google.Maps/Geocoding/GeocodingService.cs @@ -19,6 +19,8 @@ using System.Threading.Tasks; using Google.Maps.Internal; +using Google.Maps.ApiCore; +using Google.ApiCore; namespace Google.Maps.Geocoding { @@ -28,49 +30,15 @@ namespace Google.Maps.Geocoding /// (turning coordinates into addresses); this process is known as /// "reverse geocoding." /// - public class GeocodingService : IDisposable + public class GeocodingService : BaseGmapsService { 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/_Services.cs b/src/Google.Maps/_Services.cs index 5a73f2e..67b9eed 100644 --- a/src/Google.Maps/_Services.cs +++ b/src/Google.Maps/_Services.cs @@ -38,5 +38,12 @@ public Services WithHttpService(IHttpService httpService) public ISigningService SigningService { get { return this._SigningService; } } public IHttpService HttpService { get { return this._HttpService; } } + + public Geocoding.GeocodingService GeocodingService + { + get { return new Geocoding.GeocodingService(HttpService, null); } + } + + } } From 748452ac95ce49415067d7020e9dba9282e846f1 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 21:21:53 -0400 Subject: [PATCH 12/24] split up to support services that might return more than simple one response --- .../ApiCore/GMaps_BaseGmapsService.cs | 19 ++--------- .../GMaps_BaseGmapsServiceTypedResponse.cs | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 src/Google.Maps/ApiCore/GMaps_BaseGmapsServiceTypedResponse.cs diff --git a/src/Google.Maps/ApiCore/GMaps_BaseGmapsService.cs b/src/Google.Maps/ApiCore/GMaps_BaseGmapsService.cs index 52f3b71..e99db76 100644 --- a/src/Google.Maps/ApiCore/GMaps_BaseGmapsService.cs +++ b/src/Google.Maps/ApiCore/GMaps_BaseGmapsService.cs @@ -8,26 +8,12 @@ namespace Google.Maps.ApiCore { - public abstract class BaseGmapsService : IGmapsService - where TRequest : BaseRequest - where TResponse : class + public abstract class BaseGmapsService + where TRequest : BaseRequest { public IHttpService HttpService { get; protected set; } public Uri BaseUri { get; protected set; } - 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); - } public void Dispose() { @@ -42,6 +28,7 @@ public void Dispose() HttpService = null; } } + } } diff --git a/src/Google.Maps/ApiCore/GMaps_BaseGmapsServiceTypedResponse.cs b/src/Google.Maps/ApiCore/GMaps_BaseGmapsServiceTypedResponse.cs new file mode 100644 index 0000000..8d2d5e3 --- /dev/null +++ b/src/Google.Maps/ApiCore/GMaps_BaseGmapsServiceTypedResponse.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Google.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); + } + + } + +} From 835678bb435dbc3df6c81982b3ca1c3020fdb3b0 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 21:22:44 -0400 Subject: [PATCH 13/24] change all services to utilize baseclass and constructor dependency injection --- src/Google.Maps/Direction/DirectionService.cs | 37 +++------------- .../DistanceMatrix/DistanceMatrixService.cs | 38 +++------------- src/Google.Maps/Elevation/ElevationService.cs | 43 +++---------------- src/Google.Maps/Geocoding/GeocodingService.cs | 3 +- .../Places/Details/PlaceDetailsService.cs | 43 +++---------------- src/Google.Maps/Places/PlacesService.cs | 39 +++-------------- src/Google.Maps/Roads/RoadsService.cs | 37 +++------------- .../StaticMaps/StaticMapService.cs | 30 ++++--------- .../StreetView/StreetViewService.cs | 29 +++---------- src/Google.Maps/TimeZone/TimeZoneService.cs | 42 +++--------------- 10 files changed, 55 insertions(+), 286 deletions(-) diff --git a/src/Google.Maps/Direction/DirectionService.cs b/src/Google.Maps/Direction/DirectionService.cs index 8a9ce8b..4ee5268 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.ApiCore; namespace Google.Maps.Direction { - public class DirectionService : IDisposable + + public class DirectionService : ApiCore.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/DistanceMatrix/DistanceMatrixService.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs index 2f08f46..134bc43 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.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 : ApiCore.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/"); + public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/elevation/"); - 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/ElevationService.cs b/src/Google.Maps/Elevation/ElevationService.cs index f4f9784..987717c 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.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 : ApiCore.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/GeocodingService.cs b/src/Google.Maps/Geocoding/GeocodingService.cs index b0f795d..d82e763 100644 --- a/src/Google.Maps/Geocoding/GeocodingService.cs +++ b/src/Google.Maps/Geocoding/GeocodingService.cs @@ -19,7 +19,6 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.Maps.ApiCore; using Google.ApiCore; namespace Google.Maps.Geocoding @@ -30,7 +29,7 @@ namespace Google.Maps.Geocoding /// (turning coordinates into addresses); this process is known as /// "reverse geocoding." /// - public class GeocodingService : BaseGmapsService + public class GeocodingService : ApiCore.BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/geocode/"); diff --git a/src/Google.Maps/Places/Details/PlaceDetailsService.cs b/src/Google.Maps/Places/Details/PlaceDetailsService.cs index f4cfe40..94e07ac 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.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 : ApiCore.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/PlacesService.cs b/src/Google.Maps/Places/PlacesService.cs index d890bc1..c21044f 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.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 : ApiCore.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/Roads/RoadsService.cs b/src/Google.Maps/Roads/RoadsService.cs index 1f314b3..b5ed532 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.ApiCore; namespace Google.Maps.Roads { - public class RoadsService : IDisposable + + public class RoadsService : ApiCore.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/StaticMaps/StaticMapService.cs b/src/Google.Maps/StaticMaps/StaticMapService.cs index 794a35d..12b69cd 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.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) @@ -89,13 +85,5 @@ Byte[] StreamToArray(Stream inputStream) return outputStream.ToArray(); } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/StreetView/StreetViewService.cs b/src/Google.Maps/StreetView/StreetViewService.cs index 7c0168f..482b27b 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); @@ -58,16 +49,16 @@ public async Task GetImageAsync(StreetViewRequest request) 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) @@ -88,13 +79,5 @@ Byte[] StreamToArray(Stream inputStream) return outputStream.ToArray(); } - public void Dispose() - { - if (http != null) - { - http.Dispose(); - http = null; - } - } } } diff --git a/src/Google.Maps/TimeZone/TimeZoneService.cs b/src/Google.Maps/TimeZone/TimeZoneService.cs index 7a7df04..8c69d82 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.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 : ApiCore.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; - } - } } } From 4dcc69b6e236d975ecdd35b058c82b7c7a94d972 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 21:23:53 -0400 Subject: [PATCH 14/24] updates to test classes --- .../Direction/DirectionServiceTests.cs | 10 +++++++++- .../Elevation/ElevationServiceTests.cs | 11 ++++++++++- .../Geocoding/GeocodingServiceTests.cs | 10 +++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Google.Maps.Test/Direction/DirectionServiceTests.cs b/src/Google.Maps.Test/Direction/DirectionServiceTests.cs index a0f3664..c61d961 100644 --- a/src/Google.Maps.Test/Direction/DirectionServiceTests.cs +++ b/src/Google.Maps.Test/Direction/DirectionServiceTests.cs @@ -22,6 +22,7 @@ using NUnit.Framework; using Google.Maps.Shared; +using Google.ApiCore; namespace Google.Maps.Direction { @@ -32,7 +33,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/Elevation/ElevationServiceTests.cs b/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs index 20fb602..8945dfc 100644 --- a/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs +++ b/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs @@ -18,6 +18,7 @@ using System; using NUnit.Framework; +using Google.ApiCore; namespace Google.Maps.Elevation { @@ -28,7 +29,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 bae3183..6d4eadc 100644 --- a/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs +++ b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs @@ -22,6 +22,7 @@ using NUnit.Framework; using Google.Maps.Shared; +using Google.ApiCore; namespace Google.Maps.Geocoding { @@ -32,7 +33,14 @@ class GeocodingServiceTests GeocodingService CreateService() { - var svc = new GeocodingService(TestingApiKey); + var svc = new GeocodingService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri: null + ); return svc; } From c76b373f322fc1e1ac5af428858af2b89acaafa2 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 21:50:41 -0400 Subject: [PATCH 15/24] updates to get everything compiling again --- .../DistanceMatrixServiceTests.cs | 10 +++++++++- .../Geocoding/GeocodingServiceTests.cs | 2 +- .../GoogleMapsForBusinessTests.cs | 17 ++++++++++++----- .../Places/PlaceDetailsServiceTests.cs | 19 +++++++++++++++++-- .../Places/PlacesServiceTests.cs | 12 ++++++++++-- src/Google.Maps.Test/QuickExamplesTests.cs | 15 +++++++++++++-- .../Roads/RoadsServiceTests.cs | 10 +++++++++- .../TimeZone/TimeZoneServiceTests.cs | 10 +++++++++- src/Google.Maps/_Services.cs | 16 ++++++++++++++-- src/Samples/SearchAddressMap/Window1.xaml.cs | 8 +++++--- 10 files changed, 99 insertions(+), 20 deletions(-) diff --git a/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs b/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs index a38f6f4..8e01c0c 100644 --- a/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs +++ b/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.ApiCore; namespace Google.Maps.DistanceMatrix { @@ -12,7 +13,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/Geocoding/GeocodingServiceTests.cs b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs index 6d4eadc..a9f2acd 100644 --- a/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs +++ b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs @@ -194,7 +194,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); Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); Assert.AreEqual(LocationType.Rooftop, response.Results[0].Geometry.LocationType); diff --git a/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs b/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs index b512be9..5202ef5 100644 --- a/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs +++ b/src/Google.Maps.Test/GoogleMapsForBusinessTests.cs @@ -21,6 +21,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 +62,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 +72,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 +80,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/Places/PlaceDetailsServiceTests.cs b/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs index 3b19293..503b7e5 100644 --- a/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs +++ b/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs @@ -2,16 +2,31 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.ApiCore; 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")] @@ -22,7 +37,7 @@ public void PlacesDetailsTest(string placeID, string placeName) { PlaceID = placeID }; - var response = new PlaceDetailsService().GetResponse(request); + var response = CreateService().GetResponse(request); Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); Assert.IsNotNull(response.Result.URL); diff --git a/src/Google.Maps.Test/Places/PlacesServiceTests.cs b/src/Google.Maps.Test/Places/PlacesServiceTests.cs index b376b62..e4cac3d 100644 --- a/src/Google.Maps.Test/Places/PlacesServiceTests.cs +++ b/src/Google.Maps.Test/Places/PlacesServiceTests.cs @@ -3,6 +3,7 @@ using System.Threading; using NUnit.Framework; +using Google.ApiCore; namespace Google.Maps.Places { @@ -19,7 +20,14 @@ public void OneTimeSetUp() private PlacesService CreateService() { - return new PlacesService(TestingApiKey); + return new PlacesService( + new Internal.MapsHttp( + new GoogleApiSigningService( + TestingApiKey + ) + ), + baseUri: null + ); } [Test] @@ -71,7 +79,7 @@ public void PlacesTest_Text() Query = "New York, NY", Radius = 10000 }; - PlacesResponse response = new PlacesService().GetResponse(request); + PlacesResponse response = CreateService().GetResponse(request); Assert.AreEqual(ServiceResponseStatus.Ok, response.Status); diff --git a/src/Google.Maps.Test/QuickExamplesTests.cs b/src/Google.Maps.Test/QuickExamplesTests.cs index 4acccbf..13020f3 100644 --- a/src/Google.Maps.Test/QuickExamplesTests.cs +++ b/src/Google.Maps.Test/QuickExamplesTests.cs @@ -17,12 +17,23 @@ namespace Google.Maps class QuickExamplesTests { + [OneTimeSetUp] + public void OneTimeSetup() + { + this.TestingApiKey = SigningHelper.GetApiKey(); + this.GMaps = new Services(TestingApiKey); + } + GoogleSigned TestingApiKey; + Google.Maps.Services GMaps; + [Test] public void GeocodingRequest_Example() { + //var GMaps = new Google.Maps.Services("YOUR_API_KEY"); + var request = new GeocodingRequest(); request.Address = "1600 Amphitheatre Parkway"; - var response = new GeocodingService().GetResponse(request); + var response = GMaps.GeocodingService.GetResponse(request); // --break in the online version here-- // @@ -57,7 +68,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 96b4dc4..8f16f32 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.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/TimeZone/TimeZoneServiceTests.cs b/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs index 5861b56..6d3aa6b 100644 --- a/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs +++ b/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using NUnit.Framework; +using Google.ApiCore; namespace Google.Maps.TimeZone { @@ -28,7 +29,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/_Services.cs b/src/Google.Maps/_Services.cs index 67b9eed..710f111 100644 --- a/src/Google.Maps/_Services.cs +++ b/src/Google.Maps/_Services.cs @@ -14,9 +14,13 @@ namespace Google.Maps /// public class Services { - public Services(string apiKey) + public Services(string apiKey) : this(new GoogleSigned(apiKey)) { - this._SigningService = new GoogleApiSigningService(new GoogleSigned(apiKey)); + } + + public Services(GoogleSigned signingInstance) + { + this._SigningService = new GoogleApiSigningService(signingInstance); this._HttpService = new Google.Maps.Internal.MapsHttp(this._SigningService); } @@ -39,10 +43,18 @@ public Services WithHttpService(IHttpService httpService) 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..7582cb7 100644 --- a/src/Samples/SearchAddressMap/Window1.xaml.cs +++ b/src/Samples/SearchAddressMap/Window1.xaml.cs @@ -51,7 +51,7 @@ private void refreshMap(Location location, Image imageControl) }; request.Markers.Add(request.Center); - var mapSvc = new StaticMapService(); + var mapSvc = GMaps.StaticMapsService; var imageSource = new BitmapImage(); imageSource.BeginInit(); @@ -95,7 +95,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 +149,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=([^&]*)"); From 616c366867573b19055a9abe732539e3bc1d765f Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 22:41:58 -0400 Subject: [PATCH 16/24] reformatting --- src/Google.Maps/GoogleSigned.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Google.Maps/GoogleSigned.cs b/src/Google.Maps/GoogleSigned.cs index a4040ba..6ac72b3 100644 --- a/src/Google.Maps/GoogleSigned.cs +++ b/src/Google.Maps/GoogleSigned.cs @@ -59,7 +59,9 @@ public static void AssignAllServices(GoogleSigned signingInstance) public string GetSignedUri(Uri uri) { - var builder = new UriBuilder(uri); if(_signType == GoogleSignedType.Business) + var builder = new UriBuilder(uri); + + if(_signType == GoogleSignedType.Business) { builder.Query = builder.Query.Substring(1) + "&client=" + _clientId; uri = builder.Uri; From b54e5717707f7c82c96a06dea1c124835e19ed6e Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 22:42:28 -0400 Subject: [PATCH 17/24] fixed typo of not transferring HttpsUri correctly --- src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs index 134bc43..7d1e3fa 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs @@ -30,7 +30,7 @@ namespace Google.Maps.DistanceMatrix /// public class DistanceMatrixService : ApiCore.BaseGmapsServiceTypedResponse { - public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/elevation/"); + public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/distancematrix/"); public DistanceMatrixService(IHttpService httpService, Uri baseUri) { From 2a25a970e026c2827262df22cb6e34efa8d50cbf Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 22:42:54 -0400 Subject: [PATCH 18/24] asynchelper to run task syncronously from Microsft.Aspnet.Identity --- src/Google.Maps/Google.Maps.csproj | 3 +++ src/Google.Maps/Internal/AsyncHelper.cs | 31 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/Google.Maps/Internal/AsyncHelper.cs diff --git a/src/Google.Maps/Google.Maps.csproj b/src/Google.Maps/Google.Maps.csproj index 8510a41..2d3d815 100644 --- a/src/Google.Maps/Google.Maps.csproj +++ b/src/Google.Maps/Google.Maps.csproj @@ -9,6 +9,9 @@ HAS_SYSTEMDRAWING + + + diff --git a/src/Google.Maps/Internal/AsyncHelper.cs b/src/Google.Maps/Internal/AsyncHelper.cs new file mode 100644 index 0000000..945af5c --- /dev/null +++ b/src/Google.Maps/Internal/AsyncHelper.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Google.Maps.Internal +{ + internal class AsyncHelper + { + private static readonly TaskFactory _myTaskFactory = new + TaskFactory(CancellationToken.None, TaskCreationOptions.None, + TaskContinuationOptions.None, TaskScheduler.Default); + + // Microsoft.AspNet.Identity.AsyncHelper + public static TResult RunSync(Func> func) + { + CultureInfo cultureUi = CultureInfo.CurrentUICulture; + CultureInfo culture = CultureInfo.CurrentCulture; + return AsyncHelper._myTaskFactory.StartNew>(delegate + { + Thread.CurrentThread.CurrentCulture = culture; + Thread.CurrentThread.CurrentUICulture = cultureUi; + return func(); + }).Unwrap().GetAwaiter().GetResult(); + } + + } +} From 843f50cb7faaa289c80ed89db75d18a1266f09ce Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 22:43:14 -0400 Subject: [PATCH 19/24] fixed notimplemented problem --- src/Google.Maps/ApiCore/GoogleApiSigningService.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Google.Maps/ApiCore/GoogleApiSigningService.cs b/src/Google.Maps/ApiCore/GoogleApiSigningService.cs index 31de2ca..a071c5a 100644 --- a/src/Google.Maps/ApiCore/GoogleApiSigningService.cs +++ b/src/Google.Maps/ApiCore/GoogleApiSigningService.cs @@ -1,4 +1,5 @@ -using System; +using Google.Maps; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,14 +9,17 @@ namespace Google.ApiCore { public class GoogleApiSigningService : ISigningService { - public GoogleApiSigningService(Google.Maps.GoogleSigned signInfo) + public GoogleApiSigningService(Google.Maps.GoogleSigned signingInstance) { - + if(signingInstance == null) throw new ArgumentNullException("signingInstance"); + this._SigningInstance = signingInstance; } + private GoogleSigned _SigningInstance; + public Uri GetSignedUri(Uri value) { - throw new NotImplementedException(); + return new Uri(_SigningInstance.GetSignedUri(value)); } } } From 19463d7d1dd0f95cfc0d0803cd87ec19ef276158 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 23:13:58 -0400 Subject: [PATCH 20/24] updates to README.md regarding the dependency injection updates --- README.md | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 04a8db4..b4e90b7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ PS> Install-Package gmaps-api-net ``` ## Overview -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. +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. Recently added was stronger support for Dependency Injection for better support of mocking the requests and responses. ## API Support @@ -34,12 +34,12 @@ Google is now requiring a proper API key for accessing the service. Use the Goo 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. @@ -64,8 +64,9 @@ 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); @@ -105,33 +106,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")); +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 From 1b819defda60c180598d931e1f2b0c84ab1559b4 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 23:57:48 -0400 Subject: [PATCH 21/24] updated appveyor version number to indicate breaking change --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index a03d02a..be432b2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.20.{build} +version: 0.21.{build} pull_requests: do_not_increment_build_number: true From e91f2e8018faee002b2d7a56f846fa0818b123ca Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Sun, 29 Oct 2017 23:58:23 -0400 Subject: [PATCH 22/24] updated appveyor version number to indicate breaking change --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index a03d02a..266d621 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.20.{build} +version: 0.22.{build} pull_requests: do_not_increment_build_number: true From e267ae732bb6a20f3f330677930608b82fbf7637 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Fri, 22 Feb 2019 23:02:10 -0500 Subject: [PATCH 23/24] got project&tests building --- .../Direction/DirectionServiceTests.cs | 5 +-- .../DistanceMatrixServiceTests.cs | 3 +- .../Elevation/ElevationServiceTests.cs | 3 +- .../Geocoding/GeocodingServiceTests.cs | 5 +-- .../Places/PlaceDetailsServiceTests.cs | 3 +- .../Places/PlacesServiceTests.cs | 3 +- .../Roads/RoadsServiceTests.cs | 2 +- .../TimeZone/TimeZoneServiceTests.cs | 3 +- src/Google.Maps/ApiCore/BaseGmapsService.cs | 2 +- .../ApiCore/BaseGmapsServiceTypedResponse.cs | 2 +- src/Google.Maps/ApiCore/BaseRequest.cs | 15 +++++++++ src/Google.Maps/ApiCore/BaseServiceBuilder.cs | 2 +- .../ApiCore/GoogleApiSigningService.cs | 2 +- src/Google.Maps/ApiCore/IGMapsService.cs | 2 +- src/Google.Maps/ApiCore/IHttpService.cs | 2 +- src/Google.Maps/ApiCore/IServiceBuilder.cs | 2 +- src/Google.Maps/ApiCore/ISigningService.cs | 2 +- src/Google.Maps/Common/BaseRequest.cs | 12 ------- src/Google.Maps/Direction/DirectionRequest.cs | 2 +- .../DistanceMatrix/DistanceMatrixRequest.cs | 2 +- .../DistanceMatrix/DistanceMatrixService.cs | 4 +-- src/Google.Maps/Elevation/ElevationRequest.cs | 3 +- src/Google.Maps/Elevation/ElevationService.cs | 4 +-- src/Google.Maps/Geocoding/GeocodingRequest.cs | 2 +- src/Google.Maps/Geocoding/GeocodingService.cs | 4 +-- src/Google.Maps/Internal/AsyncHelper.cs | 31 ------------------- src/Google.Maps/Internal/MapsHttp.cs | 5 +-- src/Google.Maps/Internal/MapsHttp.cs.orig | 2 +- .../Autocomplete/AutocompleteRequest.cs | 3 +- .../Places/Details/PlaceDetailsRequest.cs | 3 +- .../Places/Details/PlaceDetailsService.cs | 4 +-- src/Google.Maps/Places/PlacesRequest.cs | 3 +- src/Google.Maps/Places/PlacesService.cs | 4 +-- src/Google.Maps/Roads/RoadsService.cs | 4 +-- src/Google.Maps/Roads/SnapToRoadsRequest.cs | 3 +- .../StaticMaps/StaticMapRequest.cs | 2 +- .../StaticMaps/StaticMapService.cs | 2 +- .../StreetView/StreetViewRequest.cs | 2 +- src/Google.Maps/TimeZone/TimeZoneRequest.cs | 3 +- src/Google.Maps/TimeZone/TimeZoneService.cs | 4 +-- src/Google.Maps/_Services.cs | 2 +- 41 files changed, 71 insertions(+), 97 deletions(-) create mode 100644 src/Google.Maps/ApiCore/BaseRequest.cs delete mode 100644 src/Google.Maps/Common/BaseRequest.cs delete mode 100644 src/Google.Maps/Internal/AsyncHelper.cs diff --git a/src/Google.Maps.Test/Direction/DirectionServiceTests.cs b/src/Google.Maps.Test/Direction/DirectionServiceTests.cs index d8decc1..d1a3501 100644 --- a/src/Google.Maps.Test/Direction/DirectionServiceTests.cs +++ b/src/Google.Maps.Test/Direction/DirectionServiceTests.cs @@ -21,8 +21,9 @@ using NUnit.Framework; -using Google.Maps.Shared; -using Google.ApiCore; +using Google.Maps.ApiCore; +using Google.Maps.Common; +using Google.Maps.Internal; namespace Google.Maps.Direction { diff --git a/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs b/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs index 8e01c0c..bfc371c 100644 --- a/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs +++ b/src/Google.Maps.Test/DistanceMatrix/DistanceMatrixServiceTests.cs @@ -2,7 +2,8 @@ using System.Collections.Generic; using NUnit.Framework; -using Google.ApiCore; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.DistanceMatrix { diff --git a/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs b/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs index 8945dfc..14f1e89 100644 --- a/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs +++ b/src/Google.Maps.Test/Elevation/ElevationServiceTests.cs @@ -18,7 +18,8 @@ using System; using NUnit.Framework; -using Google.ApiCore; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.Elevation { diff --git a/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs index a9f2acd..22efe14 100644 --- a/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs +++ b/src/Google.Maps.Test/Geocoding/GeocodingServiceTests.cs @@ -21,8 +21,9 @@ using NUnit.Framework; -using Google.Maps.Shared; -using Google.ApiCore; +using Google.Maps.Common; +using Google.Maps.ApiCore; +using Google.Maps.Internal; namespace Google.Maps.Geocoding { diff --git a/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs b/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs index 503b7e5..5300dc8 100644 --- a/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs +++ b/src/Google.Maps.Test/Places/PlaceDetailsServiceTests.cs @@ -2,7 +2,8 @@ using System.Collections.Generic; using NUnit.Framework; -using Google.ApiCore; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.Places.Details { diff --git a/src/Google.Maps.Test/Places/PlacesServiceTests.cs b/src/Google.Maps.Test/Places/PlacesServiceTests.cs index e4cac3d..7a95884 100644 --- a/src/Google.Maps.Test/Places/PlacesServiceTests.cs +++ b/src/Google.Maps.Test/Places/PlacesServiceTests.cs @@ -3,7 +3,8 @@ using System.Threading; using NUnit.Framework; -using Google.ApiCore; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.Places { diff --git a/src/Google.Maps.Test/Roads/RoadsServiceTests.cs b/src/Google.Maps.Test/Roads/RoadsServiceTests.cs index 8f16f32..d99dd3b 100644 --- a/src/Google.Maps.Test/Roads/RoadsServiceTests.cs +++ b/src/Google.Maps.Test/Roads/RoadsServiceTests.cs @@ -17,7 +17,7 @@ using System; using NUnit.Framework; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.Roads { diff --git a/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs b/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs index 6d3aa6b..0b439b5 100644 --- a/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs +++ b/src/Google.Maps.Test/TimeZone/TimeZoneServiceTests.cs @@ -19,7 +19,8 @@ using System.Collections.Generic; using NUnit.Framework; -using Google.ApiCore; +using Google.Maps.ApiCore; +using Google.Maps.Common; namespace Google.Maps.TimeZone { diff --git a/src/Google.Maps/ApiCore/BaseGmapsService.cs b/src/Google.Maps/ApiCore/BaseGmapsService.cs index e99db76..197248a 100644 --- a/src/Google.Maps/ApiCore/BaseGmapsService.cs +++ b/src/Google.Maps/ApiCore/BaseGmapsService.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.ApiCore { diff --git a/src/Google.Maps/ApiCore/BaseGmapsServiceTypedResponse.cs b/src/Google.Maps/ApiCore/BaseGmapsServiceTypedResponse.cs index 8d2d5e3..aa4cf61 100644 --- a/src/Google.Maps/ApiCore/BaseGmapsServiceTypedResponse.cs +++ b/src/Google.Maps/ApiCore/BaseGmapsServiceTypedResponse.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.ApiCore { diff --git a/src/Google.Maps/ApiCore/BaseRequest.cs b/src/Google.Maps/ApiCore/BaseRequest.cs new file mode 100644 index 0000000..4ae452f --- /dev/null +++ b/src/Google.Maps/ApiCore/BaseRequest.cs @@ -0,0 +1,15 @@ +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; } + + public abstract Uri ToUri(); + } +} \ No newline at end of file diff --git a/src/Google.Maps/ApiCore/BaseServiceBuilder.cs b/src/Google.Maps/ApiCore/BaseServiceBuilder.cs index 21f9ecc..6010c05 100644 --- a/src/Google.Maps/ApiCore/BaseServiceBuilder.cs +++ b/src/Google.Maps/ApiCore/BaseServiceBuilder.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace Google.ApiCore +namespace Google.Maps.ApiCore { public abstract class BaseServiceBuilder : IServiceBuilder { diff --git a/src/Google.Maps/ApiCore/GoogleApiSigningService.cs b/src/Google.Maps/ApiCore/GoogleApiSigningService.cs index a071c5a..77a46cd 100644 --- a/src/Google.Maps/ApiCore/GoogleApiSigningService.cs +++ b/src/Google.Maps/ApiCore/GoogleApiSigningService.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace Google.ApiCore +namespace Google.Maps.ApiCore { public class GoogleApiSigningService : ISigningService { diff --git a/src/Google.Maps/ApiCore/IGMapsService.cs b/src/Google.Maps/ApiCore/IGMapsService.cs index df97189..1067da8 100644 --- a/src/Google.Maps/ApiCore/IGMapsService.cs +++ b/src/Google.Maps/ApiCore/IGMapsService.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.ApiCore { diff --git a/src/Google.Maps/ApiCore/IHttpService.cs b/src/Google.Maps/ApiCore/IHttpService.cs index bcf7c68..3bdc032 100644 --- a/src/Google.Maps/ApiCore/IHttpService.cs +++ b/src/Google.Maps/ApiCore/IHttpService.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace Google.ApiCore +namespace Google.Maps.ApiCore { public interface IHttpService { diff --git a/src/Google.Maps/ApiCore/IServiceBuilder.cs b/src/Google.Maps/ApiCore/IServiceBuilder.cs index e957bd7..2f3cac3 100644 --- a/src/Google.Maps/ApiCore/IServiceBuilder.cs +++ b/src/Google.Maps/ApiCore/IServiceBuilder.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace Google.ApiCore +namespace Google.Maps.ApiCore { public interface IServiceBuilder diff --git a/src/Google.Maps/ApiCore/ISigningService.cs b/src/Google.Maps/ApiCore/ISigningService.cs index 2756ae4..49e8de4 100644 --- a/src/Google.Maps/ApiCore/ISigningService.cs +++ b/src/Google.Maps/ApiCore/ISigningService.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -namespace Google.ApiCore +namespace Google.Maps.ApiCore { public interface ISigningService { diff --git a/src/Google.Maps/Common/BaseRequest.cs b/src/Google.Maps/Common/BaseRequest.cs deleted file mode 100644 index 11268db..0000000 --- a/src/Google.Maps/Common/BaseRequest.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Google.Maps.Common -{ - public abstract class BaseRequest - { - public abstract Uri ToUri(); - } -} diff --git a/src/Google.Maps/Direction/DirectionRequest.cs b/src/Google.Maps/Direction/DirectionRequest.cs index eb0b6c5..b60329c 100644 --- a/src/Google.Maps/Direction/DirectionRequest.cs +++ b/src/Google.Maps/Direction/DirectionRequest.cs @@ -3,7 +3,7 @@ using System.Text; using System.ComponentModel; -using Google.Maps; +using Google.Maps.ApiCore; using Google.Maps.Common; using Google.Maps.Internal; diff --git a/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs index 906b52b..29fde90 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixRequest.cs @@ -21,7 +21,7 @@ using System.Text; using System.Linq; -using Google.Maps; +using Google.Maps.ApiCore; using Google.Maps.Common; using Google.Maps.Internal; diff --git a/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs b/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs index 7d1e3fa..97aae05 100644 --- a/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs +++ b/src/Google.Maps/DistanceMatrix/DistanceMatrixService.cs @@ -18,7 +18,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.DistanceMatrix { @@ -28,7 +28,7 @@ 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 : ApiCore.BaseGmapsServiceTypedResponse + public class DistanceMatrixService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/distancematrix/"); diff --git a/src/Google.Maps/Elevation/ElevationRequest.cs b/src/Google.Maps/Elevation/ElevationRequest.cs index b7f64de..59e69b5 100644 --- a/src/Google.Maps/Elevation/ElevationRequest.cs +++ b/src/Google.Maps/Elevation/ElevationRequest.cs @@ -17,8 +17,7 @@ using System; using System.Collections.Generic; -using Google.Maps; -using Google.Maps.Common; +using Google.Maps.ApiCore; using Google.Maps.Internal; namespace Google.Maps.Elevation diff --git a/src/Google.Maps/Elevation/ElevationService.cs b/src/Google.Maps/Elevation/ElevationService.cs index 987717c..b6ad230 100644 --- a/src/Google.Maps/Elevation/ElevationService.cs +++ b/src/Google.Maps/Elevation/ElevationService.cs @@ -18,7 +18,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.Elevation { @@ -28,7 +28,7 @@ namespace Google.Maps.Elevation /// using the four nearest locations. /// /// - public class ElevationService : ApiCore.BaseGmapsServiceTypedResponse + public class ElevationService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/elevation/"); diff --git a/src/Google.Maps/Geocoding/GeocodingRequest.cs b/src/Google.Maps/Geocoding/GeocodingRequest.cs index c337976..a4f66a2 100644 --- a/src/Google.Maps/Geocoding/GeocodingRequest.cs +++ b/src/Google.Maps/Geocoding/GeocodingRequest.cs @@ -17,7 +17,7 @@ using System; -using Google.Maps; +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 d82e763..fd71fb3 100644 --- a/src/Google.Maps/Geocoding/GeocodingService.cs +++ b/src/Google.Maps/Geocoding/GeocodingService.cs @@ -19,7 +19,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.Geocoding { @@ -29,7 +29,7 @@ namespace Google.Maps.Geocoding /// (turning coordinates into addresses); this process is known as /// "reverse geocoding." /// - public class GeocodingService : ApiCore.BaseGmapsServiceTypedResponse + public class GeocodingService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.google.com/maps/api/geocode/"); diff --git a/src/Google.Maps/Internal/AsyncHelper.cs b/src/Google.Maps/Internal/AsyncHelper.cs deleted file mode 100644 index 945af5c..0000000 --- a/src/Google.Maps/Internal/AsyncHelper.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace Google.Maps.Internal -{ - internal class AsyncHelper - { - private static readonly TaskFactory _myTaskFactory = new - TaskFactory(CancellationToken.None, TaskCreationOptions.None, - TaskContinuationOptions.None, TaskScheduler.Default); - - // Microsoft.AspNet.Identity.AsyncHelper - public static TResult RunSync(Func> func) - { - CultureInfo cultureUi = CultureInfo.CurrentUICulture; - CultureInfo culture = CultureInfo.CurrentCulture; - return AsyncHelper._myTaskFactory.StartNew>(delegate - { - Thread.CurrentThread.CurrentCulture = culture; - Thread.CurrentThread.CurrentUICulture = cultureUi; - return func(); - }).Unwrap().GetAwaiter().GetResult(); - } - - } -} diff --git a/src/Google.Maps/Internal/MapsHttp.cs b/src/Google.Maps/Internal/MapsHttp.cs index 6737ab5..5cbe66c 100644 --- a/src/Google.Maps/Internal/MapsHttp.cs +++ b/src/Google.Maps/Internal/MapsHttp.cs @@ -22,7 +22,8 @@ using System.IO; using Newtonsoft.Json; -using Google.ApiCore; +using Google.Maps.ApiCore; +using Google.Maps.Internal.Serialization; namespace Google.Maps.Internal { @@ -32,7 +33,7 @@ public class MapsHttp : IHttpService, IDisposable { Converters = new List { new JsonEnumTypeConverter(), - new JsonLocationConverter() + new JsonLatLngConverter() } }; diff --git a/src/Google.Maps/Internal/MapsHttp.cs.orig b/src/Google.Maps/Internal/MapsHttp.cs.orig index c504020..a2f24b4 100644 --- a/src/Google.Maps/Internal/MapsHttp.cs.orig +++ b/src/Google.Maps/Internal/MapsHttp.cs.orig @@ -25,7 +25,7 @@ using Newtonsoft.Json; <<<<<<< HEAD using Google.Maps.Internal.Serialization; ======= -using Google.ApiCore; +using Google.Maps.ApiCore; >>>>>>> e91f2e8018faee002b2d7a56f846fa0818b123ca namespace Google.Maps.Internal diff --git a/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs b/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs index 3add1b1..b3f9aa0 100644 --- a/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs +++ b/src/Google.Maps/Places/Autocomplete/AutocompleteRequest.cs @@ -3,8 +3,7 @@ using System.Linq; using System.Text; -using Google.Maps; -using Google.Maps.Common; +using Google.Maps.ApiCore; namespace Google.Maps.Places { diff --git a/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs b/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs index f6f557f..cd21e87 100644 --- a/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs +++ b/src/Google.Maps/Places/Details/PlaceDetailsRequest.cs @@ -3,8 +3,7 @@ using System.Linq; using System.Text; -using Google.Maps; -using Google.Maps.Common; +using Google.Maps.ApiCore; namespace Google.Maps.Places.Details { diff --git a/src/Google.Maps/Places/Details/PlaceDetailsService.cs b/src/Google.Maps/Places/Details/PlaceDetailsService.cs index 94e07ac..47d1d83 100644 --- a/src/Google.Maps/Places/Details/PlaceDetailsService.cs +++ b/src/Google.Maps/Places/Details/PlaceDetailsService.cs @@ -18,14 +18,14 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.Places.Details { /// /// Provides a direct way to access Places Details via an HTTP request. /// - public class PlaceDetailsService : ApiCore.BaseGmapsServiceTypedResponse + public class PlaceDetailsService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.googleapis.com/maps/api/place/details/"); diff --git a/src/Google.Maps/Places/PlacesRequest.cs b/src/Google.Maps/Places/PlacesRequest.cs index ab41469..c33f704 100644 --- a/src/Google.Maps/Places/PlacesRequest.cs +++ b/src/Google.Maps/Places/PlacesRequest.cs @@ -18,8 +18,7 @@ using System; using System.Linq; -using Google.Maps; -using Google.Maps.Common; +using Google.Maps.ApiCore; namespace Google.Maps.Places diff --git a/src/Google.Maps/Places/PlacesService.cs b/src/Google.Maps/Places/PlacesService.cs index c21044f..70fe880 100644 --- a/src/Google.Maps/Places/PlacesService.cs +++ b/src/Google.Maps/Places/PlacesService.cs @@ -18,7 +18,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.Places { @@ -28,7 +28,7 @@ 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 : ApiCore.BaseGmapsServiceTypedResponse + public class PlacesService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.googleapis.com/maps/api/place/"); diff --git a/src/Google.Maps/Roads/RoadsService.cs b/src/Google.Maps/Roads/RoadsService.cs index b5ed532..376e786 100644 --- a/src/Google.Maps/Roads/RoadsService.cs +++ b/src/Google.Maps/Roads/RoadsService.cs @@ -2,12 +2,12 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.Roads { - public class RoadsService : ApiCore.BaseGmapsServiceTypedResponse + public class RoadsService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://roads.googleapis.com/v1/"); diff --git a/src/Google.Maps/Roads/SnapToRoadsRequest.cs b/src/Google.Maps/Roads/SnapToRoadsRequest.cs index 7de659d..b3c7784 100644 --- a/src/Google.Maps/Roads/SnapToRoadsRequest.cs +++ b/src/Google.Maps/Roads/SnapToRoadsRequest.cs @@ -1,8 +1,7 @@ using System; using System.Linq; -using Google.Maps; -using Google.Maps.Common; +using Google.Maps.ApiCore; namespace Google.Maps.Roads { diff --git a/src/Google.Maps/StaticMaps/StaticMapRequest.cs b/src/Google.Maps/StaticMaps/StaticMapRequest.cs index 0af1a3f..ce8a692 100644 --- a/src/Google.Maps/StaticMaps/StaticMapRequest.cs +++ b/src/Google.Maps/StaticMaps/StaticMapRequest.cs @@ -20,7 +20,7 @@ using System.Collections.Generic; using Google.Maps.Internal; -using Google.Maps; +using Google.Maps.ApiCore; using Google.Maps.Common; namespace Google.Maps.StaticMaps diff --git a/src/Google.Maps/StaticMaps/StaticMapService.cs b/src/Google.Maps/StaticMaps/StaticMapService.cs index 12b69cd..13301b5 100644 --- a/src/Google.Maps/StaticMaps/StaticMapService.cs +++ b/src/Google.Maps/StaticMaps/StaticMapService.cs @@ -19,7 +19,7 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps.StaticMaps { diff --git a/src/Google.Maps/StreetView/StreetViewRequest.cs b/src/Google.Maps/StreetView/StreetViewRequest.cs index 0bdf810..9665c6f 100644 --- a/src/Google.Maps/StreetView/StreetViewRequest.cs +++ b/src/Google.Maps/StreetView/StreetViewRequest.cs @@ -19,7 +19,7 @@ using System.Linq; using System.Collections.Generic; -using Google.Maps; +using Google.Maps.ApiCore; using Google.Maps.Common; using Google.Maps.Internal; using System.ComponentModel; diff --git a/src/Google.Maps/TimeZone/TimeZoneRequest.cs b/src/Google.Maps/TimeZone/TimeZoneRequest.cs index f0e4231..0fec422 100644 --- a/src/Google.Maps/TimeZone/TimeZoneRequest.cs +++ b/src/Google.Maps/TimeZone/TimeZoneRequest.cs @@ -16,8 +16,7 @@ */ using System; -using Google.Maps; -using Google.Maps.Common; +using Google.Maps.ApiCore; namespace Google.Maps.TimeZone { diff --git a/src/Google.Maps/TimeZone/TimeZoneService.cs b/src/Google.Maps/TimeZone/TimeZoneService.cs index 8c69d82..040b1d0 100644 --- a/src/Google.Maps/TimeZone/TimeZoneService.cs +++ b/src/Google.Maps/TimeZone/TimeZoneService.cs @@ -18,14 +18,14 @@ using System.Threading.Tasks; using Google.Maps.Internal; -using Google.ApiCore; +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 : ApiCore.BaseGmapsServiceTypedResponse + public class TimeZoneService : BaseGmapsServiceTypedResponse { public static readonly Uri HttpsUri = new Uri("https://maps.googleapis.com/maps/api/timezone/outputFormat?parameters"); diff --git a/src/Google.Maps/_Services.cs b/src/Google.Maps/_Services.cs index 710f111..a42df08 100644 --- a/src/Google.Maps/_Services.cs +++ b/src/Google.Maps/_Services.cs @@ -4,7 +4,7 @@ using System.Text; using System.Threading.Tasks; -using Google.ApiCore; +using Google.Maps.ApiCore; namespace Google.Maps { From 6f28290e5ab31ab27b68ef62dec8481aa67aab49 Mon Sep 17 00:00:00 2001 From: Eric Newton Date: Fri, 22 Feb 2019 23:12:20 -0500 Subject: [PATCH 24/24] remove accidental orig files --- src/Google.Maps/Google.Maps.csproj.orig | 27 ------ src/Google.Maps/Internal/MapsHttp.cs.orig | 102 ---------------------- 2 files changed, 129 deletions(-) delete mode 100644 src/Google.Maps/Google.Maps.csproj.orig delete mode 100644 src/Google.Maps/Internal/MapsHttp.cs.orig diff --git a/src/Google.Maps/Google.Maps.csproj.orig b/src/Google.Maps/Google.Maps.csproj.orig deleted file mode 100644 index 5bf3d52..0000000 --- a/src/Google.Maps/Google.Maps.csproj.orig +++ /dev/null @@ -1,27 +0,0 @@ - - - net461;netstandard1.3 - True - sn.snk - False - False - - - HAS_SYSTEMDRAWING - - -<<<<<<< HEAD - - - -======= - ->>>>>>> e91f2e8018faee002b2d7a56f846fa0818b123ca - - - - - - - - \ No newline at end of file diff --git a/src/Google.Maps/Internal/MapsHttp.cs.orig b/src/Google.Maps/Internal/MapsHttp.cs.orig deleted file mode 100644 index a2f24b4..0000000 --- a/src/Google.Maps/Internal/MapsHttp.cs.orig +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using System.IO; - -using Newtonsoft.Json; -<<<<<<< HEAD -using Google.Maps.Internal.Serialization; -======= -using Google.Maps.ApiCore; ->>>>>>> e91f2e8018faee002b2d7a56f846fa0818b123ca - -namespace Google.Maps.Internal -{ - public class MapsHttp : IHttpService, IDisposable - { - JsonSerializerSettings settings = new JsonSerializerSettings - { -<<<<<<< HEAD - Converters = new List - { - new JsonEnumTypeConverter(), - new JsonLatLngConverter() -======= - Converters = new List { - new JsonEnumTypeConverter(), - new JsonLocationConverter() ->>>>>>> e91f2e8018faee002b2d7a56f846fa0818b123ca - } - }; - - ISigningService signingSvc; - HttpClient client; - - public MapsHttp(ISigningService signingSvc) - { - this.signingSvc = signingSvc; - this.client = new HttpClient(); - } - - public async Task GetAsync(Uri uri) where T : class - { - if(this.signingSvc != null) - { - uri = signingSvc.GetSignedUri(uri); - } - - var json = await client.GetStringAsync(uri).ConfigureAwait(false); - - var result = JsonConvert.DeserializeObject(json, settings); - - return result; - } - - public T Get(Uri uri) where T : class - { - return GetAsync(uri).GetAwaiter().GetResult(); - } - - public async Task GetStreamAsync(Uri uri) - { - if(this.signingSvc != null) - { - uri = signingSvc.GetSignedUri(uri); - } - - return await client.GetStreamAsync(uri).ConfigureAwait(false); - } - - public Stream GetStream(Uri uri) - { - return GetStreamAsync(uri).GetAwaiter().GetResult(); - } - - public void Dispose() - { - if (client != null) - { - client.Dispose(); - client = null; - } - } - } -} \ No newline at end of file