Merge branch 'framework' of https://gitee.com/ccnetcore/Yi into framework

This commit is contained in:
橙子
2023-02-10 19:49:31 +08:00
20 changed files with 120 additions and 41 deletions

View File

@@ -12,23 +12,18 @@ using System.Threading.Tasks;
using Yi.Framework.Core.Const;
using Yi.Framework.Core.CurrentUsers;
namespace Yi.Framework.Core.Extensions
namespace Microsoft.AspNetCore.Builder
{
public static class CurrentUserExtensions
public static class CurrentUserUseExtensions
{
public static IServiceCollection AddCurrentUserServer(this IServiceCollection services)
{
return services.AddScoped<ICurrentUser, CurrentUser>();
}
public static IApplicationBuilder UseCurrentUserServer(this IApplicationBuilder app)
{
return app.UseMiddleware<CurrentUserMiddleware>();
}
}
}
public class CurrentUserMiddleware
{

View File

@@ -9,7 +9,7 @@ using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Exceptions;
namespace Yi.Framework.Core.Extensions
namespace Microsoft.AspNetCore.Builder
{
internal class ExceptionModle

View File

@@ -27,7 +27,8 @@ namespace AspNetCore.Microsoft.AspNetCore.Builder
{
foreach (var k in swaggerModels)
{
c.SwaggerEndpoint(k.url, k.name);
c.SwaggerEndpoint(k.Url, k.Name);
}
}
@@ -38,12 +39,17 @@ namespace AspNetCore.Microsoft.AspNetCore.Builder
}
public class SwaggerModel
{
public SwaggerModel(string name)
{
this.Name = name;
this.Url = "/swagger/v1/swagger.json";
}
public SwaggerModel(string url, string name)
{
this.url = url;
this.name = name;
this.Url = url;
this.Name = name;
}
public string url { get; set; }
public string name { get; set; }
public string Url { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Core.Const;
using Yi.Framework.Core.CurrentUsers;
namespace Microsoft.Extensions.DependencyInjection
{
public static class CurrentUserAddExtensions
{
public static IServiceCollection AddCurrentUserServer(this IServiceCollection services)
{
return services.AddScoped<ICurrentUser, CurrentUser>();
}
}
}

View File

@@ -18,4 +18,8 @@
<Folder Include="Microsoft\Extensions\Hosting\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using StartupModules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.AspNetCore
{
public class YiFrameworkAspNetCoreModule : IStartupModule
{
public void Configure(IApplicationBuilder app, ConfigureMiddlewareContext context)
{
app.UseCurrentUserServer();
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
{
services.AddCurrentUserServer();
}
}
}

View File

@@ -95,19 +95,16 @@ namespace Yi.Framework.Core.Sqlsugar.Extensions
};
db.Aop.OnLogExecuting = (s, p) =>
{
if (GobalLogModel.SqlLogEnable)
{
var _logger = ServiceLocatorModel.Instance?.GetRequiredService<ILogger<SqlSugarClient>>();
var _logger = ServiceLocatorModel.Instance?.GetRequiredService<ILogger<SqlSugarClient>>();
StringBuilder sb = new StringBuilder();
sb.Append("执行SQL:" + s.ToString());
foreach (var i in p)
{
sb.Append($"\r\n参数:{i.ParameterName},参数值:{i.Value}");
}
sb.Append($"\r\n 完整SQL{UtilMethods.GetSqlString(DbType.MySql, s, p)}");
_logger?.LogInformation(sb.ToString());
StringBuilder sb = new StringBuilder();
sb.Append("执行SQL:" + s.ToString());
foreach (var i in p)
{
sb.Append($"\r\n参数:{i.ParameterName},参数值:{i.Value}");
}
sb.Append($"\r\n 完整SQL{UtilMethods.GetSqlString(DbType.MySql, s, p)}");
_logger?.LogDebug(sb.ToString());
};
});

View File

@@ -38,6 +38,7 @@ namespace Yi.Framework.Core.Helper
return assembly.GetTypes().Where(m => m.IsClass
&& className == null ? true : m.Name == className
&& spaceName == null ? true : m.Namespace == spaceName
&& !m.Name.StartsWith("<>")
).ToList();
}

View File

@@ -1,4 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Text.Json;
@@ -6,7 +8,14 @@ namespace Yi.Framework.Core.Helper
{
public class JsonHelper
{
public static string ObjToStr<T>(T obj, string dateTimeFormat)
{
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter()
{
DateTimeFormat = dateTimeFormat
};
return Newtonsoft.Json.JsonConvert.SerializeObject(obj, Formatting.Indented, timeConverter);
}
public static string ObjToStr<T>(T obj)
{
@@ -28,7 +37,7 @@ namespace Yi.Framework.Core.Helper
string result = String.Empty;
try
{
JsonSerializer.Serialize("");
System.Text.Json.JsonSerializer.Serialize("");
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer =
new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(T));
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())

View File

@@ -6,10 +6,4 @@ using System.Threading.Tasks;
namespace Yi.Framework.Core.Model
{
public class GobalLogModel
{
public static bool SqlLogEnable { get; set; } = true;
public static bool LoginCodeEnable { get; set; } = true;
}
}

View File

@@ -24,7 +24,7 @@ namespace Yi.Framework.Core
//全局错误,需要靠前,放在此处无效
//app.UseErrorHandlingServer();
app.UseCurrentUserServer();
}
public void ConfigureServices(IServiceCollection services, ConfigureServicesContext context)
@@ -34,10 +34,8 @@ namespace Yi.Framework.Core
//全盘扫描,自动依赖注入
services.AddAutoIocServer();
services.AddCurrentUserServer();
//全局日志
GobalLogModel.SqlLogEnable = Appsettings.appBool("SqlLog_Enable");
GobalLogModel.LoginCodeEnable = Appsettings.appBool("LoginCode_Enable");
}
}
}

View File

@@ -79,7 +79,13 @@ namespace Yi.Framework.Ddd.Services
ReflexHelper.SetModelValue(nameof(IEntity<long>.Id), SnowflakeHelper.NextId, entity);
}
}
if (entity is IEntity<Guid> entityForGuidId)
{
if (entityForGuidId.Id == Guid.Empty)
{
ReflexHelper.SetModelValue(nameof(IEntity<long>.Id), new Guid(), entity);
}
}
return Task.FromResult(entity);
}

View File

@@ -8,10 +8,12 @@ using Yi.BBS.Sqlsugar;
using Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection;
using Yi.Framework.Core.Autofac;
using Yi.RBAC.Application;
using Yi.Framework.AspNetCore;
namespace Yi.BBS.Web
{
[DependsOn(
typeof(YiFrameworkAspNetCoreModule),
typeof(YiFrameworkCoreAutofacModule),
typeof(YiBBSSqlsugarModule),
typeof(YiBBSApplicationModule)

View File

@@ -1,5 +1,6 @@
using AspNetCore.Microsoft.AspNetCore.Builder;
using StartupModules;
using Yi.Framework.AspNetCore;
using Yi.Framework.Auth.JwtBearer;
using Yi.Framework.Core;
using Yi.Framework.Core.Attributes;
@@ -10,6 +11,7 @@ using Yi.Template.Sqlsugar;
namespace Yi.Template.Web
{
[DependsOn(
typeof(YiFrameworkAspNetCoreModule),
typeof(YiFrameworkCoreAutofacModule),
typeof(YiTemplateSqlsugarModule),
typeof(YiTemplateApplicationModule)

View File

@@ -2,6 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
//"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
},

View File

@@ -8,10 +8,12 @@ using Yi.BBS.Sqlsugar;
using Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection;
using Yi.Framework.Core.Autofac;
using Yi.RBAC.Application;
using Yi.Framework.AspNetCore;
namespace Yi.BBS.Web
{
[DependsOn(
typeof(YiFrameworkAspNetCoreModule),
typeof(YiFrameworkCoreAutofacModule),
typeof(YiBBSSqlsugarModule),
typeof(YiBBSApplicationModule)

View File

@@ -1,5 +1,6 @@
using AspNetCore.Microsoft.AspNetCore.Builder;
using StartupModules;
using Yi.Framework.AspNetCore;
using Yi.Framework.Auth.JwtBearer;
using Yi.Framework.Core;
using Yi.Framework.Core.Attributes;
@@ -10,6 +11,7 @@ using Yi.RBAC.Sqlsugar;
namespace Yi.RBAC.Web
{
[DependsOn(
typeof(YiFrameworkAspNetCoreModule),
typeof(YiFrameworkCoreAutofacModule),
typeof(YiRBACSqlsugarModule),
typeof(YiRBACApplicationModule)

View File

@@ -2,6 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
//"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
},

View File

@@ -1,5 +1,6 @@
using AspNetCore.Microsoft.AspNetCore.Builder;
using StartupModules;
using Yi.Framework.AspNetCore;
using Yi.Framework.Auth.JwtBearer;
using Yi.Framework.Core;
using Yi.Framework.Core.Attributes;
@@ -10,6 +11,7 @@ using Yi.Template.Sqlsugar;
namespace Yi.Template.Web
{
[DependsOn(
typeof(YiFrameworkAspNetCoreModule),
typeof(YiFrameworkCoreAutofacModule),
typeof(YiTemplateSqlsugarModule),
typeof(YiTemplateApplicationModule)

View File

@@ -2,6 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
//"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
},