Browse Source

提交代码更改

master
Nice 2 years ago
parent
commit
70a68e6ea6
  1. 4
      Easy.Snowflakes/Easy/Realization/IDatabaseExtension.cs
  2. 12
      Easy.sln
  3. 39
      WebDemo/Controllers/WeatherForecastController.cs
  4. 26
      WebDemo/Program.cs
  5. 31
      WebDemo/Properties/launchSettings.json
  6. 12
      WebDemo/WeatherForecast.cs
  7. 17
      WebDemo/WebDemo.csproj
  8. 8
      WebDemo/appsettings.Development.json
  9. 9
      WebDemo/appsettings.json
  10. 2
      src/Easy.Core/Easy.Core.csproj
  11. 0
      src/Easy.Core/Easy/Exceptions/BusinessException.cs
  12. 0
      src/Easy.Core/Easy/When.cs
  13. 2
      src/Easy.Core/System/EnumExtension.cs
  14. 2
      src/Easy.DDD.Application/Easy.DDD.Application.csproj
  15. 1
      src/Easy.DDD.Domain/Easy/DDD/Domain/Entities/ConcurrencyStampConsts.cs
  16. 2
      src/Easy.FluentValidation/Easy/Aop/FluentValidationRegister.cs
  17. 2
      src/Easy.Result/Easy.Result.csproj
  18. 1
      src/Easy.Result/Easy/Aop/ApiResultProxy.cs
  19. 20
      src/Easy.Result/Easy/Aop/ParameterVerification.cs
  20. 4
      src/Easy.Result/Easy/Extensions/ApiResultExtensions.cs
  21. 20
      src/Easy.Result/Easy/Extensions/ServiceCollectionServiceExtensions.cs
  22. 23
      src/Easy.Result/Easy/Result/ApiResultOptions.cs
  23. 1
      src/Easy.Uow/Easy/Extensions/ServiceCollectionServiceExtensions.cs

4
Easy.Snowflakes/Easy/Realization/IDatabaseExtension.cs

@ -36,7 +36,7 @@ internal static class IDatabaseExtension
internal static async Task<bool> SafedUnLockAsync(this IDatabase redisDb, string cacheKey, string lockValue)
{
var lockKey = GetLockKey(cacheKey);
AutoDelayTimers.Instance.CloseTimer(lockKey);
AutoDelayTimers.CloseTimer(lockKey);
var script = @"local invalue = @value
local currvalue = redis.call('get',@key)
@ -68,7 +68,7 @@ internal static class IDatabaseExtension
var result = redisDb.ScriptEvaluateAsync(prepared, parameters, CommandFlags.None).GetAwaiter().GetResult();
if ((int)result == 0)
{
AutoDelayTimers.Instance.CloseTimer(key);
AutoDelayTimers.CloseTimer(key);
}
return;
}

12
Easy.sln

@ -35,7 +35,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Easy.Snowflakes", "Easy.Sno
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Easy.EventBus", "src\Easy.EventBus\Easy.EventBus.csproj", "{F464D123-49B6-4DC7-AE88-2F78CA0B6A3D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Guid.Test", "src\Guid.Test\Guid.Test.csproj", "{AB0828ED-6432-4647-8970-B57757ACD945}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDemo", "WebDemo\WebDemo.csproj", "{A42FC010-4B67-4836-A619-89C7A1C6A802}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -95,10 +95,10 @@ Global
{F464D123-49B6-4DC7-AE88-2F78CA0B6A3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F464D123-49B6-4DC7-AE88-2F78CA0B6A3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F464D123-49B6-4DC7-AE88-2F78CA0B6A3D}.Release|Any CPU.Build.0 = Release|Any CPU
{AB0828ED-6432-4647-8970-B57757ACD945}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB0828ED-6432-4647-8970-B57757ACD945}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB0828ED-6432-4647-8970-B57757ACD945}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB0828ED-6432-4647-8970-B57757ACD945}.Release|Any CPU.Build.0 = Release|Any CPU
{A42FC010-4B67-4836-A619-89C7A1C6A802}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A42FC010-4B67-4836-A619-89C7A1C6A802}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A42FC010-4B67-4836-A619-89C7A1C6A802}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A42FC010-4B67-4836-A619-89C7A1C6A802}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -119,7 +119,7 @@ Global
{8D281035-BB53-4377-9386-0CB664A5C6B3} = {A263D7E3-0153-48D0-822D-E3E0B51A4890}
{9D31086B-1333-4745-AEC2-7966141E503C} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
{F464D123-49B6-4DC7-AE88-2F78CA0B6A3D} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
{AB0828ED-6432-4647-8970-B57757ACD945} = {E2F1B3BA-DD92-4729-BDD0-91BB936520C0}
{A42FC010-4B67-4836-A619-89C7A1C6A802} = {A263D7E3-0153-48D0-822D-E3E0B51A4890}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7260112B-0232-4725-AB84-EF4DCCABFD77}

39
WebDemo/Controllers/WeatherForecastController.cs

@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
namespace WebDemo.Controllers;
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpPost(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Post(Test test)
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
public class Test
{
public string MyProperty { get; set; }
}
}

26
WebDemo/Program.cs

@ -0,0 +1,26 @@
using Easy.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddApiResultProxy();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAuthorization();
app.MapControllers();
app.Run();

31
WebDemo/Properties/launchSettings.json

@ -0,0 +1,31 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:28692",
"sslPort": 0
}
},
"profiles": {
"WebDemo": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5128",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

12
WebDemo/WeatherForecast.cs

@ -0,0 +1,12 @@
namespace WebDemo;
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}

17
WebDemo/WebDemo.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Easy.Result\Easy.Result.csproj" />
</ItemGroup>
</Project>

8
WebDemo/appsettings.Development.json

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

9
WebDemo/appsettings.json

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

2
src/Easy.Core/Easy.Core.csproj

@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<!--<Nullable>enable</Nullable>-->
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.1.5</Version>
<Version>1.1.6</Version>
<RootNamespace />
</PropertyGroup>

0
src/Easy.Result/Easy/Exceptions/BusinessException.cs → src/Easy.Core/Easy/Exceptions/BusinessException.cs

0
src/Easy.Result/Easy/When.cs → src/Easy.Core/Easy/When.cs

2
src/Easy.Core/System/EnumExtension.cs

@ -100,7 +100,7 @@ namespace System
throw new Exception("GetEnumDefineAttributes<T> 中的 T 必须为枚举类型!");
}
List<EnumDefineAttribute> list = new List<EnumDefineAttribute>();
List<EnumDefineAttribute> list = new();
EnumDefineAttribute eda = null;
foreach (var en in AsEnumerable<T>())
{

2
src/Easy.DDD.Application/Easy.DDD.Application.csproj

@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<RootNamespace />
<Version>1.1.3</Version>
<Version>1.1.4</Version>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" Version="6.0.0" />

1
src/Easy.DDD.Domain/Easy/DDD/Domain/Entities/ConcurrencyStampConsts.cs

@ -3,3 +3,4 @@ public static class ConcurrencyStampConsts
{
public const int MaxLength = 40;
}

2
src/Easy.FluentValidation/Easy/Aop/FluentValidationRegister.cs

@ -28,7 +28,7 @@ public class FluentValidationRegister : IAsyncActionFilter
var validationResult = await validator.ValidateAsync(ValidationContext);
When.Is(!validationResult.IsValid, validationResult.Errors?.First()?.ErrorMessage);
//When.Is(!validationResult.IsValid, validationResult.Errors?.First()?.ErrorMessage);
}
}
}

2
src/Easy.Result/Easy.Result.csproj

@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.1.5</Version>
<Version>1.1.6</Version>
<RootNamespace />
<!--<Nullable>enable</Nullable>-->
</PropertyGroup>

1
src/Easy.Result/Easy/Aop/ApiResultProxy.cs

@ -48,6 +48,7 @@ public class ApiResultProxy : IAsyncExceptionFilter
});
}
}
}

20
src/Easy.Result/Easy/Aop/ParameterVerification.cs

@ -0,0 +1,20 @@
using Easy.Result;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Easy.Aop;
public class ParameterVerification : IAsyncActionFilter
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
if (!context.ModelState.IsValid)
{
var errorMessage = context.ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault();
await context.HttpContext.Response.WriteAsJsonAsync(new ApiResult()
{
Message = errorMessage.ErrorMessage,
Status = "RETRY",
});
}
}
}

4
src/Easy.Result/Easy/Extensions/ApiResultExtensions.cs

@ -19,7 +19,7 @@ public static class ApiResultExtensions
static public TSource SUCCESS<TSource>(this TSource source, string message = null)
where TSource : ApiResult
{
return source.CustomStatusMessage("SUCCESS", message ?? "操作成功");
return source.CustomStatusMessage(ApiResultConsts.SUCCESS, message ?? "操作成功");
}
/// <summary>
/// 重试
@ -27,7 +27,7 @@ public static class ApiResultExtensions
static public TSource RETRY<TSource>(this TSource source, string message = null)
where TSource : ApiResult
{
return source.CustomStatusMessage("RETRY", message ?? "出错了,请稍后再试。");
return source.CustomStatusMessage(ApiResultConsts.RETRY, message ?? "出错了,请稍后再试。");
}
/// <summary>
/// 自定义状态消息

20
src/Easy.Result/Easy/Extensions/ServiceCollectionServiceExtensions.cs

@ -1,16 +1,32 @@
using Easy.Aop;
using Easy.Result;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
namespace Easy.Extensions;
public static class ServiceCollectionServiceExtensions
{
public static IServiceCollection AddApiResultProxy(this IServiceCollection services)
public static IServiceCollection AddApiResultProxy(this IServiceCollection services, ApiResultOptions apiResultOptions)
{
services.Configure<MvcOptions>(options =>
{
options.Filters.Add<ApiResultProxy>();
if (apiResultOptions.ApiResultRroxy)
{
options.Filters.Add<ApiResultProxy>();
}
if (apiResultOptions.ParameterVerification)
{
options.Filters.Add<ParameterVerification>();
}
});
if (apiResultOptions.ParameterVerification)
{
services.Configure<ApiBehaviorOptions>(options =>
{
// 使用自定义模型验证【Api接口需要添加才能生效】
options.SuppressModelStateInvalidFilter = true;
});
}
return services;
}

23
src/Easy.Result/Easy/Result/ApiResultOptions.cs

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Easy.Result;
public class ApiResultOptions
{
/// <summary>
/// 参数验证
/// </summary>
public bool ParameterVerification { get; set; }
/// <summary>
/// 结果代理
/// </summary>
public bool ApiResultRroxy { get; set; }
public ApiResultOptions()
{
ParameterVerification = true;
ApiResultRroxy = true;
}
}

1
src/Easy.Uow/Easy/Extensions/ServiceCollectionServiceExtensions.cs

@ -15,7 +15,6 @@ public static class ServiceCollectionServiceExtensions
{
options.Filters.Add<UnitOfWorkProxy>();
});
//IUnitOfWorkManager
return services;
}

Loading…
Cancel
Save