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); }
public override void Update() { if (DateTime.UtcNow < lastCheckStatus + checkStatusInterval) { return; } List <string> checkTrips = new List <string>(activeTrips.Keys); foreach (string tripID in checkTrips) { try { string bookingPK = activeTrips[tripID].pk; TDispatchAPI.GetBookingStatusResponse getBookingStatusResponse = api.GetBookingStatus(bookingPK); TDispatchAPI.GetBookingResponse getBookingResponse = api.GetBooking(bookingPK); getBookingResponse.booking.sub_status = getBookingStatusResponse.booking.sub_status; UpdateBooking(tripID, getBookingResponse.booking); } catch (Exception e) { Logger.LogDebug("TDispatch update exception for trip: " + tripID, e.ToString()); } } lastCheckStatus = DateTime.UtcNow; }
public void UpdateBooking(string tripID, TDispatchAPI.Booking value) { Status activeTrip = ConvertTDispatchStatusToTripThruStatus(activeTrips[tripID].status, activeTrips[tripID].sub_status); Status valueTrip = ConvertTDispatchStatusToTripThruStatus(value.status, value.sub_status); if (activeTrip == valueTrip) { return; } Logger.BeginRequest("TDispatch trip " + tripID + " update", null, tripID); string bookingPK = activeTrips[tripID].pk; if (value.pk == null) { value.pk = bookingPK; } activeTrips[tripID] = value; Logger.Log("BookingStatus changed ", value); Logger.Log("Notify originating partner through TripThru"); Logger.Tab(); Location newLocation = null; TDispatchAPI.GetBookingStatusResponse getBookingStatusResponse = api.GetBookingStatus(bookingPK); if (getBookingStatusResponse.booking.driver != null) { if (getBookingStatusResponse.booking.driver.location != null) { if (getBookingStatusResponse.booking.driver.location.lat != null) { if (getBookingStatusResponse.booking.driver.location.lng != null) { newLocation = new Location((double)getBookingStatusResponse.booking.driver.location.lat, (double)getBookingStatusResponse.booking.driver.location.lng); } } } } Gateway.UpdateTripStatusRequest request = new Gateway.UpdateTripStatusRequest( clientID: ID, tripID: tripID, status: ConvertTDispatchStatusToTripThruStatus(value.status, value.sub_status), driverLocation: newLocation); tripthru.UpdateTripStatus(request); Logger.Untab(); if (activeTrips[tripID].status == "completed" || activeTrips[tripID].status == "cancelled" || activeTrips[tripID].status == "rejected" || activeTrips[tripID].status == "missed") { activeTrips.Remove(tripID); } Logger.EndRequest(null); }
public override void Update() { if (DateTime.UtcNow < lastCheckStatus + checkStatusInterval) { return; } List <string> checkTrips = new List <string>(activeTrips.Keys); foreach (string tripID in checkTrips) { string bookingPK = activeTrips[tripID].pk; TDispatchAPI.GetBookingStatusResponse getBookingStatusResponse = api.GetBookingStatus(bookingPK); TDispatchAPI.GetBookingResponse getBookingResponse = api.GetBooking(bookingPK); UpdateBooking(tripID, getBookingResponse.booking); } lastCheckStatus = DateTime.UtcNow; }