Beispiel #1
0
        /// <summary>
        /// Invoke the operation
        /// </summary>
        /// <param name="operation">indicating the operation delegate</param>
        /// <param name="onException">indicating the delegate to handle exception</param>
        /// <param name="retryCount">indicating the max retry count</param>
        /// <returns>returns result</returns>
        public static T InvokeOperation(OperationDelegate operation, ExceptionThrownDelegate onException, RetryPolicy policy)
        {
            int       retry         = policy.RetryCount;
            Exception lastException = null;

            while (retry > 0)
            {
                try
                {
                    return(operation());
                }
                catch (Exception e)
                {
                    lastException = e;
                    onException(e, retry);

                    if (!policy.NoIncreaseRetryCountExceptionList.Contains(e.GetType()))
                    {
                        retry--;
                    }
                }
            }

            throw lastException;
        }
Beispiel #2
0
        public void ExceptionThrown(TestAssembly testAssembly, Exception exception)
        {
            if (InvokeRequired)
            {
                Delegate del = new ExceptionThrownDelegate(ExceptionThrown);
                BeginInvoke(del, testAssembly, exception);
                return;
            }

            textResults.Text += exception.ToString() + Environment.NewLine + Environment.NewLine;
        }
 public static void TryDispose(this IDisposable item, ExceptionThrownDelegate onFail)
 {
     if (item == null)
     {
         return;
     }
     try
     {
         item.Dispose();
     }
     catch (Exception ex)
     {
         if (onFail != null)
         {
             onFail(ex);
         }
     }
 }
Beispiel #4
0
        public void ExceptionThrown(TestAssembly testAssembly, Exception exception)
        {
            if (InvokeRequired)
            {
                Delegate del = new ExceptionThrownDelegate(ExceptionThrown);
                BeginInvoke(del, testAssembly, exception);
                return;
            }

            textResults.Text += exception.ToString() + Environment.NewLine + Environment.NewLine;
        }
Beispiel #5
0
 /// <summary>
 /// Invoke the operation
 /// </summary>
 /// <param name="operation">indicating the operation delegate</param>
 /// <param name="onException">indicating the delegate to handle exception</param>
 /// <param name="retryCount">indicating the max retry count</param>
 /// <returns>returns result</returns>
 public static T InvokeOperation(OperationDelegate operation, ExceptionThrownDelegate onException, int retryCount)
 {
     return(InvokeOperation(operation, onException, new RetryPolicy(retryCount)));
 }