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(); }
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); }
public abstract void PendingRideMade(PendingRide pendingRide);
protected void InvokeApartOfPendingRide(PendingRide pendingRide) => ApartOfPendingRide?.Invoke(this, pendingRide);
static void OnUserNotConfirmedRide(string userId, bool isDriver, PendingRide pendingRide) { OnUserNotConfirmedRideAsync(userId, isDriver, pendingRide).FireAndForgetAsync(Program.ErrorHandler); }
#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 { }
public static void StopTracking(PendingRide pendingRide) { pendingRide.UserTimedOut -= OnUserNotConfirmedRide; }