Beispiel #1
0
 private DispatchTripResponse HandleRejectDispatchResponse(DispatchTripResponse response1)
 {
     Logger.Log("No partners are available that cover that area");
     Logger.Untab();
     rejects++;
     response1 = new DispatchTripResponse(result: Result.Rejected); return(response1);
 }
Beispiel #2
0
 private DispatchTripResponse HandleQuoteBroadcastFailedResponse(DispatchTripResponse response1, QuoteTripResponse response)
 {
     Logger.Log("QuoteTrip call failed");
     Logger.Untab();
     rejects++;
     response1 = new DispatchTripResponse(result: response.result); return(response1);
 }
Beispiel #3
0
        protected DispatchTripResponse MakeRejectDispatchResponse()
        {
            DispatchTripResponse response;

            rejects++;
            response = new DispatchTripResponse(result: Result.Rejected);
            return(response);
        }
Beispiel #4
0
        public override DispatchTripResponse DispatchTrip(DispatchTripRequest r)
        {
            requests++;
            DispatchTripResponse response;

            if (TripIsNotAlreadyActive(r))
            {
                // Note: GetTrip populates the foreignTripID
                Gateway partner = null;
                if (PartnerHasNotBeenSpecified(r))
                {
                    response = AutoDispatchTrip(r, ref partner);
                }
                else
                {
                    partner = SelectedPartner(r);
                }

                if (PartnerHasBeenSelected(partner))
                {
                    RecordTripOriginatingAndServicingPartner(r, partner);
                    if (TripIsLocal(r))
                    {
                        response = new DispatchTripResponse(result: Result.OK);
                    }
                    else
                    {
                        var partnerClientId = r.clientID;
                        ChangeTheClientIDToTripThru(r);
                        response   = partner.DispatchTrip(r);
                        r.clientID = partnerClientId;
                    }
                    if (response.result != Result.OK)
                    {
                        Logger.Log("DispatchTrip to " + partner.name + " failed");
                    }
                    else
                    {
                        MakeTripAndAddItToActive(r, partner);
                    }
                }
                else
                {
                    response = MakeRejectDispatchResponse(r, partners[r.clientID], partner);
                    Logger.Log("DispatchTrip failed: No partner found.");
                }
            }
            else
            {
                response = MakeRejectDispatchResponse(r, partners[r.clientID], null);
                Logger.Log("DispatchTrip failed: Trip already active");
            }
            return(response);
        }
Beispiel #5
0
        private DispatchTripResponse AutoDispatchTrip(DispatchTripRequest r, ref Gateway partner)
        {
            DispatchTripResponse response = new DispatchTripResponse(result: Result.UnknownError);

            Logger.Log("Auto mode, so quote trip through all partners");
            Logger.Tab();
            // Dispatch to partner with shortest ETA
            QuoteTripResponse quoteTripResponse = BroadcastQuoteRequestsToAllPartners(r);

            if (BroadcastQuoteWasRejected(quoteTripResponse))
            {
                response = HandleRejectDispatchResponse(response);
            }
            else if (quoteTripResponse.result != Result.OK)
            {
                response = HandleQuoteBroadcastFailedResponse(response, quoteTripResponse);
            }
            else
            {
                partner = SelectThePartnerWithBestQuote(r, partner, quoteTripResponse);
            }
            Logger.Untab();
            return(response);
        }
 public override DispatchTripResponse DispatchTrip(DispatchTripRequest r)
 {
     requests++;
     if (r.fleetID != null)
     {
         PartnerFleet f = PartnerFleets[r.fleetID];
         if (f.FleetServesLocation(r.pickupLocation))
         {
             PartnerTrip trip = GetTrip(r);
             if (f.QueueTrip(trip))
             {
                 DispatchTripResponse response = new DispatchTripResponse();
                 Logger.Log("DispatchTrip successful on " + name + ", Response: " + response);
                 return response;
             }
         }
         return new DispatchTripResponse(result: Result.Rejected);
     }
     // Note: GetTrip populates the foreignTripID
     foreach (PartnerFleet f in PartnerFleets.Values)
     {
         if (!f.FleetServesLocation(r.pickupLocation))
             continue;
         PartnerTrip trip = GetTrip(r);
         if (f.QueueTrip(trip))
         {
             DispatchTripResponse response = new DispatchTripResponse();
             Logger.Log("DispatchTrip successful on " + name + ", Response: " + response);
             return response;
         }
     }
     {
         DispatchTripResponse response = new DispatchTripResponse(result: Result.Rejected);
         Logger.Log("DispatchTrip rejected on " + name + ", no available drivers -- Response: " + response);
         return response;
     }
 }
Beispiel #7
0
 protected DispatchTripResponse MakeRejectDispatchResponse()
 {
     DispatchTripResponse response;
     rejects++;
     response = new DispatchTripResponse(result: Result.Rejected);
     return response;
 }
Beispiel #8
0
        protected DispatchTripResponse MakeRejectDispatchResponse(DispatchTripRequest r, Gateway client, Gateway partner)
        {
            DispatchTripResponse response;
            rejects++;
            response = new DispatchTripResponse(result: Result.Rejected);

            var trip = new Trip
            {
                Id = r.tripID,
                OriginatingPartnerName = client.name,
                OriginatingPartnerId = client.ID,
                ServicingPartnerName = partner == null ? null : partner.name,
                ServicingPartnerId = partner == null ? null : partner.ID,
                Status = Status.Rejected,
                PickupLocation = r.pickupLocation,
                PickupTime = r.pickupTime,
                DropoffLocation = r.dropoffLocation,
                PassengerName = r.passengerName,
                VehicleType = r.vehicleType,
                Creation = DateTime.UtcNow,
                LatenessMilliseconds = 0,
                SamplingPercentage = 1
            };
            activeTrips.SaveTrip(trip); // Hack: save trip should be moved somewhere else.

            return response;
        }
 private DispatchTripResponse HandleRejectDispatchResponse(DispatchTripResponse response1)
 {
     Logger.Log("No partners are available that cover that area");
     Logger.Untab();
     rejects++;
     response1 = new DispatchTripResponse(result: Result.Rejected); return response1;
 }
 private DispatchTripResponse HandleQuoteBroadcastFailedResponse(DispatchTripResponse response1, QuoteTripResponse response)
 {
     Logger.Log("QuoteTrip call failed");
     Logger.Untab();
     rejects++;
     response1 = new DispatchTripResponse(result: response.result); return response1;
 }
 private DispatchTripResponse AutoDispatchTrip(DispatchTripRequest r, ref Gateway partner)
 {
     DispatchTripResponse response = new DispatchTripResponse(result: Result.UnknownError);
     Logger.Log("Auto mode, so quote trip through all partners");
     Logger.Tab();
     // Dispatch to partner with shortest ETA
     QuoteTripResponse quoteTripResponse = BroadcastQuoteRequestsToAllPartners(r);
     if (BroadcastQuoteWasRejected(quoteTripResponse))
         response = HandleRejectDispatchResponse(response);
     else if (quoteTripResponse.result != Result.OK)
         response = HandleQuoteBroadcastFailedResponse(response, quoteTripResponse);
     else
         partner = SelectThePartnerWithBestQuote(r, partner, quoteTripResponse);
     Logger.Untab();
     return response;
 }
Beispiel #12
0
 private DispatchTripResponse DispatchToSpecificFleet(DispatchTripRequest r)
 {
     Logger.Log("Dispatching to fleet " + r.fleetID);
     PartnerFleet f = PartnerFleets[r.fleetID];
     if (f.FleetServesLocation(r.pickupLocation))
     {
         PartnerTrip trip = GetTrip(r);
         if (f.QueueTrip(trip))
         {
             DispatchTripResponse response = new DispatchTripResponse();
             Logger.Log("DispatchTrip successful on " + name + ", Response: " + response);
             Logger.SetServicingId(this.ID);
             return response;
         }
     }
     return new DispatchTripResponse(result: Result.Rejected);
 }
Beispiel #13
0
 private DispatchTripResponse DispatchToFirstFleetThatServes(DispatchTripRequest r)
 {
     Logger.Log("Dispatching to first fleet that serves");
     DispatchTripResponse response = new DispatchTripResponse(result: Result.Rejected);
     foreach (PartnerFleet f in PartnerFleets.Values)
     {
         if (!f.FleetServesLocation(r.pickupLocation))
             continue;
         PartnerTrip trip = GetTrip(r);
         if (f.QueueTrip(trip))
         {
             DispatchTripResponse resp = new DispatchTripResponse();
             Logger.Log("DispatchTrip successful on " + name + ", Response: " + resp);
             return resp;
         }
     }
     return response;
 }
Beispiel #14
0
 public override DispatchTripResponse DispatchTrip(DispatchTripRequest r)
 {
     DispatchTripResponse response;
     {
         requests++;
         if (r.partnerID != null && r.partnerID != ID)
         {
             Logger.Log("Dispatching trip to partner " + r.partnerID);
             PartnerTrip trip = GetTrip(r, autoDispatch: false);
             trip.origination = PartnerTrip.Origination.Local;
             PartnerFleets.FirstOrDefault().Value.QueueTrip(trip);
             if (TryToDispatchToForeignProvider(trip, r.partnerID))
                 response = new DispatchTripResponse(result: Result.OK);
             else
                 response = new DispatchTripResponse(result: Result.Rejected);
         }
         else if (r.driverID != null)
             response = DispatchToSpecificDriver(r);
         else if (r.fleetID != null)
             response = DispatchToSpecificFleet(r);
         else
             response = DispatchToFirstFleetThatServes(r);
     }
     return response;
 }
Beispiel #15
0
        public override DispatchTripResponse DispatchTrip(DispatchTripRequest r)
        {
            requests++;
            DispatchTripResponse response;
            if (TripIsNotAlreadyActive(r))
            {
                // Note: GetTrip populates the foreignTripID
                Gateway partner = null;
                if (PartnerHasNotBeenSpecified(r))
                    response = AutoDispatchTrip(r, ref partner);
                else
                    partner = SelectedPartner(r);

                if (PartnerHasBeenSelected(partner))
                {
                    RecordTripOriginatingAndServicingPartner(r, partner);
                    if (TripIsLocal(r))
                        response = new DispatchTripResponse(result: Result.OK);
                    else
                    {
                        var partnerClientId = r.clientID;
                        ChangeTheClientIDToTripThru(r);
                        response = partner.DispatchTrip(r);
                        r.clientID = partnerClientId;
                    }
                    if (response.result != Result.OK)
                        Logger.Log("DispatchTrip to " + partner.name + " failed");
                    else
                        MakeTripAndAddItToActive(r, partner);
                }
                else
                {
                    response = MakeRejectDispatchResponse(r, partners[r.clientID], partner);
                    Logger.Log("DispatchTrip failed: No partner found.");
                }
            }
            else
            {
                response = MakeRejectDispatchResponse(r, partners[r.clientID], null);
                Logger.Log("DispatchTrip failed: Trip already active");
            }
            return response;
        }