This commit is contained in:
Chris French 2018-08-28 23:58:21 -07:00
Родитель 3845414ae0
Коммит 97aca93ae8
11 изменённых файлов: 319 добавлений и 65 удалений

Просмотреть файл

@ -25,6 +25,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Console", "Console", "{80170A9E-5ACF-483A-8A8E-18CA7B0C9A34}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RESTToolkitTestConsoleApp", "Samples\Console\RESTToolkitTestConsoleApp\RESTToolkitTestConsoleApp.csproj", "{3BE4FCCE-768A-4ABE-AF3E-938B5D884AC8}"
ProjectSection(ProjectDependencies) = postProject
{F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F} = {F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BingMapsRESTToolkit.Standard", "Source\BingMapsRESTToolkit.Standard\BingMapsRESTToolkit.Standard.csproj", "{F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F}"
EndProject
@ -84,4 +87,7 @@ Global
{5F797BB6-13E8-4A02-BC01-613FC791EB41} = {833D0345-46F0-486E-9BEF-5269405683F8}
{5173922A-0160-4EE1-9AD8-F629B23CFE71} = {26E65B0F-9554-408A-95D4-BDEC52945FC3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3DB70BA-969B-47D7-8A77-65B190E2CC81}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -1,34 +1,86 @@
using BingMapsRESTToolkit;
using System;
namespace RESTToolkitTestConsoleApp.NetStandard
namespace RESTToolkitTestConsoleApp
{
class Program
class Tests
{
static void Main(string[] args)
{
var r = ServiceManager.GetResponseAsync(new GeocodeRequest()
{
BingMapsKey = System.Configuration.ConfigurationManager.AppSettings.Get("BingMapsKey"),
Query = "Seattle"
}).GetAwaiter().GetResult();
private string _ApiKey = System.Configuration.ConfigurationManager.AppSettings.Get("BingMapsKey");
if (r != null && r.ResourceSets != null &&
private Resource[] GetResourcesFromRequest(BaseRestRequest rest_request)
{
var r = ServiceManager.GetResponseAsync(rest_request).GetAwaiter().GetResult();
if (!(r != null && r.ResourceSets != null &&
r.ResourceSets.Length > 0 &&
r.ResourceSets[0].Resources != null &&
r.ResourceSets[0].Resources.Length > 0)
r.ResourceSets[0].Resources.Length > 0))
throw new Exception("No results found.");
return r.ResourceSets[0].Resources;
}
public void AutoSuggestTest()
{
}
public void LocationRecogTest()
{
Console.WriteLine("Running Location Recognition Test");
Coordinate cpoint = new Coordinate(47.668915, -122.375789);
Console.WriteLine("coord: {0}", cpoint.ToString());
var request = new LocationRecogRequest() { BingMapsKey = _ApiKey, CenterPoint = cpoint };
Console.WriteLine("constructed!");
Console.WriteLine(request.GetRequestUrl());
var resources = GetResourcesFromRequest(request);
foreach (LocationRecog resource in resources)
{
for (var i = 0; i < r.ResourceSets[0].Resources.Length; i++)
{
Console.WriteLine((r.ResourceSets[0].Resources[i] as Location).Name);
}
Console.WriteLine(resource);
}
else
Console.ReadLine();
}
public void GeoCodeTest()
{
Console.WriteLine("Running Geocode Test");
var request = new GeocodeRequest()
{
Console.WriteLine("No results found.");
BingMapsKey = _ApiKey,
Query = "Seattle"
};
var resources = GetResourcesFromRequest(request);
foreach (var resource in resources)
{
Console.WriteLine((resource as Location).Name);
}
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
Tests tests = new Tests();
tests.GeoCodeTest();
tests.LocationRecogTest();
}
}
}

Просмотреть файл

@ -17,7 +17,7 @@ namespace RESTToolkitTestConsoleApp
r.ResourceSets[0].Resources.Length > 0))
throw new Exception("No results found.");
return r.ResourceSets[0].Resources;
}
@ -30,23 +30,40 @@ namespace RESTToolkitTestConsoleApp
{
Console.WriteLine("Running Location Recognition Test");
var cpoint = new Coordinate(47.668915, -122.375789);
Coordinate cpoint = new Coordinate(47.668915, -122.375789);
Console.WriteLine("coord: {0}", cpoint.ToString());
var request = new LocationRecogRequest();
request.BingMapsKey = _ApiKey;
request.CenterPoint = cpoint;
var request = new LocationRecogRequest() { BingMapsKey = _ApiKey, CenterPoint = cpoint };
Console.WriteLine("constructed!");
Console.WriteLine(request.GetRequestUrl());
var resources = GetResourcesFromRequest(request);
foreach (var resource in resources)
{
Console.WriteLine(resource);
}
var r = (resources[0] as LocationRecog);
if (r.AddressOfLocation.Length > 0)
Console.WriteLine($"Address:\n{r.AddressOfLocation.ToString()}");
if (r.BusinessAtLocation != null)
{
foreach (LocalBusiness business in r.BusinessAtLocation)
{
Console.WriteLine($"Business:\n{business.BusinessInfo.EntityName}");
}
}
if (r.NaturalPOIAtLocation != null)
{
foreach (NaturalPOIAtLocationEntity poi in r.NaturalPOIAtLocation)
{
Console.WriteLine($"POI:\n{poi.EntityName}");
}
}
Console.ReadLine();
}
@ -61,7 +78,7 @@ namespace RESTToolkitTestConsoleApp
};
var resources = GetResourcesFromRequest(request);
foreach (var resource in resources)
{
Console.WriteLine((resource as Location).Name);
@ -71,7 +88,6 @@ namespace RESTToolkitTestConsoleApp
}
}
class Program
{
static void Main(string[] args)
@ -80,7 +96,5 @@ namespace RESTToolkitTestConsoleApp
tests.GeoCodeTest();
tests.LocationRecogTest();
}
}
}

Просмотреть файл

@ -115,6 +115,14 @@
<Compile Include="..\Models\ResponseModels\TransitLine.cs" Link="Models\ResponseModels\TransitLine.cs" />
<Compile Include="..\Models\ResponseModels\Warning.cs" Link="Models\ResponseModels\Warning.cs" />
<Compile Include="..\Models\ResponseModels\Waypoint.cs" Link="Models\ResponseModels\Waypoint.cs" />
<Compile Include="..\Models\ResponseModels\NaturalPOIAtLocationEntity.cs" Link="Models\ResponseModels\NaturalPOIAtLocationEntity.cs" />
<Compile Include="..\Models\ResponseModels\LocationRecog.cs" Link="Models\ResponseModels\LocationRecog.cs" />
<Compile Include="..\Models\ResponseModels\LocalBusiness.cs" Link="Models\ResponseModels\LocalBusiness.cs" />
<Compile Include="..\Models\ResponseModels\BusinessInfoEntity.cs" Link="Models\ResponseModels\BusinessInfoEntity.cs" />
<Compile Include="..\Models\RouteOptions.cs" Link="Models\RouteOptions.cs" />
<Compile Include="..\Models\SimpleAddress.cs" Link="Models\SimpleAddress.cs" />
<Compile Include="..\Models\SimpleWaypoint.cs" Link="Models\SimpleWaypoint.cs" />

Просмотреть файл

@ -81,6 +81,7 @@
<Compile Include="Models\CustomMapStyles\SettingsStyle.cs" />
<Compile Include="Models\ImageryPushpin.cs" />
<Compile Include="Models\ResponseModels\BirdseyeMetadata.cs" />
<Compile Include="Models\ResponseModels\BusinessInfoEntity.cs" />
<Compile Include="Models\ResponseModels\CompressedPointList.cs" />
<Compile Include="Models\ResponseModels\CoverageArea.cs" />
<Compile Include="Models\ResponseModels\Detail.cs" />
@ -96,6 +97,9 @@
<Compile Include="Models\ResponseModels\ImageryMetadata.cs" />
<Compile Include="Models\ResponseModels\ImageryProvider.cs" />
<Compile Include="Models\ResponseModels\Instruction.cs" />
<Compile Include="Models\ResponseModels\LocalBusiness.cs" />
<Compile Include="Models\ResponseModels\LocationRecog.cs" />
<Compile Include="Models\ResponseModels\NaturalPOIAtLocationEntity.cs" />
<Compile Include="Models\ResponseModels\RouteProxyAsyncResult.cs" />
<Compile Include="Models\ResponseModels\IsochroneResponse.cs" />
<Compile Include="Models\ResponseModels\ItineraryItem.cs" />

Просмотреть файл

@ -0,0 +1,48 @@
using System;
using System.Runtime.Serialization;
namespace BingMapsRESTToolkit
{
/// <summary>
/// Bussiness Info Entity Resource, used by Location Recognition
/// </summary>
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
public class BusinessInfoEntity
{
/// <summary>
/// Unique ID for Business
/// </summary>
[DataMember(Name = "id", EmitDefaultValue = false)]
public string Id { get; set; }
/// <summary>
/// Name of the business entity
/// </summary>
[DataMember(Name = "entityName", EmitDefaultValue = false)]
public string EntityName { get; set; }
/// <summary>
/// Website URL of the business entity
/// </summary>
[DataMember(Name = "url", EmitDefaultValue = false)]
public Uri URL { get; set; }
/// <summary>
/// Phone number of the business entity
/// </summary>
[DataMember(Name = "phone", EmitDefaultValue = false)]
public string Phone { get; set; }
/// <summary>
/// Category Business Type ID
/// </summary>
[DataMember(Name = "typeId", EmitDefaultValue = false)]
public int TypeId { get; set; }
/// <summary>
/// Category Business Type ID List
/// </summary>
[DataMember(Name = "otherTypeIds", EmitDefaultValue = false)]
public int[] OtherTypeIds { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,30 @@
using System;
using System.Runtime.Serialization;
namespace BingMapsRESTToolkit
{
/// <summary>
/// Local Business Resoruce, used by Location Recognition
/// </summary>
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
public class LocalBusiness
{
[DataMember(Name = "businessAddress", EmitDefaultValue = false)]
public Address BusinessAddress { get; set; }
[DataMember(Name = "businessInfo", EmitDefaultValue = false)]
public BusinessInfoEntity BusinessInfo { get; set; }
/// <summary>
/// Type of business entity representing the primary nature of business of the entity. Refer to the Business Entity Types table below for a full list of supported types
/// </summary>
[DataMember(Name = "type", EmitDefaultValue = false)]
public string Type { get; set; }
/// <summary>
/// List of types which represent the secondary nature of business of the entity
/// </summary>
[DataMember(Name = "otherTypes", EmitDefaultValue = false)]
public string[] OhterTypes { get; set; }
}
}

Просмотреть файл

@ -0,0 +1,37 @@
using System;
using System.Runtime.Serialization;
namespace BingMapsRESTToolkit
{
/// <summary>
/// A LocationRecog response object returned by the LocationRecog operation.
/// </summary>
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
public class LocationRecog : Resource
{
[DataMember(Name = "isPrivateResidence", EmitDefaultValue = false)]
public string _IsPrivateResidence { get; set; }
public bool IsPrivateResidence
{
get
{
return bool.Parse(_IsPrivateResidence);
}
set
{
_IsPrivateResidence = value.ToString();
}
}
[DataMember(Name = "businessesAtLocation", EmitDefaultValue = false)]
public LocalBusiness[] BusinessAtLocation { get; set; }
[DataMember(Name = "addressOfLocation", EmitDefaultValue = false)]
public Address[] AddressOfLocation { get; set; }
[DataMember(Name = "naturalPOIAtLocation", EmitDefaultValue = false)]
public NaturalPOIAtLocationEntity[] NaturalPOIAtLocation { get; set;}
}
}

Просмотреть файл

@ -0,0 +1,21 @@
using System;
using System.Runtime.Serialization;
namespace BingMapsRESTToolkit
{
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
public class NaturalPOIAtLocationEntity
{
[DataMember(Name = "entityName", EmitDefaultValue = false)]
public string EntityName { get; set; }
[DataMember(Name = "latitude", EmitDefaultValue = false)]
public double Latitude { get; set; }
[DataMember(Name = "longitude", EmitDefaultValue = false)]
public double Longitude { get; set; }
[DataMember(Name = "type", EmitDefaultValue = false)]
public string Type { get; set; }
}
}

Просмотреть файл

@ -42,6 +42,7 @@ namespace BingMapsRESTToolkit
[KnownType(typeof(DistanceMatrixAsyncStatus))]
[KnownType(typeof(IsochroneResponse))]
[KnownType(typeof(SnapToRoadResponse))]
[KnownType(typeof(LocationRecog))]
public class Resource
{
/// <summary>

Просмотреть файл

@ -11,34 +11,76 @@ namespace BingMapsRESTToolkit
{
#region Private Properties
/// <summary>
/// Constant Max value for Top param: 20
/// </summary>
private const int MaxTop = 20;
private readonly int MaxTop = 20;
private readonly double maxRadKilo = 2.0;
/// <summary>
/// Constant Max distance for Radius in KM : 2 KM
/// </summary>
private const double maxRadKilo = 2.0;
/// <summary>
/// Constant Max distance for Radius in Miles : Using built-in distance converter
/// </summary>
private readonly double maxRadMile = SpatialTools.ConvertDistance(2.0, DistanceUnitType.Kilometers, DistanceUnitType.Miles);
/// <summary>
/// Radius value
/// </summary>
private double _Radius;
/// <summary>
/// Top value
/// </summary>
private int _Top;
/// <summary>
/// List of LocationRecog EntityType Enums
/// </summary>
private List<LocationRecogEntityTypes> _IncludeEntityTypes;
#endregion
#region Constructor
/// <summary>
/// Constructor with default values
/// </summary>
public LocationRecogRequest() : base()
{
DistanceUnits = DistanceUnitType.Kilometers;
Radius = 0.25;
Top = 20;
DistanceUnits = DistanceUnitType.Kilometers;
VerbosePlaceNames = false;
IncludeEntityTypes = "businessAndPOI";
_IncludeEntityTypes = new List<LocationRecogEntityTypes>() { LocationRecogEntityTypes.BusinessAndPOI };
_Radius = 0.25;
_Top = 10;
}
#endregion
#region Public Properties
/// <summary>
/// Location Recog at this point (lat,lon)
/// </summary>
public Coordinate CenterPoint { get; set; }
/// <summary>
/// Optional DateTime parameter.
/// </summary>
public DateTime? DateTimeInput { get; set; }
/// <summary>
/// Library `DistanceUnitType` Enum, either `Kilometers` or `Miles`
/// </summary>
public DistanceUnitType DistanceUnits { get; set; }
/// <summary>
/// Consumer-facing IncludeEntity Types:
/// - setter with value as comma-separated string, e.g. "Address, NaturalPoi".
/// - getter as comma-separated string, all lower-case and trimmed, e.g. "address,naturalpoi".
/// </summary>
public string IncludeEntityTypes
{
get
@ -85,7 +127,7 @@ namespace BingMapsRESTToolkit
}
this._IncludeEntityTypes = _types;
_IncludeEntityTypes = _types;
}
}
@ -93,12 +135,12 @@ namespace BingMapsRESTToolkit
{
get
{
return this.Top;
return _Top;
}
set
{
this.Top = (value > MaxTop) ? MaxTop : value;
_Top = (value >= MaxTop) ? MaxTop : value;
}
}
@ -110,12 +152,26 @@ namespace BingMapsRESTToolkit
{
get
{
return Radius;
return _Radius;
}
set
{
if (ValidateRadius(value))
Radius = value;
double rad = (double)value;
switch (DistanceUnits)
{
case DistanceUnitType.Kilometers:
if (0 <= rad && rad <= maxRadKilo)
_Radius = rad;
else
throw new Exception($"The maximum radius is {maxRadKilo} KM but {rad} KM was entered.");
break;
case DistanceUnitType.Miles:
if (0 <= rad && rad <= maxRadMile)
_Radius = rad;
else
throw new Exception($"The maximum radius is {maxRadMile} Miles but {rad} Miles was entered.");
break;
}
}
}
@ -123,29 +179,6 @@ namespace BingMapsRESTToolkit
#endregion
#region Private Methods
private bool ValidateRadius(double rad)
{
switch(_DistanceUnitType)
{
case DistanceUnitType.Kilometers:
if (0 <= rad && rad <= maxRadKilo)
return true;
else
throw new Exception($"The maximum radius is {maxRadKilo} KM but {rad} KM was entered.");
case DistanceUnitType.Miles:
if (0 <= rad && rad <= maxRadMile)
return true;
else
throw new Exception($"The maximum radius is {maxRadMile} Miles but {rad} Miles was entered.");
}
return false;
}
#endregion
#region Public Methods