modbus字节序解析bug修复

zw
rszn 4 months ago
parent 5ff587d8f4
commit fdda7dd5f3

@ -0,0 +1,43 @@
using HybirdFrameworkCore.Entity;
using log4net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace WebStarter.MyFilter;
public class RequestFilter : Attribute, IActionFilter, IExceptionFilter, IResultFilter
{
private static readonly ILog Log = LogManager.GetLogger(typeof(RequestFilter));
public void OnActionExecuting(ActionExecutingContext context)
{
Log.Info($"OnActionExecuting {context.HttpContext.Request.Path}");
}
public void OnActionExecuted(ActionExecutedContext context)
{
Log.Info($"OnActionExecuted {context.HttpContext.Request.Path}, result = {context.Result}");
}
public void OnException(ExceptionContext context)
{
Log.Error($"{context.Exception.StackTrace}");
if (!context.ExceptionHandled)
{
context.ExceptionHandled = true;
Result<string> result = Result<string>.Fail("系统异常");
context.Result = new ObjectResult(result)
{
StatusCode = StatusCodes.Status500InternalServerError
};
}
}
public void OnResultExecuting(ResultExecutingContext context)
{
}
public void OnResultExecuted(ResultExecutedContext context)
{
}
}

@ -19,6 +19,7 @@ using Service.Plc.Client;
using Service.RealTime; using Service.RealTime;
using SqlSugar; using SqlSugar;
using SqlSugar.IOC; using SqlSugar.IOC;
using WebStarter.MyFilter;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
var log = LogManager.GetLogger(typeof(Program)); var log = LogManager.GetLogger(typeof(Program));
@ -85,7 +86,10 @@ builder.Services.AddControllers().AddJsonOptions(configure =>
// configure.JsonSerializerOptions.Converters.Add(new LongJsonConverter()); // configure.JsonSerializerOptions.Converters.Add(new LongJsonConverter());
}); });
builder.Services.AddControllers(); builder.Services.AddControllers(op =>
{
op.Filters.Add<RequestFilter>();
});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();

Loading…
Cancel
Save