예제 #1
0
        private bool CheckNotPastLockedDateTime(out TimeSpan waitFor, DateTime timeToCheck)
        {
            // If lockedDateTime doesn't have a value, storedLockedDateTime is null
            // If lockedDateTime has a value, but it is before the timeToCheck, set it to null, and set storedLockedDateTime to null
            // Otherwise, set storedLockedDateTime to the value of lockedDateTime
            var storedLockedDateTime = LockHelper.LockedCreateOrUpdate(
                ref _disabledUntilLock,
                ref _disabledUntil,
                (currentValue) => currentValue.HasValue && timeToCheck > currentValue,
                (currentValue) =>
            {
                return(null);
            }
                );

            // If storedLockedDateTime is not null, we return false (the time to check is before the lockedDateTime) and we out the remaining time difference.
            if (storedLockedDateTime.HasValue)
            {
                waitFor = storedLockedDateTime.Value - timeToCheck;
                return(false);
            }

            // Otherwise, we return false, and out 0 (as we've already passed the time stored in lockedDateTime)
            waitFor = TimeSpan.Zero;
            return(true);
        }
예제 #2
0
 /// <summary>
 /// See ISettableCircuitProvider
 /// </summary>
 public void SetOpenUntil(DateTime newTime)
 {
     // If lockedDateTime does not have a value OR it does have a value but that value is less than
     // the newTime passed in, set lockedDateTime to the value passed in.
     // Otherwise, leave lockedDateTime with the current value
     LockHelper.LockedCreateOrUpdate(
         ref _disabledUntilLock,
         ref _disabledUntil,
         (currentValue) => !currentValue.HasValue || (currentValue.HasValue && newTime > currentValue),
         (currentValue) => newTime
         );
 }