diff --git a/aspnet-core/Lion.AbpPro.sln b/aspnet-core/Lion.AbpPro.sln index 8b63f2a5..ac19300f 100644 --- a/aspnet-core/Lion.AbpPro.sln +++ b/aspnet-core/Lion.AbpPro.sln @@ -168,7 +168,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lion.AbpPro.FileManagement. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lion.AbpPro.FileManagement.HttpApi.Host", "modules\FileManagement\host\Lion.AbpPro.FileManagement.HttpApi.Host\Lion.AbpPro.FileManagement.HttpApi.Host.csproj", "{831CD22A-AC6E-4515-AB24-8C96B34C717F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.FreeSqlReppsitory", "services\src\Lion.AbpPro.FreeSqlReppsitory\Lion.AbpPro.FreeSqlReppsitory.csproj", "{27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lion.AbpPro.FreeSqlRepository", "services\src\Lion.AbpPro.FreeSqlRepository\Lion.AbpPro.FreeSqlRepository.csproj", "{27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.FreeSqlRepository.Tests", "services\test\Lion.AbpPro.FreeSqlRepository.Tests\Lion.AbpPro.FreeSqlRepository.Tests.csproj", "{7971DF5A-B001-4751-8F40-D7752C612BF1}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -404,6 +406,10 @@ Global {27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}.Debug|Any CPU.Build.0 = Debug|Any CPU {27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}.Release|Any CPU.ActiveCfg = Release|Any CPU {27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18}.Release|Any CPU.Build.0 = Release|Any CPU + {7971DF5A-B001-4751-8F40-D7752C612BF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7971DF5A-B001-4751-8F40-D7752C612BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7971DF5A-B001-4751-8F40-D7752C612BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7971DF5A-B001-4751-8F40-D7752C612BF1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -484,6 +490,7 @@ Global {78589964-923E-4803-9B74-183487C3ED0F} = {40BF21CB-4520-45A6-A588-5FFB95BAC87C} {831CD22A-AC6E-4515-AB24-8C96B34C717F} = {C188A1F4-9601-42E5-9A0A-B282E13EAC41} {27C7A0E6-4C2E-4AFF-9DE7-1F526DDC0D18} = {CA9AC87F-097E-4F15-8393-4BC07735A5B0} + {7971DF5A-B001-4751-8F40-D7752C612BF1} = {04DBDB01-70F4-4E06-B468-8F87850B22BE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F} diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConsts.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConst.cs similarity index 95% rename from aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConsts.cs rename to aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConst.cs index 0799dc29..a5580a56 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConsts.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostConst.cs @@ -1,6 +1,6 @@ namespace Lion.AbpPro { - public class AbpProHttpApiHostConsts + public static class AbpProHttpApiHostConst { /// /// 跨域策略名 diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs index 72cf7124..e3259b75 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs @@ -21,9 +21,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Lion.AbpPro.CAP; -using Lion.AbpPro.Extensions.Filters; +using Lion.AbpPro.Extensions; using Lion.AbpPro.Extensions.Hangfire; -using Lion.AbpPro.Jobs; using Lion.AbpPro.Shared.Hosting.Microservices; using Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.Builder; using Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filters; @@ -31,7 +30,6 @@ using Lion.AbpPro.Shared.Hosting.Microservices.Swaggers; using Volo.Abp; using Volo.Abp.Account.Web; using Volo.Abp.AspNetCore.Authentication.JwtBearer; -using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic; using Volo.Abp.AspNetCore.Serilog; @@ -75,13 +73,13 @@ namespace Lion.AbpPro { var configuration = context.Services.GetConfiguration(); ConfigureCache(context); - ConfigureSwaggerServices(context, configuration); + ConfigureSwaggerServices(context); ConfigureOptions(context); ConfigureJwtAuthentication(context, configuration); ConfigureHangfireMysql(context); - ConfigurationCap(context); - ConfigurationStsHttpClient(context); - ConfigurationMiniProfiler(context); + ConfigureCap(context); + ConfigureHttpClient(context); + ConfigureMiniProfiler(context); ConfigureMagicodes(context); ConfigureAbpExceptions(context); ConfigureIdentity(context); @@ -91,12 +89,13 @@ namespace Lion.AbpPro { var app = context.GetApplicationBuilder(); var configuration = context.GetConfiguration(); + app.UseRequestLog(); app.UseAbpRequestLocalization(); app.UseCorrelationId(); app.UseStaticFiles(); app.UseMiniProfiler(); app.UseRouting(); - app.UseCors(AbpProHttpApiHostConsts.DefaultCorsPolicyName); + app.UseCors(AbpProHttpApiHostConst.DefaultCorsPolicyName); app.UseAuthentication(); if (MultiTenancyConsts.IsEnabled) @@ -124,7 +123,7 @@ namespace Lion.AbpPro IgnoreAntiforgeryToken = true }); - if (configuration.GetValue("Consul:Enabled", false)) + if (configuration.GetValue("Consul:Enabled", false)) { app.UseConsul(); } @@ -146,7 +145,6 @@ namespace Lion.AbpPro /// 配置Magicodes.IE /// Excel导入导出 /// - /// private void ConfigureMagicodes(ServiceConfigurationContext context) { context.Services.AddTransient(); @@ -170,8 +168,8 @@ namespace Lion.AbpPro JobExpirationCheckInterval = TimeSpan.FromMinutes(30), TablesPrefix = "Hangfire_" })); - var delaysInSeconds = new int[] { 10, 60, 60 * 3 }; // 重试时间间隔 - var Attempts = 3; // 重试次数 + var delaysInSeconds = new[] { 10, 60, 60 * 3 }; // 重试时间间隔 + const int Attempts = 3; // 重试次数 config.UseFilter(new AutomaticRetryAttribute() { Attempts = Attempts, DelaysInSeconds = delaysInSeconds }); config.UseFilter(new AutoDeleteAfterSuccessAttributer(TimeSpan.FromDays(7))); config.UseFilter(new JobRetryLastFilter(Attempts)); @@ -182,7 +180,7 @@ namespace Lion.AbpPro /// 配置MiniProfiler /// /// - private void ConfigurationMiniProfiler(ServiceConfigurationContext context) + private void ConfigureMiniProfiler(ServiceConfigurationContext context) { context.Services.AddMiniProfiler(options => options.RouteBasePath = "/profiler") .AddEntityFramework(); @@ -204,7 +202,7 @@ namespace Lion.AbpPro .AddJwtBearer(options => { options.TokenValidationParameters = - new Microsoft.IdentityModel.Tokens.TokenValidationParameters() + new TokenValidationParameters() { // 是否开启签名认证 ValidateIssuerSigningKey = true, @@ -232,7 +230,7 @@ namespace Lion.AbpPro var accessToken = currentContext.Request.Query["access_token"].FirstOrDefault() ?? currentContext.Request.Cookies[ - AbpProHttpApiHostConsts.DefaultCookieName]; + AbpProHttpApiHostConst.DefaultCookieName]; if (accessToken.IsNullOrWhiteSpace()) { @@ -289,7 +287,7 @@ namespace Lion.AbpPro } - private void ConfigurationStsHttpClient(ServiceConfigurationContext context) + private void ConfigureHttpClient(ServiceConfigurationContext context) { context.Services.AddHttpClient(context.Services.GetConfiguration().GetSection("HttpClient:Sts:Name").Value, options => @@ -322,17 +320,16 @@ namespace Lion.AbpPro { context.Services.Configure(options => { options.Lockout = new LockoutOptions() { AllowedForNewUsers = false }; }); } - private void ConfigureConventionalControllers() - { - Configure(options => - { - options.ConventionalControllers.Create(typeof(AbpProApplicationModule) - .Assembly); - }); - } - private static void ConfigureSwaggerServices(ServiceConfigurationContext context, - IConfiguration configuration) + // private void ConfigureConventionalControllers() + // { + // Configure(options => + // { + // options.ConventionalControllers.Create(typeof(AbpProApplicationModule).Assembly); + // }); + // } + + private static void ConfigureSwaggerServices(ServiceConfigurationContext context) { context.Services.AddSwaggerGen( options => @@ -347,8 +344,8 @@ namespace Lion.AbpPro options.DocumentFilter(); options.SchemaFilter(); // 加载所有xml注释,这里会导致swagger加载有点缓慢 - var xmls = Directory.GetFiles(AppContext.BaseDirectory, "*.xml"); - foreach (var xml in xmls) + var xmlPaths = Directory.GetFiles(AppContext.BaseDirectory, "*.xml"); + foreach (var xml in xmlPaths) { options.IncludeXmlComments(xml, true); } @@ -382,7 +379,7 @@ namespace Lion.AbpPro Type = SecuritySchemeType.ApiKey, In = ParameterLocation.Header, Name = "Accept-Language", - Description = "多语言设置,系统预设语言有zh-Hans、en,默认为zh-Hans" + Description = "多语言设置,系统预设语言有zh-Hans、en,默认为zh-Hans", }); options.AddSecurityRequirement(new OpenApiSecurityRequirement @@ -393,17 +390,17 @@ namespace Lion.AbpPro Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "ApiKey" } }, - new string[] { } + Array.Empty() } }); }); } - private void ConfigurationCap(ServiceConfigurationContext context) + private void ConfigureCap(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - var enabled = configuration.GetValue("Cap:Enabled", false); + var enabled = configuration.GetValue("Cap:Enabled", false); if (enabled) { context.AddAbpCap(capOptions => diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/AutoDeleteAfterSuccessAttributer.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/AutoDeleteAfterSuccessAttributer.cs index 12c7e988..e961e364 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/AutoDeleteAfterSuccessAttributer.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/AutoDeleteAfterSuccessAttributer.cs @@ -3,7 +3,7 @@ using Hangfire.Common; using Hangfire.States; using Hangfire.Storage; -namespace Lion.AbpPro.Extensions.Filters; +namespace Lion.AbpPro.Extensions.Hangfire; public class AutoDeleteAfterSuccessAttributer : JobFilterAttribute, IApplyStateFilter { diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CronType.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CronType.cs index 51c72a61..a19ca4e6 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CronType.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CronType.cs @@ -1,7 +1,7 @@ using System; using Hangfire; -namespace Lion.AbpPro.Jobs +namespace Lion.AbpPro.Extensions.Hangfire { /// /// Cron类型 diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CustomHangfireAuthorizeFilter.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CustomHangfireAuthorizeFilter.cs index 91641f65..801f7fcb 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CustomHangfireAuthorizeFilter.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/CustomHangfireAuthorizeFilter.cs @@ -2,7 +2,7 @@ using Hangfire.Dashboard; using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Users; -namespace Lion.AbpPro.Extensions.Filters +namespace Lion.AbpPro.Extensions.Hangfire { public class CustomHangfireAuthorizeFilter : IDashboardAuthorizationFilter { diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/JobRetryLastFilter.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/JobRetryLastFilter.cs index 03c4f60b..f46c1a8d 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/JobRetryLastFilter.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/JobRetryLastFilter.cs @@ -19,7 +19,7 @@ public class JobRetryLastFilter : JobFilterAttribute, IElectStateFilter public void OnStateElection(ElectStateContext context) { - int retryAttempt = context.GetJobParameter("RetryCount"); + var retryAttempt = context.GetJobParameter("RetryCount"); if (RetryCount == retryAttempt) { Log.Error("最后一次重试"); diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs index dd3ef677..f076ac63 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/MVC/Filters/ResultExceptionFilter.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Lion.AbpPro.Extension.Customs.Dtos; -using Lion.AbpPro.Shared.Hosting.Microservices.System; +using Lion.AbpPro.Extensions.System; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; @@ -23,7 +23,7 @@ using Volo.Abp.Validation; namespace Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filters { - public class ResultExceptionFilter : IFilterMetadata, IAsyncExceptionFilter, ITransientDependency + public sealed class ResultExceptionFilter : IFilterMetadata, IAsyncExceptionFilter, ITransientDependency { private ILogger Logger { get; set; } @@ -56,7 +56,7 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filt await HandleAndWrapException(context); } - protected virtual bool ShouldHandleException(ExceptionContext context) + private bool ShouldHandleException(ExceptionContext context) { if (context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.GetCustomAttributes(typeof(WrapResultAttribute), true).Any()) { @@ -71,7 +71,7 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filt return false; } - protected virtual async Task HandleAndWrapException(ExceptionContext context) + private async Task HandleAndWrapException(ExceptionContext context) { //TODO: Trigger an AbpExceptionHandled event or something like that. @@ -108,21 +108,20 @@ namespace Lion.AbpPro.Shared.Hosting.Microservices.Microsoft.AspNetCore.MVC.Filt private string SimplifyMessage(Exception error) { - string message = string.Empty; switch (error) { case AbpAuthorizationException e: - return message = "Authenticate failure!"; + return "Authenticate failure!"; case AbpValidationException e: - return message = "Request param validate failure!"; + return "Request param validate failure!"; case EntityNotFoundException e: - return message = "not found the entity!"; + return "not found the entity!"; case BusinessException e: - return message = $"{e.Message}"; + return $"{e.Message}"; case NotImplementedException e: - return message = "not implement!"; + return "not implement!"; default: - return message = "server internal error!"; + return "server internal error!"; } } } diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/AbpProApplicationBuilderExtensionsExtensions.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/AbpProApplicationBuilderExtensionsExtensions.cs new file mode 100644 index 00000000..370a65bb --- /dev/null +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/AbpProApplicationBuilderExtensionsExtensions.cs @@ -0,0 +1,15 @@ +using Lion.AbpPro.Extensions.Middlewares; + +namespace Microsoft.AspNetCore.Builder; + +public static class AbpProApplicationBuilderExtensionsExtensions +{ + /// + /// 记录请求响应日志 + /// + /// + public static IApplicationBuilder UseRequestLog(this IApplicationBuilder app) + { + return app.UseMiddleware(); + } +} \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/RequestLogMiddleware.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/RequestLogMiddleware.cs new file mode 100644 index 00000000..780f43ad --- /dev/null +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Middlewares/RequestLogMiddleware.cs @@ -0,0 +1,84 @@ +using System; +using System.IO; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; + +namespace Lion.AbpPro.Extensions.Middlewares; + +public class RequestLogMiddleware +{ + private readonly RequestDelegate _next; + private readonly ILogger _logger; + + public RequestLogMiddleware(RequestDelegate next, + ILogger logger) + { + _next = next; + _logger = logger; + } + + public async Task InvokeAsync(HttpContext context) + { + context.Request.EnableBuffering(); + var originalBody = context.Response.Body; + if (context.Request.Path.ToString().ToLower().Contains("swagger") + || context.Request.Path.ToString().ToLower().Contains("login") + || context.Request.Path.ToString().ToLower().Contains("monitor") + || context.Request.Path.ToString().ToLower().Contains("cap") + || context.Request.Path.ToString().ToLower().Contains("hangfire") + || context.Request.Path.ToString() == "/" + ) + { + await _next(context); + } + else + { + try + { + var logRequestId = Guid.NewGuid().ToString(); + await RequestDataLog(context, logRequestId); + using (var ms = new MemoryStream()) + { + context.Response.Body = ms; + await _next(context); + ResponseDataLog(ms, logRequestId); + ms.Position = 0; + await ms.CopyToAsync(originalBody); + } + } + catch (Exception ex) + { + // 记录异常 + _logger.LogError(ex.Message + "" + ex.InnerException); + } + finally + { + context.Response.Body = originalBody; + } + } + } + + private async Task RequestDataLog(HttpContext context, + string requestId) + { + var request = context.Request; + var body = new StreamReader(request.Body); + var requestData = $" 请求路径:{request.Path}\r\n 请求Body参数:{await body.ReadToEndAsync()}"; + _logger.LogInformation($"日志中间件[Request],LogRequestId:{requestId}:请求接口信息:{requestData}"); + request.Body.Position = 0; + } + + private void ResponseDataLog(MemoryStream ms, string requestId) + { + ms.Position = 0; + var responseBody = new StreamReader(ms).ReadToEnd(); + // 去除 Html + var isHtml = Regex.IsMatch(responseBody, "<[^>]+>"); + if (!isHtml && !string.IsNullOrEmpty(responseBody)) + { + _logger.LogInformation($"日志中间件[Response],LogRequestId:{requestId}:响应接口信息:{responseBody}"); + } + } +} \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/RecurringJobsExtensions.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/RecurringJobsExtensions.cs index a6cf0f75..f8d71897 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/RecurringJobsExtensions.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/RecurringJobsExtensions.cs @@ -1,8 +1,10 @@ using Hangfire; +using Lion.AbpPro.Extensions.Hangfire; +using Lion.AbpPro.Jobs; using Microsoft.Extensions.DependencyInjection; using Volo.Abp; -namespace Lion.AbpPro.Jobs +namespace Lion.AbpPro.Extensions { public static class RecurringJobsExtensions { diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/WrapResultAttribute.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/WrapResultAttribute.cs index dd441526..f9c2e50f 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/WrapResultAttribute.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/System/WrapResultAttribute.cs @@ -1,6 +1,6 @@ using System; -namespace Lion.AbpPro.Shared.Hosting.Microservices.System +namespace Lion.AbpPro.Extensions.System { public class WrapResultAttribute : Attribute { diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs index 8bddc9e7..5e855727 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Login.cshtml.cs @@ -58,7 +58,7 @@ namespace Lion.AbpPro.Pages var result = await _accountAppService.LoginAsync(new LoginInput() { Name = userName, Password = password }); - Response.Cookies.Append(AbpProHttpApiHostConsts.DefaultCookieName, + Response.Cookies.Append(AbpProHttpApiHostConst.DefaultCookieName, result.Token, options); } catch (Exception e) diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml index b0000fb9..f7bd18b1 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Pages/Monitor.cshtml @@ -27,12 +27,12 @@
@@ -40,12 +40,12 @@
@@ -53,36 +53,36 @@
diff --git a/aspnet-core/services/src/Lion.AbpPro.Application/AbpProApplicationModule.cs b/aspnet-core/services/src/Lion.AbpPro.Application/AbpProApplicationModule.cs index a3616b37..5f058bce 100644 --- a/aspnet-core/services/src/Lion.AbpPro.Application/AbpProApplicationModule.cs +++ b/aspnet-core/services/src/Lion.AbpPro.Application/AbpProApplicationModule.cs @@ -1,6 +1,6 @@ using Lion.AbpPro.DataDictionaryManagement; using Lion.AbpPro.FileManagement; -using Lion.AbpPro.FreeSqlReppsitory; +using Lion.AbpPro.FreeSqlRepository; using Lion.AbpPro.NotificationManagement; using Volo.Abp.Account; using Volo.Abp.AuditLogging; diff --git a/aspnet-core/services/src/Lion.AbpPro.Application/Lion.AbpPro.Application.csproj b/aspnet-core/services/src/Lion.AbpPro.Application/Lion.AbpPro.Application.csproj index d75bfccb..4c32b960 100644 --- a/aspnet-core/services/src/Lion.AbpPro.Application/Lion.AbpPro.Application.csproj +++ b/aspnet-core/services/src/Lion.AbpPro.Application/Lion.AbpPro.Application.csproj @@ -12,7 +12,7 @@ - + diff --git a/aspnet-core/services/src/Lion.AbpPro.Domain.Shared/Users/Dto/UserOutput.cs b/aspnet-core/services/src/Lion.AbpPro.Domain.Shared/Users/Dto/UserOutput.cs new file mode 100644 index 00000000..30603a4c --- /dev/null +++ b/aspnet-core/services/src/Lion.AbpPro.Domain.Shared/Users/Dto/UserOutput.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lion.AbpPro.Users.Dto +{ + public class UserOutput + { + public Guid Id { get; set; } + } +} diff --git a/aspnet-core/services/src/Lion.AbpPro.Domain/Users/IUserFreeSqlBasicRepository.cs b/aspnet-core/services/src/Lion.AbpPro.Domain/Users/IUserFreeSqlBasicRepository.cs new file mode 100644 index 00000000..9c7179ce --- /dev/null +++ b/aspnet-core/services/src/Lion.AbpPro.Domain/Users/IUserFreeSqlBasicRepository.cs @@ -0,0 +1,14 @@ +using Lion.AbpPro.Users.Dto; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lion.AbpPro.Users +{ + public interface IUserFreeSqlBasicRepository + { + Task> GetListAsync(); + } +} diff --git a/aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/AbpProFreeSqlModule.cs b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/AbpProFreeSqlModule.cs similarity index 92% rename from aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/AbpProFreeSqlModule.cs rename to aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/AbpProFreeSqlModule.cs index aeb1f7c3..7f191ad9 100644 --- a/aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/AbpProFreeSqlModule.cs +++ b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/AbpProFreeSqlModule.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; -namespace Lion.AbpPro.FreeSqlReppsitory; +namespace Lion.AbpPro.FreeSqlRepository; public class AbpProFreeSqlModule : AbpModule { @@ -13,7 +13,7 @@ public class AbpProFreeSqlModule : AbpModule var freeSql = new FreeSql.FreeSqlBuilder() .UseConnectionString(FreeSql.DataType.MySql, connectionString) .Build(); - + context.Services.AddSingleton(freeSql); } } \ No newline at end of file diff --git a/aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/FreeSqlBasicRepository.cs b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/FreeSqlBasicRepository.cs similarity index 93% rename from aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/FreeSqlBasicRepository.cs rename to aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/FreeSqlBasicRepository.cs index 2ed04944..0e5fc9db 100644 --- a/aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/FreeSqlBasicRepository.cs +++ b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/FreeSqlBasicRepository.cs @@ -1,7 +1,7 @@ using Volo.Abp.Domain.Services; using Volo.Abp.Threading; -namespace Lion.AbpPro.FreeSqlReppsitory; +namespace Lion.AbpPro.FreeSqlRepository; public abstract class FreeSqlBasicRepository : DomainService { diff --git a/aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/Lion.AbpPro.FreeSqlReppsitory.csproj b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/Lion.AbpPro.FreeSqlRepository.csproj similarity index 100% rename from aspnet-core/services/src/Lion.AbpPro.FreeSqlReppsitory/Lion.AbpPro.FreeSqlReppsitory.csproj rename to aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/Lion.AbpPro.FreeSqlRepository.csproj diff --git a/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/UserFreeSqlBasicRepository.cs b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/UserFreeSqlBasicRepository.cs new file mode 100644 index 00000000..d245872b --- /dev/null +++ b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/UserFreeSqlBasicRepository.cs @@ -0,0 +1,17 @@ +using Lion.AbpPro.Users; +using Lion.AbpPro.Users.Dto; + +namespace Lion.AbpPro.FreeSqlRepository +{ + public class UserFreeSqlBasicRepository : FreeSqlBasicRepository, IUserFreeSqlBasicRepository + { + public async Task> GetListAsync() + { + var sql = "select id from AbpUsers"; + var result = await FreeSql.Select() + .WithSql(sql) + .ToListAsync(); + return result; + } + } +} diff --git a/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestBase.cs b/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestBase.cs new file mode 100644 index 00000000..8af1ddb4 --- /dev/null +++ b/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestBase.cs @@ -0,0 +1,13 @@ +using Lion.AbpPro.FreeSqlReppsitory.Tests; +using Lion.AbpPro.Localization; + +namespace Lion.AbpPro.FreeSqlRepository.Tests +{ + public abstract class AbpProFreeSqlRepositoryTestBase: AbpProTestBase + { + protected AbpProFreeSqlRepositoryTestBase() + { + ServiceProvider.InitializeLocalization(); + } + } +} diff --git a/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestModule.cs b/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestModule.cs new file mode 100644 index 00000000..dc65b4f6 --- /dev/null +++ b/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/AbpProFreeSqlRepositoryTestModule.cs @@ -0,0 +1,78 @@ +using System; +using System.Linq; +using Lion.AbpPro.EntityFrameworkCore; +using Lion.AbpPro.FreeSqlRepository; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore.Sqlite; +using Volo.Abp.Modularity; + +namespace Lion.AbpPro.FreeSqlReppsitory.Tests; + +[DependsOn( + typeof(AbpProTestBaseModule), + typeof(AbpProEntityFrameworkCoreTestModule), + typeof(AbpProFreeSqlModule) +)] +public class AbpProFreeSqlRepositoryTestModule : AbpModule +{ + private const string ConnectionString = "Data Source=:memory:"; + private SqliteConnection _sqliteConnection; + + public override void ConfigureServices(ServiceConfigurationContext context) + { + + var freeSql = new FreeSql.FreeSqlBuilder() + .UseConnectionString(FreeSql.DataType.Sqlite, ConnectionString) + .UseAutoSyncStructure(true) + .Build(); + context.Services.AddSingleton(freeSql); + var connection = new SqliteConnection(ConnectionString); + ConfigureInMemorySqlite(context.Services, freeSql); + } + + + private void ConfigureInMemorySqlite(IServiceCollection services, IFreeSql freeSql) + { + _sqliteConnection = CreateDatabaseAndGetConnection(freeSql); + + //services.Configure(options => + //{ + // options.PreConfigure(options => { options.DbContextOptions.UseBatchEF_Sqlite(); }); + // options.Configure(context => { context.DbContextOptions.UseSqlite(_sqliteConnection); }); + //}); + } + + public override void OnApplicationShutdown(ApplicationShutdownContext context) + { + // _sqliteConnection.Dispose(); + } + + private static SqliteConnection CreateDatabaseAndGetConnection(IFreeSql freeSql) + { + var connection = new SqliteConnection(ConnectionString); + //connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new AbpProDbContext(options)) + { + foreach (var entityType in context.Model.GetEntityTypes()) + { + freeSql.CodeFirst.SyncStructure(entityType.ClrType, entityType.GetTableName(), true); + } + + //context.GetService().CreateTables(); + } + + return connection; + } +} \ No newline at end of file diff --git a/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Lion.AbpPro.FreeSqlRepository.Tests.csproj b/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Lion.AbpPro.FreeSqlRepository.Tests.csproj new file mode 100644 index 00000000..dabe9e51 --- /dev/null +++ b/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Lion.AbpPro.FreeSqlRepository.Tests.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + + false + + Lion.AbpPro.FreeSqlRepository.Tests + + + + + + + + + + + + + + + + diff --git a/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Users/UserFreeSqlBasicRepository_Tests.cs b/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Users/UserFreeSqlBasicRepository_Tests.cs new file mode 100644 index 00000000..c0bea6af --- /dev/null +++ b/aspnet-core/services/test/Lion.AbpPro.FreeSqlRepository.Tests/Users/UserFreeSqlBasicRepository_Tests.cs @@ -0,0 +1,26 @@ +using System.Threading.Tasks; +using Lion.AbpPro.Users; +using Shouldly; +using Xunit; + +namespace Lion.AbpPro.FreeSqlRepository.Tests.Users +{ + + + public class UserFreeSqlBasicRepository_Tests: AbpProFreeSqlRepositoryTestBase + { + private readonly IUserFreeSqlBasicRepository _userFreeSqlBasicRepository; + public UserFreeSqlBasicRepository_Tests() + { + _userFreeSqlBasicRepository = GetRequiredService(); + } + + [Fact] + public async Task Should_NotThrow_ListAsyncTest() + { + var result = await _userFreeSqlBasicRepository.GetListAsync(); + result.ShouldNotBeNull(); + } + } + +} diff --git a/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestBase.cs b/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestBase.cs new file mode 100644 index 00000000..9b8c4455 --- /dev/null +++ b/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestBase.cs @@ -0,0 +1,18 @@ +using Lion.AbpPro.FreeSqlReppsitory.Tests; +using Lion.AbpPro.Localization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lion.AbpPro +{ + public abstract class AbpProFreeSqlRepositoryTestBase: AbpProTestBase + { + public AbpProFreeSqlRepositoryTestBase() + { + ServiceProvider.InitializeLocalization(); + } + } +} diff --git a/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestModule.cs b/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestModule.cs new file mode 100644 index 00000000..848910b6 --- /dev/null +++ b/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/AbpProFreeSqlRepositoryTestModule.cs @@ -0,0 +1,30 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Lion.AbpPro.FreeSqlReppsitory.Tests; + +[DependsOn( + typeof(AbpProTestBaseModule), + typeof(AbpProFreeSqlModule) + )] + +public class AbpProFreeSqlRepositoryTestModule: AbpModule +{ + + //public override void ConfigureServices(ServiceConfigurationContext context) + //{ + + + + // var configuration = context.Services.GetConfiguration(); + // var connectionString = configuration.GetConnectionString("Default"); + // var freeSql = new FreeSql.FreeSqlBuilder() + // .UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\document.db;Pooling=true;Max Pool Size=10") + // .UseAutoSyncStructure(true) + // .Build(); + + // context.Services.AddSingleton(freeSql); + //} + +} \ No newline at end of file diff --git a/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Lion.AbpPro.FreeSqlReppsitory.Tests.csproj b/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Lion.AbpPro.FreeSqlReppsitory.Tests.csproj new file mode 100644 index 00000000..752d23e1 --- /dev/null +++ b/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Lion.AbpPro.FreeSqlReppsitory.Tests.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + Lion.AbpPro + false + + + + + + + diff --git a/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Users/UserFreeSqlBasicRepository_Tests.cs b/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Users/UserFreeSqlBasicRepository_Tests.cs new file mode 100644 index 00000000..64ae6f45 --- /dev/null +++ b/aspnet-core/services/test/Lion.AbpPro.FreeSqlReppsitory.Tests1/Users/UserFreeSqlBasicRepository_Tests.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Shouldly; +using Xunit; + +namespace Lion.AbpPro.Users +{ + + + public class UserFreeSqlBasicRepository_Tests: AbpProFreeSqlRepositoryTestBase + { + //private readonly IUserFreeSqlBasicRepository _userFreeSqlBasicRepository; + //public UserFreeSqlBasicRepositoryTest() + //{ + // _userFreeSqlBasicRepository = GetRequiredService(); + //} + + [Fact] + public void Should_NotThrow_ListAsyncTest() + { + //var result = await _userFreeSqlBasicRepository.GetListAsync(); + var s = 1; + } + } + +} diff --git a/aspnet-core/services/test/Lion.AbpPro.TestBase/AbpProTestBaseModule.cs b/aspnet-core/services/test/Lion.AbpPro.TestBase/AbpProTestBaseModule.cs index 05833854..88a4ddd3 100644 --- a/aspnet-core/services/test/Lion.AbpPro.TestBase/AbpProTestBaseModule.cs +++ b/aspnet-core/services/test/Lion.AbpPro.TestBase/AbpProTestBaseModule.cs @@ -43,7 +43,7 @@ namespace Lion.AbpPro public override void OnApplicationInitialization(ApplicationInitializationContext context) { - SeedTestData(context); + //SeedTestData(context); } private static void SeedTestData(ApplicationInitializationContext context)