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")); }
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; }
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; }
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(); }
private static int GetMaxCalls(ThrottleAction action, bool isRegistered) { return(isRegistered ? ThrottleCountRegistered[action] : ThrottleCountUnregistered[action]); }