Пример #1
0
 public static void For(Func<bool> pred, TimeSpan wait, TimeSpan retry)
 {
     if (retry > wait)
     {
         throw new ArgumentException("Retry period must not be greater than wait");
     }
     var tt = new TimeOutTracker(wait);
     bool isSuccess;
     var lastTry = DateTime.Now;
     while (!(isSuccess = pred()) && !tt.HasTimedOut)
     {
         TimeSpan timeSpan = retry - (DateTime.Now - lastTry);
         if (timeSpan.TotalMilliseconds > 0)
         {
             Thread.Sleep(timeSpan);
         }
         lastTry = DateTime.Now;
     }
     if (!isSuccess)
     {
         throw new TimeoutException(string.Format("timed out after waiting for {0}", wait));
     }
 }
Пример #2
0
        public static void For(Func <bool> pred, TimeSpan wait, TimeSpan retry)
        {
            if (retry > wait)
            {
                throw new ArgumentException("Retry period must not be greater than wait");
            }
            var  tt = new TimeOutTracker(wait);
            bool isSuccess;
            var  lastTry = DateTime.Now;

            while (!(isSuccess = pred()) && !tt.HasTimedOut)
            {
                TimeSpan timeSpan = retry - (DateTime.Now - lastTry);
                if (timeSpan.TotalMilliseconds > 0)
                {
                    Thread.Sleep(timeSpan);
                }
                lastTry = DateTime.Now;
            }
            if (!isSuccess)
            {
                throw new TimeoutException(string.Format("timed out after waiting for {0}", wait));
            }
        }
Пример #3
0
        private void WaitUntilPageIsInRecycleBin(TimeSpan maxWaitForDeletionInMs)
        {
            var timeoutTracker = new TimeOutTracker(maxWaitForDeletionInMs);
            do
            {
                try
                {
                    Refresh();
                }
                catch (NoSuchPageException)
                {
                    return;
                }
                if (!Exists || Status == PageState.IsInRecycleBin)
                {
                    return;
                }
            } while (!timeoutTracker.HasTimedOut);

            throw new PageDeletionException(
                Project.Session.ServerLogin,
                string.Format("Timeout while waiting for the page {0} to move into the recycle bin", this));
        }
Пример #4
0
        private void WaitForDeletionFromRecycleBin(TimeSpan maxWaitForDeletionFromRecycleBin)
        {
            //At this point we are at a race condition with the server.
            //It can happen that although the status is set to IsInRecycleBin, it can't be removed from there yet.
            //Therefor we have to try again, until it works (or a timeout is reached to avoid infinite loops on errors).
            var timeOutTracker = new TimeOutTracker(maxWaitForDeletionFromRecycleBin);
            do
            {
                DeleteFromRecycleBin();

                try
                {
                    Refresh();
                }
                catch (NoSuchPageException)
                {
                    return;
                }
                if (!Exists)
                {
                    return;
                }
            } while (!timeOutTracker.HasTimedOut);

            throw new PageDeletionException(
                Project.Session.ServerLogin,
                string.Format("Timeout while waiting for remove from recycle bin for page {0}", this));
        }