Beispiel #1
0
        public override void PendingRideMade(PendingRide pendingRide)
        {
            if (state != RideOfferState.Unmatched)
            {
                throw new Exception("Added to pending ride in a status other than Unmatched");
            }

            state = RideOfferState.Unconfirmed;

            PostStatus(pendingRide.Id).FireAndForgetAsync(Program.ErrorHandler);

            InvokeApartOfPendingRide(pendingRide);
            InvokeStateUpdated();
        }
Beispiel #2
0
        public override void PendingRideMade(PendingRide pendingRide)
        {
            if (state != RideRequestState.Unmatched)
            {
                throw new Exception("Added to pending ride in a status other than Unmatched");
            }

            state         = RideRequestState.WaitingForDriverConfirmation;
            pendingRideId = pendingRide.Id;

            //No update to data store until driver has confirmed

            InvokeApartOfPendingRide(pendingRide);
            InvokeStateUpdated();
        }
        async static Task MakeRide(UserRideOffer offer, CancellationToken cancellationToken)
        {
            bool matched = false;

            do
            {
                // This is the preferred way of cancelling a task. Note that
                // a cancellation token can be made with a timeout.
                cancellationToken.ThrowIfCancellationRequested();

                var potentialRide = await rideMatcher.GetRide(offer, rideRequestOrigins, rideRequestDestination);

                cancellationToken.ThrowIfCancellationRequested();

                // NOTE: C# disallows using await inside a lock. This means that
                // the thread that is running MakeRide() will not enter OnRideRequestCanceled()
                // while it holds this lock (because it won't yield execution).
                // As long as no method call here invokes the Canceled event,
                // this guarantees that the locking will work as expected.
                lock (rideBuildLock)
                {
                    IList <MatchableRideRequest> requests = potentialRide.Item1;

                    // Some requests could have gotten canceled during the matching process.
                    matched = requests.All(req => pendingRequests.ContainsKey(req.Request.Id));

                    if (matched)
                    {
                        // This must happen while we still hold the ride build lock
                        // because because requests could become canceled.
                        foreach (var request in requests)
                        {
                            RemoveRideRequest(request.Request);
                        }

                        var pendingRide = new PendingRide(potentialRide.Item2,
                                                          offer,
                                                          requests.Select((Mrr) => Mrr.Request).ToList(),
                                                          rideMatcher);

                        pendingRide.InitializeAndPost().FireAndForgetAsync(Program.ErrorHandler);
                    }
                }
            } while (!matched);
        }
Beispiel #4
0
 public abstract void PendingRideMade(PendingRide pendingRide);
Beispiel #5
0
 protected void InvokeApartOfPendingRide(PendingRide pendingRide) => ApartOfPendingRide?.Invoke(this, pendingRide);
Beispiel #6
0
 static void OnUserNotConfirmedRide(string userId, bool isDriver, PendingRide pendingRide)
 {
     OnUserNotConfirmedRideAsync(userId, isDriver, pendingRide).FireAndForgetAsync(Program.ErrorHandler);
 }
Beispiel #7
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        /// <summary>
        /// When a user fails to confirm a pending ride, and is timed out.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="isDriver"></param>
        /// <param name="pendingRide"></param>
        static async Task OnUserNotConfirmedRideAsync(string userId, bool isDriver, PendingRide pendingRide)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
        }
Beispiel #8
0
 public static void StopTracking(PendingRide pendingRide)
 {
     pendingRide.UserTimedOut -= OnUserNotConfirmedRide;
 }