44 changed files with 321 additions and 134 deletions
@ -1,7 +1,7 @@ |
|||
using Microsoft.Extensions.Options; |
|||
using StackExchange.Redis; |
|||
|
|||
namespace LINGYUN.Abp.Features.Validation.Redis |
|||
namespace LINGYUN.Abp.Features.LimitValidation.Redis |
|||
{ |
|||
public class AbpRedisRequiresLimitFeatureOptions : IOptions<AbpRedisRequiresLimitFeatureOptions> |
|||
{ |
|||
@ -0,0 +1,24 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<None Remove="LINGYUN\Abp\Features\LimitValidation\Localization\Resources\en.json" /> |
|||
<None Remove="LINGYUN\Abp\Features\LimitValidation\Localization\Resources\zh-Hans.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<EmbeddedResource Include="LINGYUN\Abp\Features\LimitValidation\Localization\Resources\en.json" /> |
|||
<EmbeddedResource Include="LINGYUN\Abp\Features\LimitValidation\Localization\Resources\zh-Hans.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.Features" Version="3.2.0" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,33 @@ |
|||
using LINGYUN.Abp.Features.LimitValidation.Localization; |
|||
using Microsoft.Extensions.Localization; |
|||
using Volo.Abp; |
|||
using Volo.Abp.ExceptionHandling; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.Abp.Features.LimitValidation |
|||
{ |
|||
public class AbpFeatureLimitException : AbpException, ILocalizeErrorMessage, IBusinessException |
|||
{ |
|||
/// <summary>
|
|||
/// 功能名称名称
|
|||
/// </summary>
|
|||
public string Feature { get; } |
|||
/// <summary>
|
|||
/// 上限
|
|||
/// </summary>
|
|||
public int Limit { get; } |
|||
|
|||
public AbpFeatureLimitException(string feature, int limit) |
|||
: base($"Features {feature} has exceeded the maximum number of calls {limit}, please apply for the appropriate permission") |
|||
{ |
|||
Feature = feature; |
|||
Limit = limit; |
|||
} |
|||
public string LocalizeMessage(LocalizationContext context) |
|||
{ |
|||
var localizer = context.LocalizerFactory.Create<FeaturesLimitValidationResource>(); |
|||
|
|||
return localizer["FeaturesLimitException", Limit]; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
using LINGYUN.Abp.Features.LimitValidation.Localization; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Features; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.VirtualFileSystem; |
|||
|
|||
namespace LINGYUN.Abp.Features.LimitValidation |
|||
{ |
|||
[DependsOn(typeof(AbpFeaturesModule))] |
|||
public class AbpFeaturesLimitValidationModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.OnRegistred(FeaturesLimitValidationInterceptorRegistrar.RegisterIfNeeded); |
|||
|
|||
Configure<AbpFeaturesLimitValidationOptions>(options => |
|||
{ |
|||
options.MapDefaultEffectPolicys(); |
|||
}); |
|||
|
|||
Configure<AbpVirtualFileSystemOptions>(options => |
|||
{ |
|||
options.FileSets.AddEmbedded<AbpFeaturesLimitValidationModule>(); |
|||
}); |
|||
|
|||
Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Resources |
|||
.Add<FeaturesLimitValidationResource>("en") |
|||
.AddVirtualJson("/LINGYUN/Abp/Features/LimitValidation/Localization/Resources"); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,11 +1,11 @@ |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace LINGYUN.Abp.Features.Validation |
|||
namespace LINGYUN.Abp.Features.LimitValidation |
|||
{ |
|||
public interface IRequiresLimitFeatureChecker |
|||
{ |
|||
Task CheckAsync(RequiresLimitFeatureContext context, CancellationToken cancellation = default); |
|||
Task<bool> CheckAsync(RequiresLimitFeatureContext context, CancellationToken cancellation = default); |
|||
|
|||
Task ProcessAsync(RequiresLimitFeatureContext context, CancellationToken cancellation = default); |
|||
} |
|||
@ -1,4 +1,4 @@ |
|||
namespace LINGYUN.Abp.Features.Validation |
|||
namespace LINGYUN.Abp.Features.LimitValidation |
|||
{ |
|||
public enum LimitPolicy : byte |
|||
{ |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace LINGYUN.Abp.Features.LimitValidation.Localization |
|||
{ |
|||
[LocalizationResourceName("AbpFeaturesLimitValidation")] |
|||
public class FeaturesLimitValidationResource |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"FeaturesLimitException": "Service has exceeded the maximum number of calls {0}. Please apply for the appropriate permissions" |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "zh-Hans", |
|||
"texts": { |
|||
"FeaturesLimitException": "服务已超过最大调用次数 {0},请申请适当的权限" |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
English | [简体中文](./README.md) |
|||
|
|||
# LINGYUN.Abp.Features.LimitValidation |
|||
|
|||
Features limit validation component |
|||
|
|||
Check the number of function calls defined to limit calls to the application by specific entities (tenants, users, clients, and so on) |
|||
|
|||
Predefined policy |
|||
|
|||
LimitPolicy.Minute Calculate the flow by the minutes |
|||
LimitPolicy.Hours Calculate the flow by the hours |
|||
LimitPolicy.Days Calculate the flow by days |
|||
LimitPolicy.Weeks Calculate the flow by weeks |
|||
LimitPolicy.Month Calculate the flow by the number of month |
|||
LimitPolicy.Years Calculate the flow by the number of years |
|||
|
|||
## How to use |
|||
|
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpFeaturesLimitValidationModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
// other |
|||
} |
|||
``` |
|||
|
|||
If you want to limit the policy duration by self-processing, override the default policy for the corresponding policy and always return a clock scale in seconds |
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpFeaturesLimitValidationModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpFeaturesLimitValidationOptions>(options => |
|||
{ |
|||
options.MapEffectPolicy(LimitPolicy.Minute, (time) => return 60;); // Means that no matter how many minutes (time), only 60 seconds will be limited |
|||
}); |
|||
} |
|||
} |
|||
``` |
|||
@ -0,0 +1,43 @@ |
|||
[English](./README.en.md) | 简体中文 |
|||
|
|||
# LINGYUN.Abp.Features.LimitValidation |
|||
|
|||
功能上限验证组件 |
|||
|
|||
检查定义的功能调用次数,来限制特定的实体(租户、用户、客户端等)对于应用程序的调用 |
|||
|
|||
预先设定了如下几个策略 |
|||
|
|||
LimitPolicy.Minute 按分钟计算流量 |
|||
LimitPolicy.Hours 按小时计算流量 |
|||
LimitPolicy.Days 按天数计算流量 |
|||
LimitPolicy.Weeks 按周数计算流量 |
|||
LimitPolicy.Month 按月数计算流量 |
|||
LimitPolicy.Years 按年数计算流量 |
|||
|
|||
## 配置使用 |
|||
|
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpFeaturesLimitValidationModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
// other |
|||
} |
|||
``` |
|||
|
|||
如果需要自行处理功能限制策略时长,请覆盖对应策略的默认策略,返回的时钟刻度单位始终是秒 |
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpFeaturesLimitValidationModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
Configure<AbpFeaturesLimitValidationOptions>(options => |
|||
{ |
|||
options.MapEffectPolicy(LimitPolicy.Minute, (time) => return 60;); // 表示不管多少分钟(time),都只会限制60秒 |
|||
}); |
|||
} |
|||
} |
|||
``` |
|||
@ -1,14 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.Features" Version="3.2.0" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,20 +0,0 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Features; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace LINGYUN.Abp.Features.Validation |
|||
{ |
|||
[DependsOn(typeof(AbpFeaturesModule))] |
|||
public class AbpFeaturesValidationModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
context.Services.OnRegistred(FeaturesValidationInterceptorRegistrar.RegisterIfNeeded); |
|||
|
|||
Configure<AbpFeaturesValidationOptions>(options => |
|||
{ |
|||
options.MapDefaultEffectPolicys(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
# LINGYUN.Abp.FeatureManagement.Client |
|||
|
|||
针对客户端的功能验证管理授权 |
|||
|
|||
## 配置使用 |
|||
|
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpFeatureManagementClientModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
// other |
|||
} |
|||
``` |
|||
@ -0,0 +1,14 @@ |
|||
# LINGYUN.Abp.Features.Client |
|||
|
|||
针对客户端的功能验证 |
|||
|
|||
## 配置使用 |
|||
|
|||
|
|||
```csharp |
|||
[DependsOn(typeof(AbpFeaturesClientModule))] |
|||
public class YouProjectModule : AbpModule |
|||
{ |
|||
// other |
|||
} |
|||
``` |
|||
@ -0,0 +1,9 @@ |
|||
using LINGYUN.Abp.Tests; |
|||
|
|||
namespace LINGYUN.Abp.Features.LimitValidation.Redis |
|||
{ |
|||
public class AbpFeaturesLimitValidationRedisTestBase : AbpTestsBase<AbpFeaturesLimitValidationRedisTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using LINGYUN.Abp.Tests; |
|||
|
|||
namespace LINGYUN.Abp.Features.LimitValidation |
|||
{ |
|||
public class AbpFeaturesLimitValidationTestBase : AbpTestsBase<AbpFeaturesLimitValidationTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -1,7 +1,7 @@ |
|||
using Volo.Abp.Features; |
|||
using Volo.Abp.Validation.StringValues; |
|||
|
|||
namespace LINGYUN.Abp.Features.Validation |
|||
namespace LINGYUN.Abp.Features.LimitValidation |
|||
{ |
|||
public class TestFeatureDefinitionProvider : FeatureDefinitionProvider |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace LINGYUN.Abp.Features.Validation |
|||
namespace LINGYUN.Abp.Features.LimitValidation |
|||
{ |
|||
public class TestFeatureNames |
|||
{ |
|||
@ -1,4 +1,4 @@ |
|||
namespace LINGYUN.Abp.Features.Validation |
|||
namespace LINGYUN.Abp.Features.LimitValidation |
|||
{ |
|||
public class TestFeatureTenant |
|||
{ |
|||
@ -1,9 +0,0 @@ |
|||
using LINGYUN.Abp.Tests; |
|||
|
|||
namespace LINGYUN.Abp.Features.Validation.Redis |
|||
{ |
|||
public class AbpFeaturesValidationRedisTestBase : AbpTestsBase<AbpFeaturesValidationRedisTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -1,8 +0,0 @@ |
|||
using LINGYUN.Abp.Tests; |
|||
|
|||
namespace LINGYUN.Abp.Features.Validation |
|||
{ |
|||
public class AbpFeaturesValidationTestBase : AbpTestsBase<AbpFeaturesValidationTestModule> |
|||
{ |
|||
} |
|||
} |
|||
Loading…
Reference in new issue