Example #1
0
        /// <summary>
        /// Adds a fallback bot to a <see cref="IBotPolicy"/> with the given configuration.
        /// </summary>
        /// <param name="builder">The policy builder.</param>
        /// <param name="configuration">The configuraton.</param>
        /// <returns>The policy builder.</returns>
        /// <example>
        /// <code>
        /// builder.Fallback(new FallbackConfiguration()
        ///     .WhenExceptionOccurs(exception => exception is HttpRequestException)
        ///     .WhenResultIs(result => result != OperationResult.Ok)
        ///     .OnFallback((exception, context) => onFallbackAction()))
        /// </code>
        /// </example>
        public static IBotPolicyBuilder <TResult> Fallback <TResult>(this IBotPolicyBuilder <TResult> builder, FallbackConfiguration <TResult> configuration)
        {
            Shield.EnsureNotNull(configuration, nameof(configuration));

            return(builder.AddBot((innerBot, config) => new FallbackBot <TResult>(innerBot, config), configuration));
        }
Example #2
0
 private IBotPolicy CreatePolicy(FallbackConfiguration conf) =>
 new BotPolicy(config => config
               .Configure(botconfig => botconfig
                          .Fallback(conf)));
Example #3
0
        /// <summary>
        /// Adds a fallback bot to a <see cref="IBotPolicy"/> with the given configuration.
        /// </summary>
        /// <param name="builder">The policy builder.</param>
        /// <param name="configuration">The configuraton.</param>
        /// <returns>The policy builder.</returns>
        /// <example>
        /// <code>
        /// builder.Fallback(new FallbackConfiguration()
        ///     .WhenExceptionOccurs(exception => exception is HttpRequestException)
        ///     .OnFallback((exception, context) => onFallbackAction()))
        /// </code>
        /// </example>
        public static IBotPolicyBuilder Fallback(this IBotPolicyBuilder builder, FallbackConfiguration configuration)
        {
            Shield.EnsureNotNull(configuration, nameof(configuration));

            return(builder.AddBot((innerBot, config) => new FallbackBot(innerBot, config), configuration));
        }