public async Task <object> GetAsync()
        {
            bool result = await _featureChecker.IsEnabledAsync("MyApp.PdfReporting");

            await _featureChecker.CheckEnabledAsync("MyApp.PdfReporting");

            string countLimit1 = await _featureChecker.GetOrNullAsync("MyApp.MaxProductCount");

            int countLimit2 = await _featureChecker.GetAsync <int>("MyApp.MaxProductCount");

            int countLimit3 = await _featureChecker.GetAsync("MyApp.MaxProductCount", 3);

            return(new { result, countLimit1, countLimit2, countLimit3 });
        }
Ejemplo n.º 2
0
 public static T Get <T>(
     [NotNull] this IFeatureChecker featureChecker,
     [NotNull] string name,
     T defaultValue = default)
     where T : struct
 {
     return(AsyncHelper.RunSync(() => featureChecker.GetAsync(name, defaultValue)));
 }
        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);
        }