Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0e28606e3d | ||
![]() |
6a025ceee5 | ||
![]() |
6b2e53d6dc |
@@ -21,29 +21,36 @@ using System.Logging;
|
||||
using ThingsGateway.FriendlyException;
|
||||
using ThingsGateway.Logging;
|
||||
using ThingsGateway.NewLife.Json.Extension;
|
||||
using ThingsGateway.UnifyResult;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
public class RequestAuditFilter : IAsyncActionFilter
|
||||
public class RequestAuditFilter : IAsyncActionFilter, IOrderedFilter
|
||||
{
|
||||
private const int FilterOrder = -3000;
|
||||
public int Order => FilterOrder;
|
||||
|
||||
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
var timeOperation = Stopwatch.StartNew();
|
||||
var resultContext = await next().ConfigureAwait(false);
|
||||
// 计算接口执行时间
|
||||
timeOperation.Stop();
|
||||
|
||||
var controllerActionDescriptor = (context.ActionDescriptor as ControllerActionDescriptor);
|
||||
// 获取动作方法描述器
|
||||
var actionMethod = controllerActionDescriptor?.MethodInfo;
|
||||
|
||||
|
||||
// 处理 Blazor Server
|
||||
if (actionMethod == null)
|
||||
{
|
||||
_ = await next.Invoke().ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// 排除 WebSocket 请求处理
|
||||
if (context.HttpContext.IsWebSocketRequest())
|
||||
{
|
||||
_ = await next().ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,7 +58,6 @@ public class RequestAuditFilter : IAsyncActionFilter
|
||||
if (actionMethod.IsDefined(typeof(SuppressRequestAuditAttribute), true)
|
||||
|| actionMethod.DeclaringType.IsDefined(typeof(SuppressRequestAuditAttribute), true))
|
||||
{
|
||||
_ = await next().ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,10 +71,7 @@ public class RequestAuditFilter : IAsyncActionFilter
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算接口执行时间
|
||||
var timeOperation = Stopwatch.StartNew();
|
||||
var resultContext = await next().ConfigureAwait(false);
|
||||
timeOperation.Stop();
|
||||
|
||||
|
||||
|
||||
var logData = new RequestAuditData();
|
||||
@@ -88,21 +91,29 @@ public class RequestAuditFilter : IAsyncActionFilter
|
||||
var requestUrl = Uri.UnescapeDataString(httpRequest.GetRequestUrlAddress());
|
||||
logData.RequestUrl = requestUrl;
|
||||
|
||||
|
||||
object returnValue = null;
|
||||
Type finalReturnType;
|
||||
var result = resultContext.Result as IActionResult;
|
||||
var data = result switch
|
||||
// 解析返回值
|
||||
if (UnifyContext.CheckVaildResult(result, out var data))
|
||||
{
|
||||
// 处理内容结果
|
||||
ContentResult content => content.Content,
|
||||
// 处理对象结果
|
||||
ObjectResult obj => obj.Value,
|
||||
// 处理 JSON 对象
|
||||
JsonResult json => json.Value,
|
||||
_ => null,
|
||||
};
|
||||
logData.ReturnInformation = data;
|
||||
|
||||
returnValue = data;
|
||||
finalReturnType = data?.GetType();
|
||||
}
|
||||
// 处理文件类型
|
||||
else if (result is FileResult fresult)
|
||||
{
|
||||
returnValue = new
|
||||
{
|
||||
FileName = fresult.FileDownloadName,
|
||||
fresult.ContentType,
|
||||
Length = fresult is FileContentResult cresult ? (object)cresult.FileContents.Length : null
|
||||
};
|
||||
finalReturnType = fresult?.GetType();
|
||||
}
|
||||
else finalReturnType = result?.GetType();
|
||||
|
||||
logData.ReturnInformation = returnValue;
|
||||
|
||||
//获取客户端信息
|
||||
var client = App.GetService<IAppService>().UserAgent;
|
||||
|
@@ -16,7 +16,6 @@ using ThingsGateway.Extension;
|
||||
using ThingsGateway.FriendlyException;
|
||||
using ThingsGateway.Logging;
|
||||
using ThingsGateway.NewLife.Json.Extension;
|
||||
using ThingsGateway.Razor;
|
||||
|
||||
namespace ThingsGateway.Admin.Application;
|
||||
|
||||
@@ -160,8 +159,7 @@ public class DatabaseLoggingWriter : IDatabaseLoggingWriter
|
||||
if (path == "/api/auth/login")
|
||||
{
|
||||
//如果是登录,用户信息就从返回值里拿
|
||||
var result = requestAuditData.ReturnInformation?.ToSystemTextJsonString();//返回值转json
|
||||
var userInfo = result.FromJsonNetString<UnifyResult<LoginOutput>>();//格式化成user表
|
||||
dynamic userInfo = requestAuditData.ReturnInformation;
|
||||
opAccount = userInfo.Data.Account;//赋值账号
|
||||
verificatId = userInfo.Data.VerificatId;
|
||||
}
|
||||
|
@@ -88,6 +88,7 @@ public class Startup : AppStartup
|
||||
}
|
||||
;
|
||||
|
||||
services.AddMvcFilter<RequestAuditFilter>();
|
||||
services.AddControllers()
|
||||
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
|
||||
//.AddXmlSerializerFormatters()
|
||||
@@ -237,7 +238,6 @@ public class Startup : AppStartup
|
||||
// logContext.Set(LoggingConst.Method, httpContext.Request.Method);//请求方法
|
||||
// });
|
||||
//});
|
||||
services.AddMvcFilter<RequestAuditFilter>();
|
||||
|
||||
//日志写入数据库配置
|
||||
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>
|
||||
|
@@ -349,7 +349,7 @@ public static class UnifyContext
|
||||
/// <param name="result"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
internal static bool CheckVaildResult(IActionResult result, out object data)
|
||||
public static bool CheckVaildResult(IActionResult result, out object data)
|
||||
{
|
||||
data = default;
|
||||
|
||||
|
@@ -37,7 +37,8 @@ public static class SystemTextJsonExtension
|
||||
{
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
WriteIndented = true, // 缩进
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull // 忽略 null
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, // 忽略 null
|
||||
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||
};
|
||||
// 如有自定义Converter,这里添加
|
||||
// IndentedOptions.Converters.Add(new ByteArrayJsonConverter());
|
||||
@@ -50,7 +51,8 @@ public static class SystemTextJsonExtension
|
||||
{
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
WriteIndented = false, // 不缩进
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||
};
|
||||
NoneIndentedOptions.Converters.Add(new ByteArrayToNumberArrayConverterSystemTextJson());
|
||||
NoneIndentedOptions.Converters.Add(new JTokenSystemTextJsonConverter());
|
||||
|
@@ -27,6 +27,13 @@ public class Startup : AppStartup
|
||||
{
|
||||
services.AddBootstrapBlazor(
|
||||
option => option.JSModuleVersion = Random.Shared.Next(10000).ToString()
|
||||
, jsonLocalizationOptions =>
|
||||
{
|
||||
jsonLocalizationOptions.DisableGetLocalizerFromResourceManager = true;
|
||||
jsonLocalizationOptions.DisableGetLocalizerFromService = true;
|
||||
jsonLocalizationOptions.IgnoreLocalizerMissing = true;
|
||||
jsonLocalizationOptions.UseKeyWhenValueIsNull = true;
|
||||
}
|
||||
);
|
||||
services.AddConfigurableOptions<MenuOptions>();
|
||||
services.ConfigureIconThemeOptions(options => options.ThemeKey = "fa");
|
||||
|
@@ -1,8 +1,8 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<PluginVersion>10.6.21</PluginVersion>
|
||||
<ProPluginVersion>10.6.21</ProPluginVersion>
|
||||
<PluginVersion>10.6.23</PluginVersion>
|
||||
<ProPluginVersion>10.6.23</ProPluginVersion>
|
||||
<AuthenticationVersion>2.1.7</AuthenticationVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@@ -90,6 +90,7 @@ public class RuntimeInfoController : ControllerBase
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("checkRealAlarm")]
|
||||
[RequestAudit]
|
||||
[DisplayName("确认实时报警")]
|
||||
public async Task CheckRealAlarm(long variableId)
|
||||
{
|
||||
|
@@ -1299,7 +1299,6 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
|
||||
try
|
||||
{
|
||||
if (Disposed) return;
|
||||
await Task.Delay(1000);
|
||||
await OnClickSearch(SearchText);
|
||||
|
||||
Value = GetValue(Value);
|
||||
@@ -1311,6 +1310,7 @@ EventCallback.Factory.Create<MouseEventArgs>(this, async e =>
|
||||
}
|
||||
finally
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
_isExecuting = false;
|
||||
}
|
||||
}
|
||||
|
@@ -357,7 +357,7 @@ public partial class OpcUaServer : BusinessBase
|
||||
{
|
||||
StoreType = CertificateStoreType.X509Store,
|
||||
StorePath = "CurrentUser\\UAServer_ThingsGateway",
|
||||
SubjectName = _driverPropertys.BigTextSubjectName,
|
||||
SubjectName = $"{_driverPropertys.BigTextSubjectName}{_driverPropertys.OpcUaStringUrl}",
|
||||
//ValidationOptions = CertificateValidationOptions.SuppressHostNameInvalid,
|
||||
},
|
||||
|
||||
|
@@ -109,6 +109,7 @@ public class Startup : AppStartup
|
||||
// setting.Converters.Add(new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }); // 解决DateTimeOffset异常
|
||||
}
|
||||
;
|
||||
services.AddMvcFilter<RequestAuditFilter>();
|
||||
|
||||
services.AddControllers()
|
||||
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
|
||||
@@ -215,7 +216,6 @@ public class Startup : AppStartup
|
||||
// });
|
||||
//});
|
||||
|
||||
services.AddMvcFilter<RequestAuditFilter>();
|
||||
|
||||
//日志写入数据库配置
|
||||
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>
|
||||
|
@@ -88,6 +88,8 @@ public class Startup : AppStartup
|
||||
}
|
||||
;
|
||||
|
||||
services.AddMvcFilter<RequestAuditFilter>();
|
||||
|
||||
services.AddControllers()
|
||||
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
|
||||
//.AddXmlSerializerFormatters()
|
||||
@@ -237,7 +239,6 @@ public class Startup : AppStartup
|
||||
// logContext.Set(LoggingConst.Method, httpContext.Request.Method);//请求方法
|
||||
// });
|
||||
//});
|
||||
services.AddMvcFilter<RequestAuditFilter>();
|
||||
|
||||
//日志写入数据库配置
|
||||
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>
|
||||
|
@@ -83,6 +83,7 @@ public class Startup : AppStartup
|
||||
// setting.Converters.Add(new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }); // 解决DateTimeOffset异常
|
||||
}
|
||||
;
|
||||
services.AddMvcFilter<RequestAuditFilter>();
|
||||
|
||||
services.AddControllers()
|
||||
.AddNewtonsoftJson(options => SetNewtonsoftJsonSetting(options.SerializerSettings))
|
||||
@@ -233,7 +234,6 @@ public class Startup : AppStartup
|
||||
// logContext.Set(LoggingConst.Method, httpContext.Request.Method);//请求方法
|
||||
// });
|
||||
//});
|
||||
services.AddMvcFilter<RequestAuditFilter>();
|
||||
|
||||
//日志写入数据库配置
|
||||
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>10.6.21</Version>
|
||||
<Version>10.6.23</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user