Пример #1
0
        async Task DoneGettingConfirmations()
        {
            IEnumerable <UserRideRequest> passengers = requests;

            lock (requests)
            {
                if (confirmedRideRequests.Count != requests.Count)
                {
                    //Can't just use confirmedRideRequsts because it is unordered; we want to maintain the original ordering.
                    passengers = requests.Where((rr) => confirmedRideRequests.Contains(rr));

                    originalRideModified = true;

                    //Expire the requests of all the others
                    foreach (var rr in requests.Where((r) => !confirmedRideRequests.Contains(r)))
                    {
                        rr.SetExpired();
                        UserTimedOut?.Invoke(rr.User.UserInfo.UserId, false, this);
                    }
                }
            }

            // If all passengers canceled, cancel the offer. If there were no
            // passengers (which should only happen in development), confirm
            // the offer.
            if (!passengers.Any() && requests.Any())
            {
                Cancel();

                return;
            }

            state = PendingRideState.Confirmed;

            if (originalRideModified)
            {
                RideInfo = await rideMatcher.MakeBestRide(offer, passengers);
            }

            //Now we pass the final info to the ActiveRideCenter
            ActiveRideId = await ActiveRideCenter.ActiveRideStarted(RideInfo, offer, confirmedRideRequests);

            PostStatus(0, ActiveRideId).FireAndForgetAsync(Program.ErrorHandler);

            CleanUp();

            StateUpdated?.Invoke(this);
        }
Пример #2
0
        /// <summary>
        /// Create a new <see cref="PendingRide"/>
        /// </summary>
        /// <param name="rideInfo">The original ride info of this ride</param>
        /// <param name="offer">The ride offer of this pending ride</param>
        /// <param name="requests">All the ride requests apart of this pending ride</param>
        /// <param name="rideMatcher">Used to create a new route if anything changes durring the confirmation phase</param>
        /// <param name="driverExpireTime">Time in milliseconds the driver has to confirm</param>
        /// <param name="riderExpireTime">Time in milliseconds the riders have to confirm, after the driver confirms</param>
        public PendingRide(RideInfo rideInfo,
                           UserRideOffer offer,
                           ICollection <UserRideRequest> requests,
                           IRideMatcher rideMatcher,
                           double driverExpireTime = 120000,
                           double riderExpireTime  = 120000)
        {
            RideInfo = rideInfo;
            Id       = IdGenerator.GenerateNewId(this);

            this.offer       = offer;
            this.requests    = requests;
            this.rideMatcher = rideMatcher;

            userToUserRequest.TryAdd(offer.User, offer);
            foreach (UserRideRequest rr in requests)
            {
                userToUserRequest.TryAdd(rr.User, rr);
            }

            driverTimer = new Timer
            {
                AutoReset = false,
                Interval  = driverExpireTime,
                Enabled   = false
            };
            riderTimer = new Timer
            {
                AutoReset = false,
                Interval  = riderExpireTime,
                Enabled   = false
            };

            driverTimer.Elapsed += (a, b) =>
            {
                offer.SetExpired();
                Cancel();
                UserTimedOut?.Invoke(offer.User.UserInfo.UserId, true, this);
            };
            riderTimer.Elapsed += async(a, b) => await DoneGettingConfirmations();
        }
Пример #3
0
 protected virtual void OnUserTimedOut(TwitchUserTimeout userTimeout)
 {
     UserTimedOut?.Invoke(this, new UserTimedOutEventArgs(userTimeout));
 }