private static SafeWait <object> CreateSafeWait(RetryOptions options)
        {
            var wait = new SafeWait <object>(string.Empty)
            {
                Timeout         = options.Timeout,
                PollingInterval = options.Interval
            };

            foreach (Type exceptionType in options.IgnoredExceptionTypes)
            {
                wait.IgnoreExceptionTypes(exceptionType);
            }

            return(wait);
        }
        private IWait <T> CreateWait(RetryOptions options)
        {
            IWait <T> wait = new SafeWait <T>(Context)
            {
                Timeout         = options.Timeout,
                PollingInterval = options.Interval
            };

            foreach (Type exceptionType in options.IgnoredExceptionTypes)
            {
                wait.IgnoreExceptionTypes(exceptionType);
            }

            return(wait);
        }
        public TResult Until <TResult>(Func <T, TResult> condition, TimeSpan?timeout = null, TimeSpan?retryInterval = null)
        {
            RetryOptions options = new RetryOptions();

            if (timeout.HasValue)
            {
                options.Timeout = timeout.Value;
            }

            if (retryInterval.HasValue)
            {
                options.Interval = retryInterval.Value;
            }

            return(Until(condition, options));
        }
示例#4
0
        protected virtual RetryOptions GetRetryOptions()
        {
            RetryOptions options = new RetryOptions();

            if (Timeout.HasValue)
            {
                options.Timeout = Timeout.Value;
            }

            if (RetryInterval.HasValue)
            {
                options.Interval = RetryInterval.Value;
            }

            options.IgnoringStaleElementReferenceException();

            return(options);
        }
        public TResult Until <TResult>(Func <T, TResult> condition, RetryOptions options)
        {
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }

            options = options ?? new RetryOptions();

            if (!options.IsTimeoutSet)
            {
                options.Timeout = Timeout;
            }

            if (!options.IsIntervalSet)
            {
                options.Interval = RetryInterval;
            }

            var wait = CreateWait(options);

            return(wait.Until(condition));
        }
        internal static bool ExecuteUntil(Func <bool> condition, RetryOptions retryOptions)
        {
            var wait = CreateSafeWait(retryOptions);

            return(wait.Until(_ => condition()));
        }