Commit 72dc71af authored by Jason Ouellet's avatar Jason Ouellet

Ajouter les paramêtres pour la gestion d'un Camion dans l'API Route

parent 49c92dc6
......@@ -12,7 +12,7 @@ namespace HereTruckDistance.Core
{
}
public ConfigurationException(string configValue) :
public ConfigurationException(string configValue) :
base(string.Format(MessageFormat, configValue))
{
}
......
......@@ -5,14 +5,12 @@ namespace HereTruckDistance.Core
{
public class HereConfig : IHereConfig
{
public string HereUri { get; set; }
public string HereAppId { get; set; }
public string HereAppCode { get; set; }
public IDictionary<String, String> Services { get; set; }
public string AppId { get; set; }
public string AppCode { get; set; }
public IDictionary<String, String> UriServices { get; set; }
public HereConfig()
{
}
}
}
\ No newline at end of file
......@@ -4,9 +4,8 @@ namespace HereTruckDistance.Core
{
public interface IHereConfig
{
string HereAppCode { get; set; }
string HereAppId { get; set; }
string HereUri { get; set; }
IDictionary<string, string> Services { get; set; }
string AppCode { get; set; }
string AppId { get; set; }
IDictionary<string, string> UriServices { get; set; }
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
namespace HereTruckDistance.Core
namespace HereTruckDistance.Core
{
public enum RouteMode
{
......@@ -10,4 +6,4 @@ namespace HereTruckDistance.Core
car,
truck,
}
}
}
\ No newline at end of file
namespace HereTruckDistance.Core
{
public enum ShippedHazardousGoods
{
explosive,
gas,
flammable,
combustible,
organic,
poison,
radioActive,
corrosive,
poisonousInhalation,
harmfulToWater,
other
}
}
\ No newline at end of file
namespace HereTruckDistance.Core
{
public enum TruckRestrictionPenalty
{
strict,
soft,
}
}
\ No newline at end of file
namespace HereTruckDistance.Core
{
public enum TruckType
{
truck,
tractorTruck,
}
}
\ No newline at end of file
namespace HereTruckDistance.Core
{
public enum TunnelCategory
{
B,
C,
D,
E,
}
}
\ No newline at end of file
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Globalization;
namespace HereTruckDistance.Core
{
public class HereGeocoderRequest : HereRequest
{
public Localisation PointDepart { get; set; }
public Localisation PointDestination { get; set; }
public IList<string> Mode { get; set; }
public bool Trafic { get; set; }
public decimal LimitePoids { get; set; }
public decimal Height { get; set; }
public string ShippedHazardousGoods { get; set; }
public HereGeocoderRequest(IConfiguration config) : base(config, "GeocoderSvc")
{
PointDepart = new Localisation(52.5m, 13.4m);
PointDestination = new Localisation(52.5m, 13.45m);
Mode = new List<string> { "fastest", "truck", "traffic:disabled" };
LimitePoids = 30.5m;
Height = 30.5m;
ShippedHazardousGoods = "harmfulToWater";
}
public Uri GetRequest()
{
//TODO: À changer pour un string builder
UriBuilder uri = new UriBuilder(ServiceUri);
uri.Query = string.Format("app_id={0}&app_code={1}" +
"&housenumber={2}" +
"&street={3}" +
"&city={4}" +
"&country={5}" +
"&gen=9" +
"&language=fr-fr",
AppId,
AppCode,
PointDepart.GetPointString(),
PointDestination.GetPointString(),
LimitePoids.ToString(CultureInfo.InvariantCulture),
Height.ToString(CultureInfo.InvariantCulture)
);
return uri.Uri;
}
}
}
\ No newline at end of file
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Runtime.Serialization;
namespace HereTruckDistance.Core
{
public abstract class HereRequest
{
public string Uri { get { return _config.HereUri; } }
public string AppId { get { return _config.HereAppId; } }
public string AppCode { get { return _config.HereAppCode; } }
public string Service { get; set; }
protected string AppId { get; private set; }
protected string AppCode { get; private set; }
protected string ServiceUri { get; private set; }
protected readonly HereConfig _config;
protected HereRequest(IConfiguration config)
{
_config = new HereConfig();
_config.HereUri = config.GetSection("HereConfig:HereUri").Value;
_config.HereAppId = config.GetSection("HereConfig:HereAppId").Value;
_config.HereAppCode = config.GetSection("HereConfig:HereAppCode").Value;
}
public Uri GetUri()
protected HereRequest(IConfiguration config, string service)
{
Valider();
var retourUri = new UriBuilder(Uri);
retourUri.Query = Service;
return retourUri.Uri;
AppId = config.GetSection("HereConfig:AppId").Value;
AppCode = config.GetSection("HereConfig:AppCode").Value;
ServiceUri = config.GetSection("HereConfig:UriServices:RouteSrv").Value;
}
private void Valider()
{
if (Uri is null || Uri.Length == 0) {
throw new ConfigurationException(nameof(Uri));
}
if (AppId is null || AppId.Length == 0)
{
throw new ConfigurationException(nameof(AppId));
......@@ -45,12 +26,10 @@ namespace HereTruckDistance.Core
{
throw new ConfigurationException(nameof(AppCode));
}
if (Service is null || Service.Length == 0)
if (ServiceUri is null || string.IsNullOrEmpty(ServiceUri))
{
throw new ConfigurationException(nameof(Service));
throw new ConfigurationException(nameof(Uri));
}
}
}
}
\ No newline at end of file
......@@ -4,9 +4,8 @@ namespace HereTruckDistance.Core
{
public class HereRouteRequest : HereRequest
{
public HereRouteRequest(IConfiguration config) :base(config)
public HereRouteRequest(IConfiguration config) :base(config, "RouteSrv")
{
Service = _config.Services["HereSrvRoute"].ToString();
}
}
......
......@@ -15,7 +15,7 @@ namespace HereTruckDistance.Core
public decimal Height { get; set; }
public string ShippedHazardousGoods { get; set; }
public HereRouteTruckRequest(IConfiguration config) : base(config)
public HereRouteTruckRequest(IConfiguration config) : base(config, "RouteSvc")
{
PointDepart = new Localisation(52.5m, 13.4m);
PointDestination = new Localisation(52.5m, 13.45m);
......@@ -28,18 +28,23 @@ namespace HereTruckDistance.Core
public Uri GetRequest()
{
//TODO: À changer pour un string builder
UriBuilder uri = new UriBuilder(Uri);
UriBuilder uri = new UriBuilder(ServiceUri);
uri.Query = string.Format("app_id={0}&app_code={1}" +
"&waypoint0=geo!{2}" +
"&waypoint1=geo!{3}" +
"&mode=fastest;truck;traffic:disabled" +
"&limitedWeight={4}" +
"&height={5}" +
"&width=2.5" +
"&length=7" +
"&shippedHazardousGoods=harmfulToWater",
"&routeattributes=sm",
"&maneuverattributes=di",
"&language=fr-fr",
AppId,
AppCode,
PointDepart.Point,
PointDestination.Point,
PointDepart.GetPointString(),
PointDestination.GetPointString(),
LimitePoids.ToString(CultureInfo.InvariantCulture),
Height.ToString(CultureInfo.InvariantCulture)
);
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Globalization;
namespace HereTruckDistance.Core
{
......@@ -10,12 +7,20 @@ namespace HereTruckDistance.Core
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
public string Point { get { return string.Format("{0},{1}", Latitude.ToString(CultureInfo.InvariantCulture), Longitude.ToString(CultureInfo.InvariantCulture)); }}
public Localisation(decimal latitude, decimal longitude)
{
Latitude = latitude;
Longitude = longitude;
}
}
}
public static class LocalisationExtension
{
public static string GetPointString(this Localisation localisation)
{
return string.Format("{0},{1}",
localisation.Latitude.ToString(CultureInfo.InvariantCulture),
localisation.Longitude.ToString(CultureInfo.InvariantCulture));
}
}
}
\ No newline at end of file
namespace HereTruckDistance.Core
{
public interface IParamBase
{
string Nom { get; }
string ValeurStr { get; }
string ToString();
}
}
\ No newline at end of file
using System;
namespace HereTruckDistance.Core
{
public class ParamsBase<T> : IParamBase where T : notnull
{
public ParamsBase(string nom)
{
Nom = nom ?? throw new ArgumentNullException(nameof(nom));
}
public ParamsBase(string nom, T valeur) : this(nom)
{
Valeur = valeur ?? throw new ArgumentNullException(nameof(valeur));
}
public T Valeur { get; set; }
public string Nom { get; private set; }
public string ValeurStr { get { return string.Format("{0}", Valeur); } }
public override string ToString()
{
; return string.Format("{0} = {1}", Nom, ValeurStr);
}
}
}
\ No newline at end of file
namespace HereTruckDistance.Core
{
public class ParamsEnum<T> : ParamsBase<T>
{
public ParamsEnum(string nom, T valeur) : base(nom, valeur)
{
}
public override string ToString()
{
return base.ToString().ToLower();
}
}
}
\ No newline at end of file
Références :
Routing :
https://developer.here.com/documentation/maps/topics/routing.html
Weight restrictions :
https://developer.here.com/api-explorer/rest/routing/truck-route-weight-restrictions
Hazardous Goods :
https://developer.here.com/api-explorer/rest/routing/truck-route-for-hazardous-goods
Abnormal loads :
https://developer.here.com/api-explorer/rest/routing/truck-route-dimension-restrictions
Multi-Language :
https://developer.here.com/api-explorer/rest/routing/route-with-language-support
Calculate Route :
Documentation sur tous les paramètres disponibles de l'API
https://developer.here.com/documentation/routing/topics/resource-calculate-route.html
Profil pour Camions :
https://developer.here.com/documentation/routing/topics/filtering-truck-routing-requests.html#filtering-truck-routing-requests__truck-profile
using System.Collections.Generic;
using System.Linq;
namespace HereTruckDistance.Core
{
public class TruckProfileParams
{
public Dictionary<string, IParamBase> Parametres { get; set; }
public override string ToString()
{
return string.Join(" ", Parametres.Select(kv => kv.ToString()).ToArray());
}
}
}
\ No newline at end of file
using System;
namespace HereTruckDistance.Core
{
public static class TruckProfileParamsExtensions
{
private const string ErrorMsgValueBetween = "La valeur doit être entre {0} et {1}";
/// <summary>
/// Truck routing only, specifies the vehicle type.Defaults to truck.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">Enum [truck | tractorTruck]</param>
public static void AddTruckType(this TruckProfileParams tpParams, TruckType valeur)
{
string nom = "truckType";
var param = new ParamsEnum<TruckType>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, specifies number of trailers pulled by the vehicle.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">The provided value must be between 0 and 4. Defaults to 0.</param>
public static void AddTrailersCount(this TruckProfileParams tpParams, int valeur)
{
if (valeur < 0 && valeur > 4) throw new ArgumentException(string.Format(ErrorMsgValueBetween, 0, 4), nameof(valeur));
string nom = "trailerCount";
var param = new ParamsBase<int>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, specifies number of axles on the vehicle.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">The provided value must be between 2 and 254. Defaults to 2.</param>
public static void AddAxleCount(this TruckProfileParams tpParams, int valeur)
{
if (valeur < 2 && valeur > 254) throw new ArgumentException(string.Format(ErrorMsgValueBetween, 2, 254), nameof(valeur));
string nom = "axleCount";
var param = new ParamsBase<int>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, list of hazardous materials in the vehicle. Please refer to the enumeration type HazardousGoodTypeType for available values.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">Enum [explosive | gas | flammable | combustible | organic | poison | radioActive | corrosive | poisonousInhalation | harmfulToWater | other]</param>
public static void AddShippedHazardousGoods(this TruckProfileParams tpParams, ShippedHazardousGoods valeur)
{
string nom = "shippedHazardousGoods";
var param = new ParamsEnum<ShippedHazardousGoods>(nom,valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, vehicle weight including trailers and shipped goods, in tons.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">The provided value must be between 0 and 1000.</param>
public static void AddLimitedWeight(this TruckProfileParams tpParams, int valeur)
{
if (valeur < 0 && valeur > 1000) throw new ArgumentException(string.Format(ErrorMsgValueBetween, 0, 1000), nameof(valeur));
string nom = "limitedWeight";
var param = new ParamsBase<int>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, vehicle weight per axle in tons.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">The provided value must be between 0 and 1000.</param>
public static void AddWeightPerAxle(this TruckProfileParams tpParams, int valeur)
{
if (valeur < 0 && valeur > 1000) throw new ArgumentException(string.Format(ErrorMsgValueBetween, 0, 1000), nameof(valeur));
string nom = "weightPerAxle";
var param = new ParamsBase<int>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
//TODO: weightsPerAxleGroup
/// <summary>
/// Truck routing only, vehicle height in meters.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">The provided value must be between 0 and 50.</param>
public static void AddHeight(this TruckProfileParams tpParams, int valeur)
{
if (valeur < 0 && valeur > 50) throw new ArgumentException(string.Format(ErrorMsgValueBetween, 0, 50), nameof(valeur));
string nom = "height";
var param = new ParamsBase<int>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, vehicle width in meters.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">The provided value must be between 0 and 50.</param>
public static void AddWidth(this TruckProfileParams tpParams, int valeur)
{
if (valeur < 0 && valeur > 50) throw new ArgumentException(string.Format(ErrorMsgValueBetween, 0, 50), nameof(valeur));
string nom = "width";
var param = new ParamsBase<int>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, vehicle length in meters.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">The provided value must be between 0 and 300.</param>
public static void AddLength(this TruckProfileParams tpParams, int valeur)
{
if (valeur < 0 && valeur > 300) throw new ArgumentException(string.Format(ErrorMsgValueBetween, 0, 300), nameof(valeur));
string nom = "length";
var param = new ParamsBase<int>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, specifies the tunnel category to restrict certain route links. The route will pass only through tunnels of a less strict category.
/// </summary>
/// <param name="tpParams"></param>
/// <param name="valeur">Enum [ B | C | D | E ]</param>
public static void AddTunnelCategory(this TruckProfileParams tpParams, TunnelCategory valeur)
{
string nom = "tunnelCategory";
var param = new ParamsEnum<TunnelCategory>(nom, valeur);
if (!tpParams.Parametres.TryAdd(nom, param))
{
tpParams.Parametres.Remove(nom);
tpParams.Parametres.Add(nom, param);
}
}
/// <summary>
/// Truck routing only, specifies the penalty type on violated truck restrictions.
/// Defaults to strict.
/// Refer to the enumeration type TruckRestrictionPenaltyType for details on available values.
/// Note that the route computed with the penalty type soft will use links with a violated truck restriction if there is no alternative to avoid them.
/// The route violating truck restrictions is then indicated with dedicated route and maneuver notes in the response
/// </summary>