降低CPU使用率,处置好因降低CPU使用率带来的颜色偏差
This commit is contained in:
@@ -5,9 +5,16 @@
|
||||
/// </summary>
|
||||
public class SdkGlobal
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否保存摄像头配置
|
||||
/// </summary>
|
||||
/// <summary>是否保存摄像头配置</summary>
|
||||
public static bool SaveCameraConfigEnable { get; set; } = false;
|
||||
|
||||
/// <summary>是否使用 TurboJpegWrapper 降低图片编码开销</summary>
|
||||
public static bool UseTurboJpegWrapper { get; set;} = true;
|
||||
|
||||
/// <summary>禁用 TurboJpegWrapper</summary>
|
||||
public static void DisableTurboJpegAcceleration()
|
||||
{
|
||||
UseTurboJpegWrapper = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
42
SHH.CameraSdk/Core/UserActionFilter.cs
Normal file
42
SHH.CameraSdk/Core/UserActionFilter.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace SHH.CameraSdk;
|
||||
|
||||
/// <summary>
|
||||
/// 全局用户操作过滤器
|
||||
/// 作用:拦截所有 API 请求,记录关键操作(如新增、删除、修改设备)
|
||||
/// 优化:使用依赖注入 (DI) 获取存储服务,避免直接文件 IO 导致的锁冲突
|
||||
/// </summary>
|
||||
public class UserActionFilter : IActionFilter
|
||||
{
|
||||
// 【关键点】构造函数注入
|
||||
// ASP.NET Core 会自动把我们在 Program.cs 中注册的 IStorageService 实例传进来
|
||||
public UserActionFilter()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action 执行【后】触发
|
||||
/// </summary>
|
||||
public void OnActionExecuted(ActionExecutedContext context)
|
||||
{
|
||||
// 1. 获取请求的基本信息
|
||||
var method = context.HttpContext.Request.Method;
|
||||
var path = context.HttpContext.Request.Path;
|
||||
|
||||
// 2. 过滤逻辑:为了防止日志爆炸,我们通常只记录非 GET 请求
|
||||
// (例如:只记录 POST/PUT/DELETE 等修改性操作)
|
||||
if (method != "GET")
|
||||
{
|
||||
var ip = context.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action 执行【前】触发 (此处不需要处理)
|
||||
/// </summary>
|
||||
public void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user