private string FormatStart(UnresolvedLocation startAddress)
 {
     if (null != startAddress.Coordinate)
     {
         return($"{startAddress.Coordinate.Lat.ToString(CultureInfo.InvariantCulture)},{startAddress.Coordinate.Lng.ToString(CultureInfo.InvariantCulture)}");
     }
     else
     {
         return(startAddress.Address);
     }
 }
Exemple #2
0
 public async Task <ResolvedLocation> ResolveAnonymousAsync(UnresolvedLocation toResolve, ResolvedLocation userLocation = null)
 {
     if (null != toResolve.Coordinate)
     {
         return(new ResolvedLocation(toResolve.Coordinate));
     }
     if (null == toResolve.Address)
     {
         return(null);
     }
     return((await locationsProvider.Find(toResolve.Address, userLocation))?.FirstOrDefault());
 }
Exemple #3
0
        public async Task <ResolvedLocation> ResolveAsync(string userId, UnresolvedLocation toResolve, ResolvedLocation userLocation = null)
        {
            if (null != toResolve.Coordinate)
            {
                return(new ResolvedLocation(toResolve.Coordinate));
            }
            if (null == toResolve.Address)
            {
                return(null);
            }
            var resolved = await resolvedLocationsStore.GetAsync(toResolve.Address, userId);

            if (null != resolved)
            {
                return(resolved);
            }
            if ("#home" == toResolve.Address || toResolve.Address.StartsWith("#event:"))
            {
                return(null);
            }
            return((await locationsProvider.Find(toResolve.Address, userLocation))?.FirstOrDefault());
        }
Exemple #4
0
 public LocationNotFoundException(UnresolvedLocation unresolvedLocation) :
     base($"Cannot resolve {unresolvedLocation.Address}/{unresolvedLocation.Coordinate}")
 {
     UnresolvedLocation = unresolvedLocation;
 }
Exemple #5
0
        private async Task <IActionResult> GetDirections(string userId, DirectionsQueryParameters directionsQueryParameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            if (directionsQueryParameters.ArrivalTime.HasValue == directionsQueryParameters.DepartureTime.HasValue)
            {
                return(BadRequest("Either departureTime xor arrialTime must be specified."));
            }
            UnresolvedLocation start;

            if (null != directionsQueryParameters.StartAddress)
            {
                start = new UnresolvedLocation(directionsQueryParameters.StartAddress);
            }
            else if (directionsQueryParameters.StartLat.HasValue && directionsQueryParameters.StartLng.HasValue)
            {
                start = new UnresolvedLocation(new Coordinate()
                {
                    Lat = directionsQueryParameters.StartLat.Value,
                    Lng = directionsQueryParameters.StartLng.Value
                });
            }
            else
            {
                return(BadRequest());
            }
            var endAdress = new UnresolvedLocation(directionsQueryParameters.EndAddress);

            try
            {
                var res = await directionsService.GetTransitAsync(new DirectionsRequest()
                {
                    UserId       = userId,
                    StartAddress = start,
                    EndAddress   = endAdress,
                    DateTime     = directionsQueryParameters.DepartureTime.HasValue ?
                                   directionsQueryParameters.DepartureTime.Value :
                                   directionsQueryParameters.ArrivalTime.Value,
                    ArriveBy = directionsQueryParameters.ArrivalTime.HasValue
                });

                if (null == res)
                {
                    return(NotFound(new DirectionsNotFoundResult()
                    {
                        Reason = DirectionsNotFoundReason.RouteNotFound,
                        EndAddressFound = true,
                        StartAddressFound = true
                    }));
                }
                Response.Headers.Add("ETag", $"\"{res.CacheKey}\"");

                return(Ok(res.TransitDirections));
            }
            catch (LocationNotFoundException e)
            {
                return(NotFound(new DirectionsNotFoundResult()
                {
                    Reason = DirectionsNotFoundReason.AddressNotFound,
                    EndAddressFound = e.UnresolvedLocation == endAdress,
                    StartAddressFound = e.UnresolvedLocation != endAdress
                }));
            }
        }