Exemplo n.º 1
0
        public async Task <ThrottleResult> CheckThrottle(ThrottleAction action, string userHandle, bool isRegistered)
        {
            int maxCalls = GetMaxCalls(action, isRegistered);

            if (await ThrottleCache.Increment($"{action}:{userHandle}", ThrottleMinute, maxCalls))
            {
                return(new ThrottleResult(false));
            }

            return(new ThrottleResult(true, $"Rate limit triggered, maximum {maxCalls} calls per minute"));
        }
Exemplo n.º 2
0
Arquivo: Fx.cs Projeto: wforney/corewf
                public ThrottleAttribute(ThrottleAction throttleAction, ThrottleMetric throttleMetric, string limit)
                {
                    Scope = Strings.AppDomain;

                    if (string.IsNullOrEmpty(limit))
                    {
                        throw Fx.Exception.ArgumentNullOrEmpty(nameof(limit));
                    }

                    _throttleAction = throttleAction;
                    _throttleMetric = throttleMetric;
                    _limit          = limit;
                }
Exemplo n.º 3
0
                public ThrottleAttribute(ThrottleAction throttleAction, ThrottleMetric throttleMetric, string limit)
                {
                    Scope = Strings.AppDomain;

                    if (string.IsNullOrEmpty(limit))
                    {
                        throw Fx.Exception.ArgumentNullOrEmpty("limit");
                    }

                    this.throttleAction = throttleAction;
                    this.throttleMetric = throttleMetric;
                    this.limit          = limit;
                }
Exemplo n.º 4
0
        protected override void OnParametersSet()
        {
            System.Diagnostics.Debug.WriteLine($"{nameof(DateRangeSlider)} component: {nameof(OnParametersSet)}");

            if (DateRangeChanged.HasDelegate && DateRangeChangedThrottleEventCallback == null)
            {
                Action <DateTime[]> throttleCallback = delegate(DateTime[] range)
                {
                    this.InvokeAsync(async() =>
                    {
                        await this.DateRangeChanged.InvokeAsync(range);
                        this.StateHasChanged();
                    });
                };

                DateRangeChangedThrottleEventCallback = new ThrottleAction <DateTime[]>(throttleCallback, this.ThrottleTimeout);
            }

            base.OnParametersSet();
        }
Exemplo n.º 5
0
 private static int GetMaxCalls(ThrottleAction action, bool isRegistered)
 {
     return(isRegistered
                                 ? ThrottleCountRegistered[action]
                                 : ThrottleCountUnregistered[action]);
 }