Пример #1
0
 public MoreTimeRequestController(
     MoreTimeRequestContext context,
     ITimeRequestData timeRequestData,
     ITimeTravelClock timeTravelClock,
     ITimeTracker timeTracker)
 {
     _dbContext       = context;
     _timeRequestData = timeRequestData;
     _clock           = timeTravelClock;
     _timeTracker     = timeTracker;
     if (_timeRequestData.NumTimeRequests(_dbContext) == 0)
     {
         // Create a new MoreTimeRequest if collection is empty,
         // which means you can't delete all MoreTimeRequests.
         _timeRequestData.AddTimeRequest(
             _dbContext,
             new MoreTimeRequest {
             RequestTimeStamp             = _clock.Now,
             Expired                      = true,
             Alerted                      = true,
             LengthInMinutes              = 0,
             MinutesToAdjustClockBy       = 0,
             TimeAdjustmentAtCreationTime = 0
         });
         _timeRequestData.SaveChanges(_dbContext);
     }
 }
Пример #2
0
        public int GetTimeDifferenceSinceRequest(
            MoreTimeRequest request,
            int accumulatedTime,
            ITimeTravelClock clock)
        {
            var negativeTimeDifference            = request.TimeAdjustmentAtCreationTime * -1;
            var timeNowFromRequestUserPerspective = RemoveSeconds(clock.Now.AddMinutes(negativeTimeDifference));
            var requestTimeWithoutSeconds         = RemoveSeconds(request.RequestTimeStamp);
            var timeDifference = Convert.ToInt32(
                timeNowFromRequestUserPerspective
                .Subtract(requestTimeWithoutSeconds)
                .TotalMinutes);

            return(timeDifference);
        }
Пример #3
0
        public bool IsTimeRequestReadyForAlert(
            MoreTimeRequest timeRequest,
            int accumulatedTime,
            ITimeTravelClock clock)
        {
            bool alert = false;

            if (timeRequest.Alerted == false)
            {
                var timeDifference = GetTimeDifferenceSinceRequest(
                    timeRequest,
                    accumulatedTime,
                    clock);

                if (timeDifference >= timeRequest.LengthInMinutes)
                {
                    alert = true;
                }
            }
            return(alert);
        }
Пример #4
0
        public bool HasTimeRequestJustExpired(
            MoreTimeRequest timeRequest,
            int accumulatedTime,
            ITimeTravelClock clock)
        {
            bool expired = false;

            if (timeRequest.Expired == false)
            {
                var timeDifference = GetTimeDifferenceSinceRequest(
                    timeRequest,
                    accumulatedTime,
                    clock);

                if (timeDifference >= timeRequest.LengthInMinutes)
                {
                    expired = true;
                }
            }
            return(expired);
        }