Exemplo n.º 1
0
 public RateLimiterRule(IRateLimiterStrategy strategy, IRateLimiterFilter filter)
 {
     Strategy = strategy;
     Filters  = new List <IRateLimiterFilter> {
         filter
     };
 }
Exemplo n.º 2
0
        /// <summary>
        /// Sets a custom rate limiter strategy used to determine a given operation should be rejected or not.
        /// </summary>
        /// <param name="strategy">The rate limiter strategy.</param>
        /// <returns>The configuration.</returns>
        public RateLimiterConfiguration UseStrategy(IRateLimiterStrategy strategy)
        {
            Shield.EnsureNotNull(strategy, nameof(strategy));

            this.Strategy = strategy;
            return(this);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the underlying strategy to sliding window rate limiter used to
        /// determine an operation is allowed to execute or not.
        /// </summary>
        /// <param name="maxAmountOfAllowedOperations">The maximum allowed operation count within the given time interval.</param>
        /// <param name="withinTimeInterval">The time interval within only the given maximum amount of operations set by the <paramref name="maxAmountOfAllowedOperations"/> allowed.</param>
        /// <returns></returns>
        public RateLimiterConfiguration SlidingWindow(int maxAmountOfAllowedOperations, TimeSpan withinTimeInterval)
        {
            Shield.EnsureTrue(maxAmountOfAllowedOperations > 0, $"{nameof(maxAmountOfAllowedOperations)} must be greater than zero!");
            Shield.EnsureTrue(withinTimeInterval > TimeSpan.Zero, $"{nameof(withinTimeInterval)} must be grater than zero!");

            this.Strategy = new SlidingWindowStrategy(maxAmountOfAllowedOperations, withinTimeInterval);
            return(this);
        }
Exemplo n.º 4
0
 public RateLimiterRule(IRateLimiterStrategy strategy, List <IRateLimiterFilter> filters = null)
 {
     Strategy = strategy;
     Filters  = filters;
 }
Exemplo n.º 5
0
 public RateLimiterBot(Bot innerBot, RateLimiterConfiguration configuration) : base(innerBot, configuration)
 {
     this.strategy = configuration.Strategy;
 }