Exemple #1
0
        public async Task <DirectionsResult> GetTransitAsync(DirectionsRequest request)
        {
            Coordinate       from, to;
            ResolvedLocation resolvedStart, resolvedEnd = null;

            if (request.UserId != null)
            {
                var locationBias = (await locationsService.ResolveAsync(request.UserId, new UnresolvedLocation(UnresolvedLocation.Home))) ?? Vienna;
                resolvedStart = await locationsService.ResolveAsync(request.UserId, request.StartAddress, locationBias);

                if (null != resolvedStart)
                {
                    resolvedEnd = await locationsService.ResolveAsync(request.UserId, request.EndAddress, resolvedStart);
                }
            }
            else
            {
                var locationBias = Vienna;
                resolvedStart = await locationsService.ResolveAnonymousAsync(request.StartAddress, locationBias);

                if (null != resolvedStart)
                {
                    resolvedEnd = await locationsService.ResolveAnonymousAsync(request.EndAddress, resolvedStart);
                }
            }
            if (null == resolvedStart)
            {
                throw new LocationNotFoundException(request.StartAddress);
            }
            if (null == resolvedEnd)
            {
                throw new LocationNotFoundException(request.EndAddress);
            }
            from = resolvedStart.Coordinate;
            to   = resolvedEnd.Coordinate;
            var plan = await transitDirectionProvider.GetDirectionsAsync(new TransitDirectionsRequest
            {
                ArriveBy = request.ArriveBy,
                DateTime = request.DateTime,
                From     = from,
                To       = to
            });

            if (null == plan)
            {
                return(null);
            }
            await directionsCache.PutAsync(plan.Id, plan);

            return(new DirectionsResult()
            {
                CacheKey = plan.Id,
                TransitDirections = plan.GetTransitDirections()
            });
        }
Exemple #2
0
        public async Task OTPCallback(string subscriptionId, OpenTripPlannerResponse route)
        {
            var sub = await _travelServiceContext.Subscriptions.FindAsync(subscriptionId);

            if (null == sub)
            {
                return;
            }
            route.Id = sub.RouteId;
            await _directionsCache.PutAsync(sub.RouteId, route.ToPlan());

            var cl = new HttpClient();
            await cl.PostAsync(sub.Callback, new StringContent(
                                   JsonConvert.SerializeObject(new DirectionsUpdate()
            {
                Id = sub.RouteId
            }), Encoding.UTF8, "application/json"));
        }