From 9410c5dc0dbd50750a8d223a09facaabb2c18158 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 24 Mar 2026 14:01:45 +0100 Subject: [PATCH] Refactor PreprocessingBehavior to log results and errors Refactored PreprocessingBehavior to serialize and log the results and errors of preprocessing SQL queries using InsertResultCommand. Now records both successful and failed executions, while preserving the stop-on-error behavior. Cleaned up and updated using directives. --- .../Behaviors/Action/PreprocessingBehavior.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ReC.Application/Common/Behaviors/Action/PreprocessingBehavior.cs b/src/ReC.Application/Common/Behaviors/Action/PreprocessingBehavior.cs index 4a20230..c0dc973 100644 --- a/src/ReC.Application/Common/Behaviors/Action/PreprocessingBehavior.cs +++ b/src/ReC.Application/Common/Behaviors/Action/PreprocessingBehavior.cs @@ -1,8 +1,9 @@ -using DigitalData.Core.Abstraction.Application.Repository; -using MediatR; +using MediatR; using ReC.Application.Common.Interfaces; using ReC.Application.RecActions.Commands; +using ReC.Application.Results.Commands; using ReC.Domain.Constants; +using System.Text.Json; namespace ReC.Application.Common.Behaviors.Action; @@ -10,20 +11,31 @@ public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPip { public async Task Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate next, CancellationToken cancel) { + string? info = null, error = null; + try { if (request.Action.PreprocessingQuery is string query) - await context.ExecuteDynamicSqlAsync(query, cancel); + { + var result = await context.ExecuteDynamicSqlAsync(query, cancel); + info = JsonSerializer.Serialize(result); + } } catch (Exception ex) { - if(request.Action.ErrorAction == ErrorAction.Stop) - { - // save output result - return false; - } + error = ex.ToString(); } + await sender.Send(new InsertResultCommand() + { + ActionId = request.Action.Id, + Info = info, + Error = error + }, cancel); + + if (error is not null && request.Action.ErrorAction == ErrorAction.Stop) + return false; + return await next(cancel); } } \ No newline at end of file