Ejemplo n.º 1
0
        protected virtual async Task PreCheckFeatureAsync(RequiresLimitFeatureContext context)
        {
            var allowed = await _limitFeatureChecker.CheckAsync(context);

            if (!allowed)
            {
                throw new AbpFeatureLimitException(context.LimitFeature, context.Limit);
            }
        }
Ejemplo n.º 2
0
        public override async Task InterceptAsync(IAbpMethodInvocation invocation)
        {
            if (AbpCrossCuttingConcerns.IsApplied(invocation.TargetObject, AbpCrossCuttingConcerns.FeatureChecking))
            {
                await invocation.ProceedAsync();

                return;
            }

            var limitFeature = GetRequiresLimitFeature(invocation.Method);

            if (limitFeature == null)
            {
                await invocation.ProceedAsync();

                return;
            }

            // 获取功能限制上限
            var limit = await _featureChecker.GetAsync(limitFeature.LimitFeature, limitFeature.DefaultLimit);

            // 获取功能限制时长
            var interval = await _featureChecker.GetAsync(limitFeature.IntervalFeature, limitFeature.DefaultInterval);

            // 必要的上下文参数
            var limitFeatureContext = new RequiresLimitFeatureContext(limitFeature.LimitFeature, _options, limitFeature.Policy, interval, limit);

            // 检查次数限制
            await PreCheckFeatureAsync(limitFeatureContext);

            // 执行代理方法
            await invocation.ProceedAsync();

            // 调用次数递增
            // TODO: 使用Redis结合Lua脚本?
            await PostCheckFeatureAsync(limitFeatureContext);
        }
 public Task <bool> CheckAsync(RequiresLimitFeatureContext context, CancellationToken cancellation = default)
 {
     return(Task.FromResult(true));
 }
 public Task ProcessAsync(RequiresLimitFeatureContext context, CancellationToken cancellation = default)
 {
     return(Task.CompletedTask);
 }
Ejemplo n.º 5
0
 protected virtual async Task PostCheckFeatureAsync(RequiresLimitFeatureContext context)
 {
     await _limitFeatureChecker.ProcessAsync(context);
 }