コード例 #1
0
        /// <summary>
        /// Parses the advice expression.
        /// </summary>
        /// <param name="adviceExpression">The advice expression.</param>
        /// <returns>An instance of ParsedAdviceExpression</returns>
        protected virtual ParsedAdviceExpression ParseAdviceExpression(string adviceExpression)
        {
            ParsedAdviceExpression parsedAdviceExpression = new ParsedAdviceExpression(adviceExpression);

            Match match = GetMatch(adviceExpression, OnExceptionNameRegex);

            if (match.Success)
            {
                parsedAdviceExpression.Success = true;
                //using exception names for exception filter
                parsedAdviceExpression.ExceptionNames       = StringUtils.CommaDelimitedListToStringArray(match.Groups[2].Value.Trim());
                parsedAdviceExpression.ActionText           = match.Groups[3].Value.Trim();
                parsedAdviceExpression.ActionExpressionText = match.Groups[4].Value.Trim();
            }
            else
            {
                match = GetMatch(adviceExpression, OnExceptionRegex);
                if (match.Success)
                {
                    parsedAdviceExpression.Success = true;
                    //using constratin expression for exception filter
                    string constraintExpression = match.Groups[2].Value.Trim().Remove(0, 1);
                    parsedAdviceExpression.ConstraintExpression = constraintExpression.Substring(0, constraintExpression.Length - 1);
                    parsedAdviceExpression.ActionText           = match.Groups[3].Value.Trim();
                    parsedAdviceExpression.ActionExpressionText = match.Groups[4].Value.Trim();
                }
            }
            return(parsedAdviceExpression);
        }
コード例 #2
0
ファイル: RetryAdvice.cs プロジェクト: Oragon/Oragon.Spring
        /// <summary>
        /// Parses the specified handler string.
        /// </summary>
        /// <param name="retryExpressionString">The handler string.</param>
        /// <returns></returns>
        protected virtual RetryExceptionHandler Parse(string retryExpressionString)
        {
            ParsedAdviceExpression parsedAdviceExpression = ParseAdviceExpression(retryExpressionString);

            if (!parsedAdviceExpression.Success)
            {
                log.Warn("Could not parse retry expression " + retryExpressionString);
                return(null);
            }

            RetryExceptionHandler handler = new RetryExceptionHandler(parsedAdviceExpression.ExceptionNames);

            handler.ConstraintExpressionText = parsedAdviceExpression.ConstraintExpression;
            handler.ActionExpressionText     = parsedAdviceExpression.AdviceExpression;

            Match match = GetMatchForActionExpression(parsedAdviceExpression.ActionExpressionText, delayRegex);

            if (match.Success)
            {
                handler.MaximumRetryCount = int.Parse(match.Groups[1].Value.Trim());
                handler.IsDelayBased      = true;

                try
                {
                    string ts = match.Groups[3].Value.Trim();
                    handler.DelayTimeSpan = (TimeSpan)timeSpanConverter.ConvertFrom(null, null, ts);
                } catch (Exception)
                {
                    log.Warn("Could not parse timespan " + match.Groups[3].Value.Trim());
                    return(null);
                }
                return(handler);
            }
            else
            {
                match = GetMatchForActionExpression(parsedAdviceExpression.ActionExpressionText, rateRegex);
                if (match.Success)
                {
                    handler.MaximumRetryCount   = int.Parse(match.Groups[1].Value.Trim());
                    handler.IsDelayBased        = false;
                    handler.DelayRateExpression = match.Groups[3].Value.Trim();
                    return(handler);
                }
                else
                {
                    return(null);
                }
            }
        }