private void MakeTripPickedUp(PartnerTrip trip)
 {
     Logger.Log("Picking up: " + trip);
     Logger.Tab();
     DateTime eta = UpdateDriverRouteAndGetETA(trip.driver, trip.dropoffLocation);
     trip.UpdateTripStatus(notifyPartner: true, status: Status.PickedUp, driverLocation: trip.driver.location, eta: eta);
     Logger.Untab();
 }
 private void MakeTripComplete(PartnerTrip t)
 {
     Logger.Log("The destination has been reached for: " + t);
     Logger.Tab();
     t.dropoffTime = DateTime.UtcNow;
     CompleteTrip(t);
     t.UpdateTripStatus(notifyPartner: true, status: Status.Complete);
     Logger.Untab();
 }
 private void MakeTripEnroute(PartnerTrip trip)
 {
     Logger.Log("Driver is now enroute: " + trip);
     Logger.Tab();
     DateTime eta = UpdateDriverRouteAndGetETA(trip.driver, trip.pickupLocation);
     trip.UpdateTripStatus(notifyPartner: true, status: Status.Enroute, driverLocation: trip.driver.location, eta: eta);
     Logger.Untab();
 }
 private static void CancelTrip(PartnerTrip t)
 {
     Logger.Log("Missed period reached: -- so cancel " + t);
     Logger.Tab();
     t.UpdateTripStatus(notifyPartner: true, status: Status.Cancelled);
     Logger.Untab();
 }
 public bool TryDispatchTripLocally(PartnerTrip t)
 {
     Logger.Log("DispatchTripLocally");
     if (!FleetServesLocation(t.pickupLocation))
     {
         Logger.Log("Pickup location " + t.pickupLocation + " is outside of coverage area");
         return false;
     }
     if (t.status != Status.Queued)
         throw new Exception("Invalid 'Dispatch' status");
     if (ThereAreAvailableDrivers())
     {
         DispatchToFirstAvailableDriver(t);
         t.UpdateTripStatus(notifyPartner: true, status: Status.Dispatched, driverLocation: t.driver.location, eta: t.pickupTime);
         return true;
     }
     Logger.Log("No drivers are currently available");
     return false;
 }
 public bool QueueTrip(PartnerTrip t)
 {
     lock (locker)
     {
         if (availableDrivers.Count == 0 && t.origination == PartnerTrip.Origination.Foreign)
             return false; // don't except from parters if no available drivers
         Logger.Log("Queueing " + t);
         queue.AddLast(t);
         partner.tripsByID.Add(t.ID, t);
         partner.activeTrips.Add(t.ID, new Trip
         {
             FleetId = t.PartnerFleet != null ? t.PartnerFleet.ID : null,
             FleetName = t.PartnerFleet != null ? t.PartnerFleet.name : null,
             DriverId = t.driver != null ? t.driver.ID : null,
             DriverLocation = t.driver != null ? t.driver.location : null,
             DriverName = t.driver != null ? t.driver.name : null,
             DropoffLocation = t.dropoffLocation,
             DriverInitiaLocation = null,
             DropoffTime = t.dropoffTime,
             Id = t.ID,
             OriginatingPartnerId = this.ID,
             OriginatingPartnerName = this.name,
             PassengerName = t.passengerName,
             PickupLocation = t.pickupLocation,
             PickupTime = t.pickupTime,
             Price = t.price,
             Status = t.status,
             VehicleType = t.vehicleType,
         });
         t.UpdateTripStatus(notifyPartner: false, status: Status.Queued);
         return true;
     }
 }
 // speed is miles per hour
 public void GetTripStatusFromForeignServiceProvider(PartnerTrip trip, bool force = false)
 {
     if (force || DateTime.UtcNow > trip.lastUpdate + updateInterval && trip.status != Status.Complete)
     {
         Logger.Log("Getting (Foreign) status of " + trip);
         Logger.Tab();
         Gateway.GetTripStatusRequest request = new Gateway.GetTripStatusRequest(clientID: ID, tripID: trip.ID);
         Gateway.GetTripStatusResponse response = tripthru.GetTripStatus(request);
         if (response.status != null)
             trip.UpdateTripStatus(notifyPartner: false, status: (Status)response.status, driverLocation: response.driverLocation, eta: response.ETA); // todo: not good -- fix this.
         if (response.driverName != null)
             trip.driver = new Driver(name: response.driverName, location: response.driverLocation);
         if (response.dropoffTime != null)
             trip.dropoffTime = response.dropoffTime;
         if (response.vehicleType != null)
             trip.vehicleType = response.vehicleType;
         if (response.distance != null)
             trip.distance = response.distance;
         Logger.Untab();
         trip.lastUpdate = DateTime.UtcNow;
     }
 }
Esempio n. 8
0
 public bool QueueTrip(PartnerTrip t)
 {
     lock (locker)
     {
         if (availableDrivers.Count == 0 && t.origination == PartnerTrip.Origination.Foreign)
             return false; // don't except from parters if no available drivers
         Logger.Log("Queueing " + t);
         queue.AddLast(t);
         if (partner.activeTrips.ContainsKey(t.ID))
             throw new Exception("Trip " + t + ": already exist in activeTrips dictionary -- Existing trip = " + partner.activeTrips[t.ID]);
         if (partner.tripsByID.ContainsKey(t.ID))
             throw new Exception("Trip " + t + ": already exist in tripsByID dictionary");
         partner.tripsByID.Add(t.ID, t);
         partner.activeTrips.Add(t.ID, new Trip
         {
             FleetId = t.PartnerFleet != null ? t.PartnerFleet.ID : null,
             FleetName = t.PartnerFleet != null ? t.PartnerFleet.name : null,
             DriverId = t.driver != null ? t.driver.ID : null,
             DriverLocation = t.driver != null ? t.driver.location : null,
             DriverName = t.driver != null ? t.driver.name : null,
             DropoffLocation = t.dropoffLocation,
             DriverInitiaLocation = t.driverInitiaLocation ?? null,
             DropoffTime = t.dropoffTime,
             Id = t.ID,
             OriginatingPartnerId = this.ID,
             OriginatingPartnerName = this.name,
             PassengerName = t.passengerName,
             PickupLocation = t.pickupLocation,
             PickupTime = t.pickupTime,
             Price = t.price,
             Status = t.status,
             VehicleType = t.vehicleType,
             SamplingPercentage = 1
         });
         t.UpdateTripStatus(notifyPartner: false, status: Status.Queued);
         return true;
     }
 }