Beispiel #1
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            RetryAttribute retryAttribute =
                (RetryAttribute)input.MethodBase.GetCustomAttributes(typeof(RetryAttribute), false)[0];

            IMethodReturn returnValue = DoInvoke(input, getNext);

            if (returnValue.Exception != null && IsExceptionTypeMatch(returnValue.Exception.GetType(), retryAttribute))
            {
                if (retryTimes >= retryAttribute.RetryTimes)
                {
                    return(returnValue);
                }

                retryTimes++;

                Invoke(input, getNext);
            }

            return(returnValue);
        }
Beispiel #2
0
 private bool IsExceptionTypeMatch(Type exceptionType, RetryAttribute retryAttribute)
 {
     return(exceptionType == retryAttribute.Type || exceptionType.IsSubclassOf(retryAttribute.Type));
 }