Example #1
0
        public override Gateway.GetTripStatusResponse GetTripStatus(Gateway.GetTripStatusRequest request)
        {
            Logger.BeginRequest("GetTripStatus received from " + tripthru.name, request, request.tripID);
            Gateway.GetTripStatusResponse response = null;
            if (activeTrips.ContainsKey(request.tripID))
            {
                string bookingPK = activeTrips[request.tripID].pk;

                TDispatchAPI.GetBookingStatusResponse getBookingStatusResponse = api.GetBookingStatus(bookingPK);

                TDispatchAPI.GetBookingResponse getBookingResponse = api.GetBooking(bookingPK);

                TDispatchAPI.Booking booking = getBookingStatusResponse.booking;
                booking.Merge(getBookingResponse.booking);

                TDispatchAPI.GetFareResponse fare = api.GetFare(new TDispatchAPI.GetFareRequest
                {
                    way_points  = booking.way_points,
                    pickup_time =
                        booking.pickup_time != null
                            ? ((DateTime)booking.pickup_time).ToString("yyyy-MM-dd'T'HH:mm:ssK",
                                                                       DateTimeFormatInfo.InvariantInfo)
                            : null,
                    pickup_location  = booking.pickup_Location.location,
                    dropoff_location = booking.dropoff_Location.location,
                    dropoff_time     =
                        booking.dropoff_time != null
                            ? ((DateTime)booking.dropoff_time).ToString("yyyy-MM-dd'T'HH:mm:ssK",
                                                                        DateTimeFormatInfo.InvariantInfo)
                            : null,
                    payment_method = booking.payment_method
                });

                response = new Gateway.GetTripStatusResponse(
                    partnerID: ID, partnerName: name, passengerName: booking.customerName,
                    pickupLocation: new Location((double)booking.pickup_Location.location.lat, (double)booking.pickup_Location.location.lng),
                    dropoffLocation: new Location((double)booking.dropoff_Location.location.lat, (double)booking.dropoff_Location.location.lng),
                    fleetID: booking.office.slug, fleetName: booking.office.name,
                    driverID: booking.driver != null ? booking.driver.pk : null,
                    driverName: booking.driver != null ? booking.driver.name : null,
                    driverLocation: booking.driver != null
                        ? new Location((double)booking.driver.location.lat,
                                       (double)booking.driver.location.lng)
                        : null, price: booking.cost.value, distance: fare.fare.distance.km,
                    result: Result.OK, status: this.ConvertTDispatchStatusToTripThruStatus(booking.status, booking.sub_status)
                    );
                if (booking.pk == null)
                {
                    booking.pk = bookingPK;
                }
                //activeTrips[request.tripID] = booking;
            }
            else
            {
                Logger.Log("Trip " + request.tripID + " not found");
                response = new GetTripStatusResponse(result: Result.NotFound);
            }
            Logger.EndRequest(response);
            return(response);
        }
Example #2
0
        public override Gateway.QuoteTripResponse QuoteTrip(Gateway.QuoteTripRequest request)
        {
            Logger.BeginRequest("QuoteTrip received from " + tripthru.name, request);
            Gateway.QuoteTripResponse response = null;
            {
                // TDispatch requires that we supply the string address and postal code in addition to the Lng/Lat coordinates
                Pair <string, string> pickup_address  = MapTools.GetReverseGeoLocAddress(request.pickupLocation);
                Pair <string, string> dropoff_address = MapTools.GetReverseGeoLocAddress(request.dropoffLocation);

                TDispatchAPI.GetFareRequest createRequest = new TDispatchAPI.GetFareRequest
                {
                    payment_method  = "cash",
                    pickup_location = new TDispatchAPI.Location {
                        lat = request.pickupLocation.Lat, lng = request.pickupLocation.Lng
                    },
                    pickup_time      = request.pickupTime.ToString("yyyy-MM-dd'T'HH:mm:ssK", DateTimeFormatInfo.InvariantInfo),
                    dropoff_location = new TDispatchAPI.Location {
                        lat = request.dropoffLocation.Lat, lng = request.dropoffLocation.Lng
                    }
                };
                // TODO: replace with POST /locations/fare
                TDispatchAPI.GetFareResponse createResponse = api.GetFare(createRequest);
                List <Quote> quotes = new List <Quote>();
                var          price  = 0.0;
                try
                {
                    price = double.Parse(createResponse.fare.formatted_total_cost.Replace("$", ""));
                }
                catch (Exception e) { }
                quotes.Add(new Quote(partnerID: ID, partnerName: name, fleetID: ID, fleetName: name, price: price, ETA: DateTime.UtcNow + new TimeSpan(1, 0, createResponse.fare.time_to_wait)));
                response = new Gateway.QuoteTripResponse(quotes, Result.OK);
            }
            Logger.EndRequest(response);
            return(response);
        }