From 3e10176d98409787314881ae599af94c49dd24da Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 24 Mar 2026 11:14:11 +0100 Subject: [PATCH] Add PreprocessingBehavior for action command pipeline Introduced PreprocessingBehavior implementing MediatR's IPipelineBehavior for InvokeRecActionViewCommand. This behavior executes a preprocessing SQL query if specified, and halts processing if an error occurs and ErrorAction is set to Stop. Added necessary using directives for dependencies. --- .../Behaviors/Action/PreprocessingBehavior.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/ReC.Application/Common/Behaviors/Action/PreprocessingBehavior.cs diff --git a/src/ReC.Application/Common/Behaviors/Action/PreprocessingBehavior.cs b/src/ReC.Application/Common/Behaviors/Action/PreprocessingBehavior.cs new file mode 100644 index 0000000..7a18a59 --- /dev/null +++ b/src/ReC.Application/Common/Behaviors/Action/PreprocessingBehavior.cs @@ -0,0 +1,29 @@ +using DigitalData.Core.Abstraction.Application.Repository; +using MediatR; +using ReC.Application.Common.Interfaces; +using ReC.Application.RecActions.Commands; +using ReC.Domain.Constants; + +namespace ReC.Application.Common.Behaviors.Action; + +public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior +{ + public async Task Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate next, CancellationToken cancel) + { + try + { + if (request.Action.PreprocessingQuery is string query) + await context.ExecuteDynamicSqlAsync(query); + } + catch (Exception ex) + { + if(request.Action.ErrorAction == ErrorAction.Stop) + { + // save output result + return false; + } + } + + return await next(cancel); + } +} \ No newline at end of file