Commit d2a56924 authored by Jason Ouellet's avatar Jason Ouellet

Ménage !

parent 09cdfa56
using System;
namespace HereTruckDistance.Core
{
public class CalculateRouteModel
{
}
}
using System;
using System.Runtime.Serialization;
namespace HereTruckDistance.Core
{
[Serializable]
public class ConfigurationException : Exception
{
private const string MessageFormat = "La valeur {0} n'est pas configuré correctement";
public ConfigurationException()
{
}
public ConfigurationException(string configValue) :
base(string.Format(MessageFormat, configValue))
{
}
public ConfigurationException(string configValue, Exception innerException) :
base(string.Format(MessageFormat, configValue), innerException)
{
}
protected ConfigurationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
namespace HereTruckDistance.Core
{
public class HereConfig : IHereConfig
{
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
using System.Collections.Generic;
namespace HereTruckDistance.Core
{
public interface IHereConfig
{
string AppCode { get; set; }
string AppId { get; set; }
IDictionary<string, string> UriServices { get; set; }
}
}
\ No newline at end of file
namespace HereTruckDistance.Core
{
public enum RouteMode
{
fastest,
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 System;
namespace HereTruckDistance.Core
{
public abstract class HereRequest
{
protected string AppId { get; private set; }
protected string AppCode { get; private set; }
protected string ServiceUri { get; private set; }
protected HereRequest(IConfiguration config, string service)
{
AppId = config.GetSection("HereConfig:AppId").Value;
AppCode = config.GetSection("HereConfig:AppCode").Value;
ServiceUri = config.GetSection("HereConfig:UriServices:RouteSrv").Value;
}
private void Valider()
{
if (AppId is null || AppId.Length == 0)
{
throw new ConfigurationException(nameof(AppId));
}
if (AppCode is null || AppCode.Length == 0)
{
throw new ConfigurationException(nameof(AppCode));
}
if (ServiceUri is null || string.IsNullOrEmpty(ServiceUri))
{
throw new ConfigurationException(nameof(Uri));
}
}
}
}
\ No newline at end of file
using Microsoft.Extensions.Configuration;
namespace HereTruckDistance.Core
{
public class HereRouteRequest : HereRequest
{
public HereRouteRequest(IConfiguration config) :base(config, "RouteSrv")
{
}
}
}
\ No newline at end of file
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Globalization;
namespace HereTruckDistance.Core
{
public class HereRouteTruckRequest : HereRequest, IHereRouteRequest
{
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 HereRouteTruckRequest(IConfiguration config) : base(config, "RouteSvc")
{
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}" +
"&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.GetPointString(),
PointDestination.GetPointString(),
LimitePoids.ToString(CultureInfo.InvariantCulture),
Height.ToString(CultureInfo.InvariantCulture)
);
return uri.Uri;
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Text;
namespace HereTruckDistance.Core
{
public interface IHereRouteRequest
{
Localisation PointDepart { get; set; }
Localisation PointDestination { get; set; }
IList<string> Mode { get; set; }
bool Trafic { get; set; }
decimal LimitePoids { get; set; }
decimal Height { get; set; }
string ShippedHazardousGoods { get; set; }
}
}
using System.Globalization;
namespace HereTruckDistance.Core
{
public class Localisation
{
public decimal Latitude { get; set; }
public decimal Longitude { get; set; }
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));