public async Task CheckAsync(MethodInvocationFeatureCheckerContext context)
    {
        if (IsFeatureCheckDisabled(context))
        {
            return;
        }

        foreach (var requiresFeatureAttribute in GetRequiredFeatureAttributes(context.Method))
        {
            await _featureChecker.CheckEnabledAsync(requiresFeatureAttribute.RequiresAll, requiresFeatureAttribute.Features);
        }
    }
        /// <summary>
        /// 多租户相关的内容。暂时不考虑
        /// <para>参考连接 https://aspnetboilerplate.com/Pages/Documents/Feature-Management </para>
        /// </summary>
        /// <param name="methodInfo"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected virtual async Task CheckFeaturesAsync(MethodInfo methodInfo, Type type)
        {
            var featureAttributes = ReflectionHelper.GetAttributesOfMemberAndType <RequiresFeatureAttribute>(methodInfo, type);

            if (featureAttributes.Count <= 0)
            {
                return;
            }

            foreach (var featureAttribute in featureAttributes)
            {
                await _featureChecker.CheckEnabledAsync(featureAttribute.RequiresAll, featureAttribute.Features);
            }
        }
Esempio n. 3
0
        private async Task CheckFeatures(MethodInfo methodInfo)
        {
            var featureAttributes = ReflectionHelper.GetAttributesOfMemberAndDeclaringType <RequiresFeatureAttribute>(methodInfo);

            if (featureAttributes.Count <= 0)
            {
                return;
            }

            foreach (var featureAttribute in featureAttributes)
            {
                await _featureChecker.CheckEnabledAsync(featureAttribute.RequiresAll, featureAttribute.Features);
            }
        }
        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 });
        }
        protected virtual async Task CheckFeatures(MethodInfo methodInfo, Type type)
        {
            var featureAttributes = ReflectionHelper.GetAttributesOfMemberAndType <RequiresFeatureAttribute>(methodInfo, type);

            if (featureAttributes.Count <= 0)
            {
                return;
            }

            if (AbpSession.TenantId == null)
            {
                if (_multiTenancyConfig.IgnoreFeatureCheckForHostUsers)
                {
                    return;
                }
            }

            foreach (var featureAttribute in featureAttributes)
            {
                await _featureChecker.CheckEnabledAsync(featureAttribute.RequiresAll, featureAttribute.Features);
            }
        }
 /// <summary>
 /// Checks if one of all given features are enabled. Throws <see cref="AbpAuthorizationException"/> if not.
 /// </summary>
 /// <param name="featureChecker"><see cref="IFeatureChecker"/> instance</param>
 /// <param name="tenantId">Tenant id</param>
 /// <param name="requiresAll">True, to require all given features are enabled. False, to require one or more.</param>
 /// <param name="featureNames">Name of the features</param>
 public static void CheckEnabled(this IFeatureChecker featureChecker, int tenantId, bool requiresAll, params string[] featureNames)
 {
     AsyncHelper.RunSync(() => featureChecker.CheckEnabledAsync(tenantId, requiresAll, featureNames));
 }