Compare commits
12 Commits
42db5460fc
...
de5e051ec1
| Author | SHA1 | Date | |
|---|---|---|---|
| de5e051ec1 | |||
| 7bdd3906bd | |||
| 49e7f7a45b | |||
| 713e4f2a02 | |||
| 99bdf77ead | |||
| c729cb33e3 | |||
| cad7ca16cb | |||
| 39d1292cc9 | |||
| 8e0ee6fbfa | |||
| 003f4c60f6 | |||
| cb12cfcbc2 | |||
| 4380f17bdb |
@@ -21,12 +21,11 @@ public class RecActionController(IMediator mediator) : ControllerBase
|
|||||||
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||||
public async Task<IActionResult> Invoke([FromRoute] long profileId, [FromBody] InvokeReferences references, CancellationToken cancel = default)
|
public async Task<IActionResult> Invoke([FromRoute] long profileId, [FromBody] InvokeReferences references, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
await mediator.Send(new InvokeBatchRecActionViewsCommand
|
return Ok(await mediator.Send(new InvokeBatchRecActionViewsCommand
|
||||||
{
|
{
|
||||||
ProfileId = profileId,
|
ProfileId = profileId,
|
||||||
References = references
|
References = references
|
||||||
}, cancel);
|
}, cancel));
|
||||||
return Accepted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region CRUD
|
#region CRUD
|
||||||
|
|||||||
@@ -1,27 +1,96 @@
|
|||||||
using Microsoft.AspNetCore.Rewrite;
|
using Microsoft.AspNetCore.Rewrite;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NLog;
|
|
||||||
using NLog.Web;
|
|
||||||
using ReC.API.Middleware;
|
using ReC.API.Middleware;
|
||||||
using ReC.Application;
|
using ReC.Application;
|
||||||
using ReC.Infrastructure;
|
using ReC.Infrastructure;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Ui.Core.Extensions;
|
||||||
|
using Serilog.Ui.SqliteDataProvider.Extensions;
|
||||||
|
using Serilog.Ui.Web.Extensions;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||||
|
|
||||||
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
// Enable Serilog self-diagnostics
|
||||||
logger.Info("Logging initialized!");
|
Serilog.Debugging.SelfLog.Enable(msg => Console.WriteLine($"[SERILOG] {msg}"));
|
||||||
|
|
||||||
|
// Build temporary configuration to read log directory from appsettings.Logging.json
|
||||||
|
var tempConfig = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json", optional: false)
|
||||||
|
.AddJsonFile("appsettings.Logging.json", optional: false)
|
||||||
|
.AddEnvironmentVariables()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var isDevelopment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development";
|
||||||
|
|
||||||
|
var logDirectory = tempConfig.GetValue<string>("Serilog:LogDirectory")
|
||||||
|
?? Path.Combine(AppContext.BaseDirectory, "logs");
|
||||||
|
var retainedFileCountLimit = tempConfig.GetValue("Serilog:RetainedFileCountLimit", 30);
|
||||||
|
|
||||||
|
Directory.CreateDirectory(logDirectory);
|
||||||
|
|
||||||
|
var sqliteDbPath = Path.Combine(logDirectory, "logs.db");
|
||||||
|
var logFilePathTemplate = Path.Combine(logDirectory, ".Rec.API-.log");
|
||||||
|
|
||||||
|
Console.WriteLine($"[INFO] Log Directory: {logDirectory}");
|
||||||
|
|
||||||
|
// Configure Serilog based on environment:
|
||||||
|
// Development : Console + SQLite (+ Web UI)
|
||||||
|
// Production : File (per-level) + SQLite (+ Web UI)
|
||||||
|
var loggerConfig = new LoggerConfiguration()
|
||||||
|
.MinimumLevel.Information()
|
||||||
|
.MinimumLevel.Override("Microsoft.AspNetCore", Serilog.Events.LogEventLevel.Warning)
|
||||||
|
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", Serilog.Events.LogEventLevel.Warning)
|
||||||
|
.Enrich.FromLogContext();
|
||||||
|
|
||||||
|
if (isDevelopment)
|
||||||
|
{
|
||||||
|
loggerConfig.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
loggerConfig
|
||||||
|
.WriteTo.File(
|
||||||
|
Path.Combine(logDirectory, ".Rec.API-Info.log"),
|
||||||
|
rollingInterval: RollingInterval.Day,
|
||||||
|
retainedFileCountLimit: retainedFileCountLimit,
|
||||||
|
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information,
|
||||||
|
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
|
||||||
|
.WriteTo.File(
|
||||||
|
Path.Combine(logDirectory, ".Rec.API-Warning.log"),
|
||||||
|
rollingInterval: RollingInterval.Day,
|
||||||
|
retainedFileCountLimit: retainedFileCountLimit,
|
||||||
|
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Warning,
|
||||||
|
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
|
||||||
|
.WriteTo.File(
|
||||||
|
Path.Combine(logDirectory, ".Rec.API-Error.log"),
|
||||||
|
rollingInterval: RollingInterval.Day,
|
||||||
|
retainedFileCountLimit: retainedFileCountLimit,
|
||||||
|
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Error,
|
||||||
|
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
|
||||||
|
.WriteTo.File(
|
||||||
|
Path.Combine(logDirectory, ".Rec.API-Critical.log"),
|
||||||
|
rollingInterval: RollingInterval.Day,
|
||||||
|
retainedFileCountLimit: retainedFileCountLimit,
|
||||||
|
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Fatal,
|
||||||
|
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// SQLite sink is always active (used by Serilog Web UI)
|
||||||
|
loggerConfig.WriteTo.SQLite(sqliteDbPath, storeTimestampInUtc: true);
|
||||||
|
|
||||||
|
Log.Logger = loggerConfig.CreateLogger();
|
||||||
|
|
||||||
|
Log.Information("Logging initialized!");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Log.Information("Starting ReC.API application");
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
// Use Serilog for logging
|
||||||
|
builder.Host.UseSerilog();
|
||||||
if (!builder.Environment.IsDevelopment())
|
|
||||||
{
|
|
||||||
builder.Logging.ClearProviders();
|
|
||||||
builder.Host.UseNLog();
|
|
||||||
}
|
|
||||||
|
|
||||||
var config = builder.Configuration;
|
var config = builder.Configuration;
|
||||||
|
|
||||||
@@ -71,6 +140,16 @@ try
|
|||||||
c.IncludeXmlComments(xmlPath);
|
c.IncludeXmlComments(xmlPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Serilog Web UI — SQLite provider, same path used by the SQLite sink above
|
||||||
|
builder.Services.AddSerilogUi(logUIOpt =>
|
||||||
|
{
|
||||||
|
logUIOpt.UseSqliteServer(dbOpt =>
|
||||||
|
{
|
||||||
|
dbOpt.WithConnectionString($"Data Source={sqliteDbPath}");
|
||||||
|
dbOpt.WithTable("Logs");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||||
@@ -89,14 +168,21 @@ try
|
|||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
// Serilog Web UI is always active (both Development and Production)
|
||||||
|
app.UseSerilogUi();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.Error(ex, "Stopped program because of exception");
|
Log.Fatal(ex, "Stopped program because of exception");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Log.CloseAndFlush();
|
||||||
|
}
|
||||||
|
|
||||||
public partial class Program;
|
public partial class Program;
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||||
<ExcludeApp_Data>false</ExcludeApp_Data>
|
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||||
<ProjectGuid>420218ad-3c27-4003-9a84-36c92352f175</ProjectGuid>
|
<ProjectGuid>420218ad-3c27-4003-9a84-36c92352f175</ProjectGuid>
|
||||||
<DesktopBuildPackageLocation>M:\App&Service\0 DD - Smart UP\ReC\API\$(Version)\Rec.API.zip</DesktopBuildPackageLocation>
|
<DesktopBuildPackageLocation>M:\App&Service\0 DD - Smart UP\ReC\Release\API\$(Version)\Rec.API.zip</DesktopBuildPackageLocation>
|
||||||
<PackageAsSingleFile>true</PackageAsSingleFile>
|
<PackageAsSingleFile>true</PackageAsSingleFile>
|
||||||
<DeployIisAppPath>Rec.API</DeployIisAppPath>
|
<DeployIisAppPath>Rec.API</DeployIisAppPath>
|
||||||
<_TargetId>IISWebDeployPackage</_TargetId>
|
<_TargetId>IISWebDeployPackage</_TargetId>
|
||||||
|
|||||||
@@ -10,10 +10,10 @@
|
|||||||
<Product>ReC.API</Product>
|
<Product>ReC.API</Product>
|
||||||
<PackageIcon>Assets\icon.ico</PackageIcon>
|
<PackageIcon>Assets\icon.ico</PackageIcon>
|
||||||
<PackageTags>digital data rest-caller rec api</PackageTags>
|
<PackageTags>digital data rest-caller rec api</PackageTags>
|
||||||
<Version>2.4.0-beta</Version>
|
<Version>1.0.0</Version>
|
||||||
<AssemblyVersion>2.4.0.0</AssemblyVersion>
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
<FileVersion>2.4.0.0</FileVersion>
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
<InformationalVersion>2.4.0-beta</InformationalVersion>
|
<InformationalVersion>1.0.0</InformationalVersion>
|
||||||
<Copyright>Copyright © 2025 Digital Data GmbH. All rights reserved.</Copyright>
|
<Copyright>Copyright © 2025 Digital Data GmbH. All rights reserved.</Copyright>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||||
@@ -23,8 +23,13 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.11" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.11" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||||
<PackageReference Include="NLog" Version="5.2.5" />
|
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
|
||||||
<PackageReference Include="NLog.Web.AspNetCore" Version="5.3.0" />
|
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.SQLite" Version="7.0.0" />
|
||||||
|
<PackageReference Include="Serilog.UI" Version="3.2.0" />
|
||||||
|
<PackageReference Include="Serilog.UI.SqliteProvider" Version="1.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -5,55 +5,8 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"NLog": {
|
"Serilog": {
|
||||||
"throwConfigExceptions": true,
|
"LogDirectory": "E:\\LogFiles\\Digital Data\\Rec.API",
|
||||||
"variables": {
|
"RetainedFileCountLimit": 30
|
||||||
"logDirectory": "E:\\LogFiles\\Digital Data\\Rec.API",
|
|
||||||
"logFileNamePrefix": "${shortdate}.Rec.API"
|
|
||||||
},
|
|
||||||
"targets": {
|
|
||||||
"infoLogs": {
|
|
||||||
"type": "File",
|
|
||||||
"fileName": "${logDirectory}\\${logFileNamePrefix}-Info.log",
|
|
||||||
"maxArchiveDays": 30
|
|
||||||
},
|
|
||||||
"warningLogs": {
|
|
||||||
"type": "File",
|
|
||||||
"fileName": "${logDirectory}\\${logFileNamePrefix}-Warning.log",
|
|
||||||
"maxArchiveDays": 30
|
|
||||||
},
|
|
||||||
"errorLogs": {
|
|
||||||
"type": "File",
|
|
||||||
"fileName": "${logDirectory}\\${logFileNamePrefix}-Error.log",
|
|
||||||
"maxArchiveDays": 30
|
|
||||||
},
|
|
||||||
"criticalLogs": {
|
|
||||||
"type": "File",
|
|
||||||
"fileName": "${logDirectory}\\${logFileNamePrefix}-Critical.log",
|
|
||||||
"maxArchiveDays": 30
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"rules": [
|
|
||||||
{
|
|
||||||
"logger": "*",
|
|
||||||
"level": "Info",
|
|
||||||
"writeTo": "infoLogs"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"logger": "*",
|
|
||||||
"level": "Warn",
|
|
||||||
"writeTo": "warningLogs"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"logger": "*",
|
|
||||||
"level": "Error",
|
|
||||||
"writeTo": "errorLogs"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"logger": "*",
|
|
||||||
"level": "Fatal",
|
|
||||||
"writeTo": "criticalLogs"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace ReC.Application.Common.Dto;
|
||||||
|
|
||||||
|
public record BatchRecActionViewResponse(int TotalActionCount)
|
||||||
|
{
|
||||||
|
public int ActionExceptionCount { get; internal set; } = 0;
|
||||||
|
}
|
||||||
@@ -29,8 +29,6 @@ public class ReadProfileViewQueryHandler(IRepository<ProfileView> repo, IMapper
|
|||||||
|
|
||||||
var profiles = await query.ToListAsync(cancel);
|
var profiles = await query.ToListAsync(cancel);
|
||||||
|
|
||||||
return profiles is null || profiles.Count == 0
|
return mapper.Map<IEnumerable<ProfileViewDto>>(profiles);
|
||||||
? throw new NotFoundException($"Profile {request.Id} not found.")
|
|
||||||
: mapper.Map<IEnumerable<ProfileViewDto>>(profiles);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,26 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ReC.Application.Common.Dto;
|
||||||
using ReC.Application.Common.Exceptions;
|
using ReC.Application.Common.Exceptions;
|
||||||
using ReC.Application.RecActions.Queries;
|
using ReC.Application.RecActions.Queries;
|
||||||
using ReC.Domain.Constants;
|
using ReC.Domain.Constants;
|
||||||
|
|
||||||
namespace ReC.Application.RecActions.Commands;
|
namespace ReC.Application.RecActions.Commands;
|
||||||
|
|
||||||
public record InvokeBatchRecActionViewsCommand : IRequest
|
public record InvokeBatchRecActionViewsCommand : IRequest<BatchRecActionViewResponse>
|
||||||
{
|
{
|
||||||
public long ProfileId { get; init; }
|
public long ProfileId { get; init; }
|
||||||
public required InvokeReferences References { get; init; }
|
public required InvokeReferences References { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRecActionViewsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionViewsCommand>
|
public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRecActionViewsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionViewsCommand, BatchRecActionViewResponse>
|
||||||
{
|
{
|
||||||
public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
|
public async Task<BatchRecActionViewResponse> Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel);
|
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel);
|
||||||
|
|
||||||
|
var res = new BatchRecActionViewResponse(TotalActionCount: actions.Count());
|
||||||
|
|
||||||
foreach (var action in actions)
|
foreach (var action in actions)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -28,30 +31,26 @@ public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRe
|
|||||||
References = request.References
|
References = request.References
|
||||||
}, cancel);
|
}, cancel);
|
||||||
}
|
}
|
||||||
catch (RecActionException ex)
|
|
||||||
{
|
|
||||||
switch (action.ErrorAction)
|
|
||||||
{
|
|
||||||
case ErrorAction.Continue:
|
|
||||||
logger?.LogWarning(ex, "Rec action failed but continuing. ActionId: {ActionId}, ProfileId: {ProfileId}", ex.ActionId, ex.ProfileId);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Rethrow the exception to stop processing further actions
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
switch (action.ErrorAction)
|
switch (action.ErrorAction)
|
||||||
{
|
{
|
||||||
case ErrorAction.Continue:
|
case ErrorAction.Continue:
|
||||||
logger?.LogError(ex, "Unexpected error during rec action. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
|
|
||||||
|
if (ex is RecActionException recEx)
|
||||||
|
logger?.LogWarning(ex, "Rec action failed but continuing. ActionId: {ActionId}, ProfileId: {ProfileId}", recEx.ActionId, recEx.ProfileId);
|
||||||
|
else
|
||||||
|
logger?.LogError(ex, "Unexpected error during rec action. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Rethrow the exception to stop processing further actions
|
// Rethrow the exception to stop processing further actions
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.ActionExceptionCount += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,9 +31,6 @@ public class ReadRecActionViewQueryHandler(IRepository<RecActionView> repo, IMap
|
|||||||
|
|
||||||
var actions = await query.ToListAsync(cancel);
|
var actions = await query.ToListAsync(cancel);
|
||||||
|
|
||||||
if (actions.Count == 0)
|
|
||||||
throw new NotFoundException($"No actions found for the profile {request.ProfileId}.");
|
|
||||||
|
|
||||||
return mapper.Map<IEnumerable<RecActionViewDto>>(actions);
|
return mapper.Map<IEnumerable<RecActionViewDto>>(actions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,15 +54,6 @@ public class ReadResultViewQueryHandler(IRepository<ResultView> repo, IMapper ma
|
|||||||
? await GetLastBatchEntitiesAsync(q, cancel)
|
? await GetLastBatchEntitiesAsync(q, cancel)
|
||||||
: await q.ToListAsync(cancel);
|
: await q.ToListAsync(cancel);
|
||||||
|
|
||||||
if (entities.Count == 0)
|
|
||||||
throw new NotFoundException($"No result views found for the given criteria. Criteria: {
|
|
||||||
JsonSerializer.Serialize(request, options: new()
|
|
||||||
{
|
|
||||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
|
||||||
WriteIndented = true
|
|
||||||
})}"
|
|
||||||
);
|
|
||||||
|
|
||||||
return mapper.Map<IEnumerable<ResultViewDto>>(entities);
|
return mapper.Map<IEnumerable<ResultViewDto>>(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/ReC.Client/Api/BatchRecActionViewResponse.cs
Normal file
14
src/ReC.Client/Api/BatchRecActionViewResponse.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace ReC.Client.Api
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the result of a batch RecAction invocation.
|
||||||
|
/// </summary>
|
||||||
|
public class BatchRecActionViewResponse
|
||||||
|
{
|
||||||
|
/// <summary>Total number of actions that were processed.</summary>
|
||||||
|
public int TotalActionCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>Number of actions that resulted in an exception.</summary>
|
||||||
|
public int ActionExceptionCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,18 +30,20 @@ namespace ReC.Client.Api
|
|||||||
/// <param name="profileId">The profile identifier.</param>
|
/// <param name="profileId">The profile identifier.</param>
|
||||||
/// <param name="references">Optional reference values to pass through to all result records.</param>
|
/// <param name="references">Optional reference values to pass through to all result records.</param>
|
||||||
/// <param name="cancellationToken">A token to cancel the operation.</param>
|
/// <param name="cancellationToken">A token to cancel the operation.</param>
|
||||||
|
/// <returns>A <see cref="BatchRecActionViewResponse"/> describing the outcome of the batch invocation.</returns>
|
||||||
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
|
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
|
||||||
#if NETFRAMEWORK
|
#if NETFRAMEWORK
|
||||||
public async Task InvokeAsync(long profileId, InvokeReferences references = null, CancellationToken cancellationToken = default)
|
public async Task<BatchRecActionViewResponse> InvokeAsync(long profileId, InvokeReferences references = null, CancellationToken cancellationToken = default)
|
||||||
#else
|
#else
|
||||||
public async Task InvokeAsync(long profileId, InvokeReferences? references = null, CancellationToken cancellationToken = default)
|
public async Task<BatchRecActionViewResponse?> InvokeAsync(long profileId, InvokeReferences? references = null, CancellationToken cancellationToken = default)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
var content = references != null ? ReCClientHelpers.ToJsonContent(references) : null;
|
var content = references != null ? ReCClientHelpers.ToJsonContent(references) : null;
|
||||||
using (content)
|
using (content)
|
||||||
using (var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content, cancellationToken))
|
using (var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content, cancellationToken))
|
||||||
{
|
{
|
||||||
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancellationToken).ConfigureAwait(false);
|
var body = await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancellationToken).ConfigureAwait(false);
|
||||||
|
return ReCClientHelpers.Deserialize<BatchRecActionViewResponse>(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,8 +53,13 @@ namespace ReC.Client.Api
|
|||||||
/// <param name="profileId">The profile identifier.</param>
|
/// <param name="profileId">The profile identifier.</param>
|
||||||
/// <param name="batchId">Batch identifier.</param>
|
/// <param name="batchId">Batch identifier.</param>
|
||||||
/// <param name="cancellationToken">A token to cancel the operation.</param>
|
/// <param name="cancellationToken">A token to cancel the operation.</param>
|
||||||
|
/// <returns>A <see cref="BatchRecActionViewResponse"/> describing the outcome of the batch invocation.</returns>
|
||||||
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
|
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
|
||||||
public Task InvokeAsync(long profileId, string batchId, CancellationToken cancellationToken = default)
|
#if NETFRAMEWORK
|
||||||
|
public Task<BatchRecActionViewResponse> InvokeAsync(long profileId, string batchId, CancellationToken cancellationToken = default)
|
||||||
|
#else
|
||||||
|
public Task<BatchRecActionViewResponse?> InvokeAsync(long profileId, string batchId, CancellationToken cancellationToken = default)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
return InvokeAsync(profileId, new InvokeReferences() { BatchId = batchId }, cancellationToken);
|
return InvokeAsync(profileId, new InvokeReferences() { BatchId = batchId }, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
<PackageIcon>icon.png</PackageIcon>
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
<RepositoryUrl>http://git.dd:3000/AppStd/Rec.git</RepositoryUrl>
|
<RepositoryUrl>http://git.dd:3000/AppStd/Rec.git</RepositoryUrl>
|
||||||
<PackageTags>digital data rec api client</PackageTags>
|
<PackageTags>digital data rec api client</PackageTags>
|
||||||
<Version>2.0.0-beta</Version>
|
<Version>1.0.0</Version>
|
||||||
<AssemblyVersion>2.0.0.0</AssemblyVersion>
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
<FileVersion>2.0.0.0</FileVersion>
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
<Description>Client-Bibliothek für die Interaktion mit der ReC.API, die typisierten HTTP-Zugriff und DI-Integration bietet.</Description>
|
<Description>Client-Bibliothek für die Interaktion mit der ReC.API, die typisierten HTTP-Zugriff und DI-Integration bietet.</Description>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -30,23 +30,18 @@ public class ProfileQueryTests : RecApplicationTestBase
|
|||||||
var (sender, scope) = CreateScopedSender();
|
var (sender, scope) = CreateScopedSender();
|
||||||
using var _ = scope;
|
using var _ = scope;
|
||||||
|
|
||||||
try
|
var profiles = await sender.Send(new ReadProfileViewQuery
|
||||||
{
|
{
|
||||||
var profiles = await sender.Send(new ReadProfileViewQuery
|
Id = profileId,
|
||||||
{
|
IncludeActions = false
|
||||||
Id = profileId,
|
});
|
||||||
IncludeActions = false
|
|
||||||
});
|
|
||||||
|
|
||||||
var profile = profiles.Single();
|
var profile = profiles.SingleOrDefault();
|
||||||
|
Assert.Multiple(() =>
|
||||||
Assert.That(profile.Id, Is.EqualTo(profileId));
|
|
||||||
Assert.That(profile.ProfileName, Is.Not.Null.And.Not.Empty);
|
|
||||||
Assert.That(profile.Active, Is.True);
|
|
||||||
}
|
|
||||||
catch (NotFoundException)
|
|
||||||
{
|
{
|
||||||
Assert.Pass("NotFound is acceptable when profile does not exist");
|
Assert.That(profile?.Id, Is.EqualTo(profileId));
|
||||||
}
|
Assert.That(profile?.ProfileName, Is.Not.Null.And.Not.Empty);
|
||||||
|
Assert.That(profile?.Active, Is.True);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,34 +30,11 @@ public class RecActionQueryTests : RecApplicationTestBase
|
|||||||
var (sender, scope) = CreateScopedSender();
|
var (sender, scope) = CreateScopedSender();
|
||||||
using var _ = scope;
|
using var _ = scope;
|
||||||
|
|
||||||
try
|
var actions = await sender.Send(new ReadRecActionViewQuery
|
||||||
{
|
{
|
||||||
var actions = await sender.Send(new ReadRecActionViewQuery
|
ProfileId = profileId
|
||||||
{
|
});
|
||||||
ProfileId = profileId
|
|
||||||
});
|
|
||||||
|
|
||||||
Assert.That(actions, Is.Not.Empty);
|
Assert.That(actions.All(a => a.ProfileId == profileId));
|
||||||
Assert.That(actions.All(a => a.ProfileId == profileId));
|
|
||||||
}
|
|
||||||
catch (NotFoundException)
|
|
||||||
{
|
|
||||||
Assert.Pass("NotFound is acceptable when test data is unavailable");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ReadRecActionViewQuery_with_unknown_profile_throws_not_found()
|
|
||||||
{
|
|
||||||
var (sender, scope) = CreateScopedSender();
|
|
||||||
using var _ = scope;
|
|
||||||
|
|
||||||
var invalidProfileId = long.MaxValue;
|
|
||||||
|
|
||||||
Assert.ThrowsAsync<NotFoundException>(async () =>
|
|
||||||
await sender.Send(new ReadRecActionViewQuery
|
|
||||||
{
|
|
||||||
ProfileId = invalidProfileId
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,18 +25,11 @@ public class ResultQueryTests : RecApplicationTestBase
|
|||||||
|
|
||||||
var invalidActionId = long.MaxValue;
|
var invalidActionId = long.MaxValue;
|
||||||
|
|
||||||
try
|
await sender.Send(new ReadResultViewQuery
|
||||||
{
|
{
|
||||||
await sender.Send(new ReadResultViewQuery
|
ActionId = invalidActionId
|
||||||
{
|
});
|
||||||
ActionId = invalidActionId
|
|
||||||
});
|
|
||||||
|
|
||||||
Assert.Pass("Read completed for unknown action id.");
|
Assert.Pass("Read completed for unknown action id.");
|
||||||
}
|
|
||||||
catch (NotFoundException)
|
|
||||||
{
|
|
||||||
Assert.Pass("NotFound is acceptable for unknown action");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using ReC.Application.RecActions.Commands;
|
|||||||
using ReC.Client;
|
using ReC.Client;
|
||||||
using ReC.Client.Api;
|
using ReC.Client.Api;
|
||||||
using ClientInvokeReferences = ReC.Client.Api.InvokeReferences;
|
using ClientInvokeReferences = ReC.Client.Api.InvokeReferences;
|
||||||
|
using ClientBatchResponse = ReC.Client.Api.BatchRecActionViewResponse;
|
||||||
|
|
||||||
namespace ReC.Tests.Client;
|
namespace ReC.Tests.Client;
|
||||||
|
|
||||||
@@ -201,4 +202,70 @@ public class RecActionApiTests : RecClientTestBase
|
|||||||
Assert.That(ex, Is.Not.Null);
|
Assert.That(ex, Is.Not.Null);
|
||||||
Assert.That(ex!.Method, Is.EqualTo("POST"));
|
Assert.That(ex!.Method, Is.EqualTo("POST"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task InvokeAsync_returns_BatchRecActionViewResponse_on_success()
|
||||||
|
{
|
||||||
|
var profileId = await TryResolveProfileIdAsync();
|
||||||
|
if (profileId is null or <= 0)
|
||||||
|
Assert.Ignore("No profile available in the database for this test (set FakeProfileId or insert a profile).");
|
||||||
|
|
||||||
|
var (client, scope) = CreateScopedClient();
|
||||||
|
using var _ = scope;
|
||||||
|
|
||||||
|
ClientBatchResponse? result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = await client.RecActions.InvokeAsync(profileId!.Value, new ClientInvokeReferences { BatchId = "test-batch" });
|
||||||
|
}
|
||||||
|
catch (ReCApiException ex)
|
||||||
|
{
|
||||||
|
Assert.Pass($"API returned {ex.StatusCode} <20> acceptable when test data is unavailable.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.That(result, Is.Not.Null);
|
||||||
|
Assert.That(result!.TotalActionCount, Is.GreaterThanOrEqualTo(0));
|
||||||
|
Assert.That(result.ActionExceptionCount, Is.GreaterThanOrEqualTo(0));
|
||||||
|
Assert.That(result.ActionExceptionCount, Is.LessThanOrEqualTo(result.TotalActionCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task InvokeAsync_with_batchId_string_returns_BatchRecActionViewResponse()
|
||||||
|
{
|
||||||
|
var profileId = await TryResolveProfileIdAsync();
|
||||||
|
if (profileId is null or <= 0)
|
||||||
|
Assert.Ignore("No profile available in the database for this test (set FakeProfileId or insert a profile).");
|
||||||
|
|
||||||
|
var (client, scope) = CreateScopedClient();
|
||||||
|
using var _ = scope;
|
||||||
|
|
||||||
|
ClientBatchResponse? result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = await client.RecActions.InvokeAsync(profileId!.Value, "test-batch");
|
||||||
|
}
|
||||||
|
catch (ReCApiException ex)
|
||||||
|
{
|
||||||
|
Assert.Pass($"API returned {ex.StatusCode} <20> acceptable when test data is unavailable.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.That(result, Is.Not.Null);
|
||||||
|
Assert.That(result!.TotalActionCount, Is.GreaterThanOrEqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void InvokeAsync_with_batchId_string_and_unknown_profile_throws_ReCApiException()
|
||||||
|
{
|
||||||
|
var (client, scope) = CreateScopedClient();
|
||||||
|
using var _ = scope;
|
||||||
|
|
||||||
|
var ex = Assert.ThrowsAsync<ReCApiException>(async () =>
|
||||||
|
await client.RecActions.InvokeAsync(long.MaxValue, "test-batch"));
|
||||||
|
|
||||||
|
Assert.That(ex, Is.Not.Null);
|
||||||
|
Assert.That(ex!.Method, Is.EqualTo("POST"));
|
||||||
|
Assert.That(ex.RequestUri!.AbsolutePath, Does.Contain("invoke"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user