Add request.References to InsertResultCommand in both PreprocessingBehavior and PostprocessingBehavior, ensuring references are recorded with both success and error results.
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using MediatR;
|
|
using ReC.Application.Common.Exceptions;
|
|
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.InvokeAction;
|
|
|
|
public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, Unit>
|
|
{
|
|
public async Task<Unit> Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
|
|
{
|
|
try
|
|
{
|
|
if (request.Action.PreprocessingQuery is string query)
|
|
{
|
|
var result = await context.ExecuteDynamicSqlAsync(query, cancel);
|
|
|
|
await sender.Send(new InsertResultCommand()
|
|
{
|
|
Status = RecStatus.OK,
|
|
ActionId = request.Action.Id,
|
|
InfoDetail = JsonSerializer.Serialize(result),
|
|
Type = ResultType.Pre,
|
|
References = request.References
|
|
}, cancel);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await sender.Send(new InsertResultCommand()
|
|
{
|
|
Status = RecStatus.Error,
|
|
ActionId = request.Action.Id,
|
|
Error = ex.ToString(),
|
|
Type = ResultType.Pre,
|
|
References = request.References
|
|
}, cancel);
|
|
|
|
if (request.Action.ErrorAction == ErrorAction.Stop)
|
|
throw new RecActionException(request.Action.Id, request.Action.ProfileId, ex);
|
|
}
|
|
|
|
return await next(cancel);
|
|
}
|
|
} |