Update behavior namespaces to InvokeAction for clarity
Renamed namespaces in PreprocessingBehavior and PostprocessingBehavior from .Action to .InvokeAction, and updated related using directives in DependencyInjection.cs. Added a folder entry for Common\Behaviors\Action\ in the project file for organization.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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 PostprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, Unit>
|
||||
{
|
||||
public async Task<Unit> Handle(InvokeRecActionViewCommand request, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
|
||||
{
|
||||
await next(cancel);
|
||||
|
||||
try
|
||||
{
|
||||
if (request.Action.PostprocessingQuery is string query)
|
||||
{
|
||||
var result = await context.ExecuteDynamicSqlAsync(query, cancel);
|
||||
var info = JsonSerializer.Serialize(result);
|
||||
|
||||
await sender.Send(new InsertResultCommand()
|
||||
{
|
||||
ActionId = request.Action.Id,
|
||||
Info = info,
|
||||
Type = ResultType.Post
|
||||
}, cancel);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var error = ex.ToString();
|
||||
|
||||
await sender.Send(new InsertResultCommand()
|
||||
{
|
||||
ActionId = request.Action.Id,
|
||||
Error = error,
|
||||
Type = ResultType.Post
|
||||
}, cancel);
|
||||
|
||||
if (request.Action.ErrorAction == ErrorAction.Stop)
|
||||
throw new RecActionException(request.Action.Id, request.Action.ProfileId, ex);
|
||||
}
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user