コード例 #1
0
        public async Task <IActionResult> GetAsync()
        {
            HttpClient client = new HttpClient();

            //Add an Accept header for JSON format.
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            IActionResult retour = null;

            //TODO: Devrait être reçu en paramètre!
            RouteDistanceModel parametres = new RouteDistanceModel();

            //Obtenir le point Géolocalisé pour l'origine et la destination
            var geoOptions = new GeocoderOptions();

            geoOptions.AddAdresse(parametres.Depart);
            var origine = await _geoSrv.ObtenirLocalisationAsync(geoOptions).ConfigureAwait(false);

            geoOptions = new GeocoderOptions();
            geoOptions.AddAdresse(parametres.Destination);
            var destination = await _geoSrv.ObtenirLocalisationAsync(geoOptions).ConfigureAwait(false);

            //Construire les options de recherche
            var options = new RouteTruckOptions();

            options.AddLocalisation(origine, 0);
            options.AddLocalisation(destination, 1);
            options.AddMode(new Mode[] { Mode.fastest, Mode.truck, Mode.trafficDisabled });
            options.AddLimitedWeight(parametres.Poids);
            options.AddLength(parametres.Longueur);
            options.AddWidth(parametres.Largeur);

            //Obtenir la distance "Camion" entre 2 points géolocalisés
            try
            {
                var retourSrv = await _routeSrv.ObtenirDistanceAsync(options).ConfigureAwait(false);

                if (retourSrv == null)
                {
                    retour = BadRequest("Une erreur est survenue lors de l'appel du service");
                }
                else
                {
                    retour = Ok(retourSrv);
                }
            }
            catch (Exception)
            {
                retour = BadRequest("Une erreur est survenue lors de l'appel du service");
            }

            client.Dispose();
            return(retour);
        }
コード例 #2
0
        /// <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 RouteTruckOptions tpParams, ShippedHazardousGoods valeur)
        {
            if (tpParams == null)
            {
                throw new ArgumentNullException(nameof(tpParams));
            }
            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);
            }
        }
コード例 #3
0
        /// <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>
        /// <param name="tpParams"></param>
        /// <param name="valeur">Enum [ strict | soft ]</param>
        public static void AddTruckRestrictionPenalty(this RouteTruckOptions tpParams, TruckRestrictionPenalty valeur)
        {
            if (tpParams == null)
            {
                throw new ArgumentNullException(nameof(tpParams));
            }
            string nom   = "truckRestrictionPenalty";
            var    param = new ParamsEnum <TruckRestrictionPenalty>(nom, valeur);

            if (!tpParams.Parametres.TryAdd(nom, param))
            {
                tpParams.Parametres.Remove(nom);
                tpParams.Parametres.Add(nom, param);
            }
        }
コード例 #4
0
        /// <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 RouteTruckOptions tpParams, int valeur)
        {
            if (tpParams == null)
            {
                throw new ArgumentNullException(nameof(tpParams));
            }
            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);
            }
        }