Esempio n. 1
0
        public async Task <IEnumerable <DispatchingResults> > CallRoutingAPI(DispatchingParameters dispatchingParameters, AssetProperties assetProperties)
        {
            var url      = $"{this.routingUrl}{GenerateURL(dispatchingParameters, assetProperties)}&key={this.bingMapsKey}";
            var response = await httpClient.GetAsync(url);

            if (!response.IsSuccessStatusCode)
            {
                throw new BadArgumentException($"Dispatching API returned: {response.StatusCode}");
            }

            var content = await response.Content.ReadAsStringAsync();

            var apiResult = JObject.Parse(content);

            var result = ExtractDispatchingResults(apiResult);

            if (dispatchingParameters.GetAlternativeCarRoute)
            {
                var alternativeUrl = $"{this.routingUrl}{GenerateURL(dispatchingParameters, assetProperties, true)}&key={this.bingMapsKey}";

                response = await httpClient.GetAsync(alternativeUrl);

                if (!response.IsSuccessStatusCode)
                {
                    throw new BadArgumentException($"Alternative dispatching API returned: {response.StatusCode}");
                }

                content = await response.Content.ReadAsStringAsync();

                apiResult = JObject.Parse(content);

                var alternativePath = ExtractAlternativeDispatchingResult(apiResult);

                foreach (var dispatchingResult in result)
                {
                    dispatchingResult.AlternativeCarRoutePoints = alternativePath;
                }
            }

            return(result);
        }
Esempio n. 2
0
        public string GenerateURL(DispatchingParameters dispatchingParameters, AssetProperties assetProperties, bool isCarRoute = false)
        {
            var strBuilder = new StringBuilder("routeAttributes=routePath");

            if (dispatchingParameters.WayPoints != null)
            {
                strBuilder.Append(GenerateWayPointsUri(dispatchingParameters.WayPoints));
            }
            else
            {
                throw new BadArgumentException("WayPoints must be defined");
            }

            if (dispatchingParameters.MaxSolutions != null)
            {
                strBuilder.Append(GenerateMaxSolutionsUri(dispatchingParameters.MaxSolutions));
            }

            if (dispatchingParameters.DistanceUnit != null)
            {
                strBuilder.Append(GenerateDistanceUnitUri(dispatchingParameters.DistanceUnit));
            }

            if (dispatchingParameters.WeightUnit != null)
            {
                strBuilder.Append(GenerateWeightUnitUri(dispatchingParameters.WeightUnit));
            }

            if (dispatchingParameters.DimensionUnit != null)
            {
                strBuilder.Append(GenerateDimensionUnitUri(dispatchingParameters.DimensionUnit));
            }

            if (isCarRoute)
            {
                return(strBuilder.ToString());
            }

            if (dispatchingParameters.Optimize != null)
            {
                strBuilder.Append(GenerateOptimizeUri(dispatchingParameters.Optimize));
            }

            if (dispatchingParameters.Avoid != null && dispatchingParameters.Avoid.Count() > 0)
            {
                strBuilder.Append(GenerateAvoidUri(dispatchingParameters.Avoid));
            }

            if (dispatchingParameters.DistanceBeforeFirstTurn != null)
            {
                strBuilder.Append($"&distanceBeforeFirstTurn={dispatchingParameters.DistanceBeforeFirstTurn}");
            }

            if (dispatchingParameters.Heading != null)
            {
                strBuilder.Append(GenerateHeadingUri(dispatchingParameters.Heading));
            }

            if (dispatchingParameters.Tolerances != null)
            {
                strBuilder.Append(GenerateTolerancesUri(dispatchingParameters.Tolerances));
            }

            if (dispatchingParameters.AvoidCrossWind == true)
            {
                strBuilder.Append("&vehicleAvoidCrossWind=true");
            }

            if (dispatchingParameters.DateTime != null)
            {
                strBuilder.Append("&dateTime=" + dispatchingParameters.DateTime.ToString());

                if (dispatchingParameters.TimeType != null)
                {
                    strBuilder.Append(GenerateTimeTypeUri(dispatchingParameters.TimeType));
                }
            }

            strBuilder.Append(GenerateAssetHeightUri(dispatchingParameters.LoadedHeight, assetProperties));
            strBuilder.Append(GenerateAssetLengthUri(dispatchingParameters.LoadedLength, assetProperties));
            strBuilder.Append(GenerateAssetWidthUri(dispatchingParameters.LoadedWidth, assetProperties));
            strBuilder.Append(GenerateAssetWeightUri(dispatchingParameters.LoadedWeight, assetProperties));


            if (dispatchingParameters.AvoidGroundingRisk == true)
            {
                strBuilder.Append("&vehicleAvoidGroundingRisk=true");
            }

            if (dispatchingParameters.HazardousMaterials != null && dispatchingParameters.HazardousMaterials.Count() > 0)
            {
                strBuilder.Append(GenerateHazardousMaterialsUri(dispatchingParameters.HazardousMaterials));
            }

            if (dispatchingParameters.HazardousPermits != null && dispatchingParameters.HazardousPermits.Count() > 0)
            {
                strBuilder.Append(GenerateHazardousPermitsUri(dispatchingParameters.HazardousPermits));
            }

            if (assetProperties == null)
            {
                return(strBuilder.ToString());
            }

            if (assetProperties.AssetAxels != null)
            {
                strBuilder.Append($"&vehicleAxles={assetProperties.AssetAxels}");
            }

            if (assetProperties.AssetTrailers != null)
            {
                strBuilder.Append($"&vehicleTrailers={assetProperties.AssetTrailers}");
            }

            if (assetProperties.AssetSemi == true)
            {
                strBuilder.Append("&vehicleSemi=true");
            }

            if (assetProperties.AssetMaxGradient != null)
            {
                strBuilder.Append($"&vehicleMaxGradient={assetProperties.AssetMaxGradient}");
            }

            if (assetProperties.AssetMinTurnRadius != null)
            {
                strBuilder.Append($"&vehicleMinTurnRadius={assetProperties.AssetMinTurnRadius}");
            }

            return(strBuilder.ToString());
        }