Compare commits
57 Commits
4ed080f58a
...
feat/clien
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9628b46ba0 | ||
|
|
1f8142852e | ||
|
|
bdd78be66c | ||
|
|
470902911e | ||
|
|
3f7ebdb632 | ||
|
|
23ef1a5797 | ||
|
|
4a7f2a41fa | ||
|
|
5f9e716ca6 | ||
|
|
91c8b98f44 | ||
|
|
10fc56b262 | ||
|
|
71368e5c85 | ||
|
|
fb649a5c68 | ||
|
|
f4abac1103 | ||
|
|
4c8e9be695 | ||
|
|
b190e4f5e9 | ||
|
|
4a1b221478 | ||
|
|
475acc0a56 | ||
|
|
f8dd16454f | ||
|
|
8cad1df95d | ||
|
|
4ee79d6cd8 | ||
|
|
c0c0650fee | ||
|
|
73059d4554 | ||
|
|
e774afc85e | ||
|
|
1fc4570210 | ||
| b71ea7d346 | |||
| 3764fdaf01 | |||
| 5e7287bf86 | |||
| 9992086e48 | |||
| 40019bf693 | |||
| 4b9e577d41 | |||
| 4e6cb20dc2 | |||
| 9a12643eb6 | |||
| f9c0a8be55 | |||
| 77fde199e1 | |||
| 9d15dfe8a5 | |||
| c41c394f48 | |||
| 34d0741ac8 | |||
| 0f3fd320b0 | |||
| 3b6df031a6 | |||
| b00902e461 | |||
| 74f4d06031 | |||
| 5ee3ca2d99 | |||
| a62923c8d6 | |||
| 9901726f5a | |||
| b8074cfaf1 | |||
| dbfae5cdad | |||
| d02bebc6e2 | |||
| 9165f9d746 | |||
| 5a226bfcea | |||
| 5cefe1457f | |||
| f4390d992a | |||
| 906d99105c | |||
| 3b4671c8e5 | |||
| 534b254d0a | |||
| 2cd7c035eb | |||
| aa34bdd279 | |||
| 2de0b5bfa3 |
5
ReC.sln
5
ReC.sln
@@ -15,6 +15,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReC.Application", "src\ReC.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReC.Client", "src\ReC.Client\ReC.Client.csproj", "{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReC.Client", "src\ReC.Client\ReC.Client.csproj", "{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
|
||||||
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
assets\icon.png = assets\icon.png
|
||||||
|
EndProjectSection
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|||||||
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
77
src/ReC.API/Controllers/OutResController.cs
Normal file
77
src/ReC.API/Controllers/OutResController.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ReC.API.Extensions;
|
||||||
|
using ReC.Application.OutResults.Queries;
|
||||||
|
|
||||||
|
namespace ReC.API.Controllers;
|
||||||
|
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class OutResController(IMediator mediator, IConfiguration config) : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets output results based on the provided query parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query">The query to filter output results.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>A list of output results matching the query.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> Get([FromQuery] ReadOutResQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets output results for a fake/test profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>A list of output results for the fake profile.</returns>
|
||||||
|
[HttpGet("fake")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadOutResQuery()
|
||||||
|
{
|
||||||
|
ProfileId = config.GetFakeProfileId()
|
||||||
|
}, cancel));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a specific output result for a fake/test profile and action.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="actionId">The ID of the action to retrieve the result for.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <param name="resultType">Specifies which part of the result to return (Full, Header, or Body).</param>
|
||||||
|
/// <returns>The requested output result or a part of it (header/body).</returns>
|
||||||
|
[HttpGet("fake/{actionId}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> Get([FromRoute] long actionId, CancellationToken cancel, ResultType resultType = ResultType.Full)
|
||||||
|
{
|
||||||
|
var res = (await mediator.Send(new ReadOutResQuery()
|
||||||
|
{
|
||||||
|
ProfileId = config.GetFakeProfileId(),
|
||||||
|
ActionId = actionId
|
||||||
|
}, cancel)).First();
|
||||||
|
|
||||||
|
return resultType switch
|
||||||
|
{
|
||||||
|
ResultType.Body => res.Body is null ? Ok(new object { }) : Ok(res.Body.JsonToDynamic()),
|
||||||
|
ResultType.Header => res.Header is null ? Ok(new object { }) : Ok(res.Header.JsonToDynamic()),
|
||||||
|
_ => Ok(res),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defines the type of result to be returned from an output result query.
|
||||||
|
/// </summary>
|
||||||
|
public enum ResultType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Return the full result object.
|
||||||
|
/// </summary>
|
||||||
|
Full,
|
||||||
|
/// <summary>
|
||||||
|
/// Return only the header part of the result.
|
||||||
|
/// </summary>
|
||||||
|
Header,
|
||||||
|
/// <summary>
|
||||||
|
/// Return only the body part of the result.
|
||||||
|
/// </summary>
|
||||||
|
Body
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ReC.API.Extensions;
|
||||||
using ReC.API.Models;
|
using ReC.API.Models;
|
||||||
using ReC.Application.RecActions.Commands;
|
using ReC.Application.RecActions.Commands;
|
||||||
using ReC.Application.RecActions.Queries;
|
using ReC.Application.RecActions.Queries;
|
||||||
@@ -9,38 +10,68 @@ namespace ReC.API.Controllers;
|
|||||||
|
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class RecActionController(IMediator mediator) : ControllerBase
|
public class RecActionController(IMediator mediator, IConfiguration config) : ControllerBase
|
||||||
{
|
{
|
||||||
private const long FakeProfileId = 2;
|
/// <summary>
|
||||||
|
/// Invokes a batch of RecActions for a given profile.
|
||||||
[HttpPost("invoke/{profileId}")]
|
/// </summary>
|
||||||
|
/// <param name="profileId">The ID of the profile.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns>
|
||||||
|
[HttpPost("invoke/{cmd}")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||||
public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
|
public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.InvokeBatchRecAction(profileId, cancel);
|
await mediator.InvokeBatchRecAction(profileId, cancel);
|
||||||
return Accepted();
|
return Accepted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes a batch of RecActions for a fake/test profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>An HTTP 202 Accepted response indicating the process has been started.</returns>
|
||||||
[HttpPost("invoke/fake")]
|
[HttpPost("invoke/fake")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
||||||
public async Task<IActionResult> Invoke(CancellationToken cancel)
|
public async Task<IActionResult> Invoke(CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.InvokeBatchRecAction(FakeProfileId, cancel);
|
await mediator.InvokeBatchRecAction(config.GetFakeProfileId(), cancel);
|
||||||
return Accepted();
|
return Accepted();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region CRUD
|
#region CRUD
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all RecActions for a given profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="profileId">The ID of the profile.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>A list of RecActions for the specified profile.</returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> Get([FromQuery] long profileId, CancellationToken cancel) => Ok(await mediator.Send(new ReadRecActionQuery()
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
{
|
public async Task<IActionResult> Get([FromQuery] ReadRecActionQuery query, CancellationToken cancel) => Ok(await mediator.Send(query, cancel));
|
||||||
ProfileId = profileId
|
|
||||||
}, cancel));
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all RecActions for a fake/test profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <param name="invoked"></param>
|
||||||
|
/// <returns>A list of RecActions for the fake profile.</returns>
|
||||||
[HttpGet("fake")]
|
[HttpGet("fake")]
|
||||||
public async Task<IActionResult> Get(CancellationToken cancel) => Ok(await mediator.Send(new ReadRecActionQuery()
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> Get(CancellationToken cancel, [FromQuery] bool invoked = false) => Ok(await mediator.Send(new ReadRecActionQuery()
|
||||||
{
|
{
|
||||||
ProfileId = FakeProfileId
|
ProfileId = config.GetFakeProfileId(),
|
||||||
|
Invoked = invoked
|
||||||
}, cancel));
|
}, cancel));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new RecAction.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">The command containing the details for the new RecAction.</param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>An HTTP 201 Created response.</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||||
public async Task<IActionResult> CreateAction([FromBody] CreateRecActionCommand command, CancellationToken cancel)
|
public async Task<IActionResult> CreateAction([FromBody] CreateRecActionCommand command, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.Send(command, cancel);
|
await mediator.Send(command, cancel);
|
||||||
@@ -48,7 +79,17 @@ public class RecActionController(IMediator mediator) : ControllerBase
|
|||||||
return CreatedAtAction(nameof(CreateAction), null);
|
return CreatedAtAction(nameof(CreateAction), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new fake RecAction for testing purposes.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <param name="request">The optional request body and header for the fake action.</param>
|
||||||
|
/// <param name="endpointUri">The target endpoint URI.</param>
|
||||||
|
/// <param name="endpointPath">The optional path to append to the endpoint URI.</param>
|
||||||
|
/// <param name="type">The HTTP method type (e.g., GET, POST).</param>
|
||||||
|
/// <returns>An HTTP 201 Created response.</returns>
|
||||||
[HttpPost("fake")]
|
[HttpPost("fake")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status201Created)]
|
||||||
public async Task<IActionResult> CreateFakeAction(
|
public async Task<IActionResult> CreateFakeAction(
|
||||||
CancellationToken cancel,
|
CancellationToken cancel,
|
||||||
[FromBody] FakeRequest? request = null,
|
[FromBody] FakeRequest? request = null,
|
||||||
@@ -64,7 +105,7 @@ public class RecActionController(IMediator mediator) : ControllerBase
|
|||||||
|
|
||||||
await mediator.Send(new CreateRecActionCommand()
|
await mediator.Send(new CreateRecActionCommand()
|
||||||
{
|
{
|
||||||
ProfileId = FakeProfileId,
|
ProfileId = config.GetFakeProfileId(),
|
||||||
EndpointUri = endpointUri,
|
EndpointUri = endpointUri,
|
||||||
Type = type,
|
Type = type,
|
||||||
BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;",
|
BodyQuery = $@"SELECT '{bodyJson ?? "NULL"}' AS REQUEST_BODY;",
|
||||||
@@ -76,23 +117,32 @@ public class RecActionController(IMediator mediator) : ControllerBase
|
|||||||
return CreatedAtAction(nameof(CreateFakeAction), null);
|
return CreatedAtAction(nameof(CreateFakeAction), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes all RecActions associated with a specific profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cmd"></param>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>An HTTP 204 No Content response upon successful deletion.</returns>
|
||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
public async Task<IActionResult> Delete([FromQuery] int profileId, CancellationToken cancel)
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
public async Task<IActionResult> Delete([FromQuery] DeleteRecActionsCommand cmd, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.Send(new DeleteRecActionsCommand()
|
await mediator.Send(cmd, cancel);
|
||||||
{
|
|
||||||
ProfileId = FakeProfileId
|
|
||||||
}, cancel);
|
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes all RecActions for a fake/test profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cancel">A token to cancel the operation.</param>
|
||||||
|
/// <returns>An HTTP 204 No Content response upon successful deletion.</returns>
|
||||||
[HttpDelete("fake")]
|
[HttpDelete("fake")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
public async Task<IActionResult> Delete(CancellationToken cancel)
|
public async Task<IActionResult> Delete(CancellationToken cancel)
|
||||||
{
|
{
|
||||||
await mediator.Send(new DeleteRecActionsCommand()
|
await mediator.Send(new DeleteRecActionsCommand()
|
||||||
{
|
{
|
||||||
ProfileId = FakeProfileId
|
ProfileId = config.GetFakeProfileId()
|
||||||
}, cancel);
|
}, cancel);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|||||||
6
src/ReC.API/Extensions/ConfigExtensions.cs
Normal file
6
src/ReC.API/Extensions/ConfigExtensions.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace ReC.API.Extensions;
|
||||||
|
|
||||||
|
public static class ConfigurationExtensions
|
||||||
|
{
|
||||||
|
public static int GetFakeProfileId(this IConfiguration config) => config.GetValue("FakeProfileId", 2);
|
||||||
|
}
|
||||||
53
src/ReC.API/Extensions/JsonExtensions.cs
Normal file
53
src/ReC.API/Extensions/JsonExtensions.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
public static class JsonExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Deserialize JSON string and automatically parse nested JSON strings.
|
||||||
|
/// </summary>
|
||||||
|
public static dynamic? JsonToDynamic(this string json)
|
||||||
|
{
|
||||||
|
// Deserialize the top-level JSON
|
||||||
|
var result = JsonSerializer.Deserialize<JsonElement>(json);
|
||||||
|
|
||||||
|
// Recursively fix stringified JSON objects
|
||||||
|
return JsonToDynamic(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static dynamic? JsonToDynamic(JsonElement obj)
|
||||||
|
{
|
||||||
|
switch (obj.ValueKind)
|
||||||
|
{
|
||||||
|
case JsonValueKind.Object:
|
||||||
|
var dict = new Dictionary<string, dynamic?>();
|
||||||
|
foreach (var prop in obj.EnumerateObject())
|
||||||
|
{
|
||||||
|
dict[prop.Name] = JsonToDynamic(prop.Value);
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
|
|
||||||
|
case JsonValueKind.Array:
|
||||||
|
var list = new List<dynamic>();
|
||||||
|
foreach (var item in obj.EnumerateArray())
|
||||||
|
{
|
||||||
|
list.Add(JsonToDynamic(item));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
|
||||||
|
case JsonValueKind.String:
|
||||||
|
var str = obj.GetString();
|
||||||
|
// Try to parse string as JSON
|
||||||
|
if (!string.IsNullOrWhiteSpace(str) && (str.StartsWith('{') || str.StartsWith('[')))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return JsonToDynamic(JsonSerializer.Deserialize<JsonElement>(str));
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
default:
|
||||||
|
return obj.GetRawText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,56 +1,78 @@
|
|||||||
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 LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var logger = LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
|
||||||
|
logger.Info("Logging initialized!");
|
||||||
|
|
||||||
var config = builder.Configuration;
|
try
|
||||||
|
|
||||||
// Add services to the container.
|
|
||||||
builder.Services.AddRecServices(options =>
|
|
||||||
{
|
{
|
||||||
options.LuckyPennySoftwareLicenseKey = builder.Configuration["LuckyPennySoftwareLicenseKey"];
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
options.ConfigureRecActions(config.GetSection("RecAction"));
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.Services.AddRecInfrastructure(options =>
|
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||||
{
|
|
||||||
options.ConfigureDbContext((provider, opt) =>
|
if (!builder.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
var cnnStr = builder.Configuration.GetConnectionString("Default")
|
builder.Logging.ClearProviders();
|
||||||
?? throw new InvalidOperationException("Connection string is not found.");
|
builder.Host.UseNLog();
|
||||||
|
}
|
||||||
|
|
||||||
var logger = provider.GetRequiredService<ILogger<RecDbContext>>();
|
var config = builder.Configuration;
|
||||||
opt.UseSqlServer(cnnStr)
|
|
||||||
.LogTo(log => logger.LogInformation("{log}", log), LogLevel.Trace)
|
// Add services to the container.
|
||||||
.EnableSensitiveDataLogging()
|
builder.Services.AddRecServices(options =>
|
||||||
.EnableDetailedErrors();
|
{
|
||||||
|
options.LuckyPennySoftwareLicenseKey = builder.Configuration["LuckyPennySoftwareLicenseKey"];
|
||||||
|
options.ConfigureRecActions(config.GetSection("RecAction"));
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddRecInfrastructure(options =>
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
{
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
options.ConfigureDbContext((provider, opt) =>
|
||||||
builder.Services.AddSwaggerGen();
|
{
|
||||||
|
var cnnStr = builder.Configuration.GetConnectionString("Default")
|
||||||
|
?? throw new InvalidOperationException("Connection string is not found.");
|
||||||
|
|
||||||
var app = builder.Build();
|
var logger = provider.GetRequiredService<ILogger<RecDbContext>>();
|
||||||
|
opt.UseSqlServer(cnnStr)
|
||||||
|
.LogTo(log => logger.LogInformation("{log}", log), LogLevel.Trace)
|
||||||
|
.EnableSensitiveDataLogging()
|
||||||
|
.EnableDetailedErrors();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
#pragma warning disable CS0618
|
#pragma warning disable CS0618
|
||||||
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
app.UseMiddleware<ExceptionHandlingMiddleware>();
|
||||||
#pragma warning restore CS0618
|
#pragma warning restore CS0618
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
}
|
}
|
||||||
|
catch(Exception ex)
|
||||||
app.UseHttpsRedirection();
|
{
|
||||||
|
logger.Error(ex, "Stopped program because of exception");
|
||||||
app.UseAuthorization();
|
throw;
|
||||||
|
}
|
||||||
app.MapControllers();
|
|
||||||
|
|
||||||
app.Run();
|
|
||||||
17
src/ReC.API/Properties/PublishProfiles/IISProfile.pubxml
Normal file
17
src/ReC.API/Properties/PublishProfiles/IISProfile.pubxml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<WebPublishMethod>Package</WebPublishMethod>
|
||||||
|
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||||
|
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||||
|
<SiteUrlToLaunchAfterPublish />
|
||||||
|
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
|
||||||
|
<ExcludeApp_Data>false</ExcludeApp_Data>
|
||||||
|
<ProjectGuid>420218ad-3c27-4003-9a84-36c92352f175</ProjectGuid>
|
||||||
|
<DesktopBuildPackageLocation>P:\Install .Net\0 DD - Smart UP\ReC\API\$(Version)\Rec.API.zip</DesktopBuildPackageLocation>
|
||||||
|
<PackageAsSingleFile>true</PackageAsSingleFile>
|
||||||
|
<DeployIisAppPath>Rec.API</DeployIisAppPath>
|
||||||
|
<_TargetId>IISWebDeployPackage</_TargetId>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -1,14 +1,27 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<PackageId>ReC.API</PackageId>
|
||||||
|
<Authors>Digital Data GmbH</Authors>
|
||||||
|
<Company>Digital Data GmbH</Company>
|
||||||
|
<Product>ReC.API</Product>
|
||||||
|
<PackageIcon>Assets\icon.ico</PackageIcon>
|
||||||
|
<PackageTags>digital data rest-caller rec api</PackageTags>
|
||||||
|
<Version>1.0.0-beta</Version>
|
||||||
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
|
<FileVersion>1.0.0.0</FileVersion>
|
||||||
|
<InformationalVersion>1.0.0-beta</InformationalVersion>
|
||||||
|
<Copyright>Copyright © 2025 Digital Data GmbH. All rights reserved.</Copyright>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<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="NLog.Web.AspNetCore" Version="5.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -13,5 +13,57 @@
|
|||||||
"RecAction": {
|
"RecAction": {
|
||||||
"MaxConcurrentInvocations": 5
|
"MaxConcurrentInvocations": 5
|
||||||
},
|
},
|
||||||
"AddedWho": "ReC.API"
|
"AddedWho": "ReC.API",
|
||||||
|
"FakeProfileId": 2,
|
||||||
|
"NLog": {
|
||||||
|
"throwConfigExceptions": true,
|
||||||
|
"variables": {
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using AutoMapper;
|
using ReC.Domain.Entities;
|
||||||
using ReC.Domain.Entities;
|
|
||||||
|
|
||||||
namespace ReC.Application.Common.Dto;
|
namespace ReC.Application.Common.Dto;
|
||||||
|
|
||||||
@@ -8,5 +7,6 @@ public class DtoMappingProfile : AutoMapper.Profile
|
|||||||
public DtoMappingProfile()
|
public DtoMappingProfile()
|
||||||
{
|
{
|
||||||
CreateMap<RecActionView, RecActionDto>();
|
CreateMap<RecActionView, RecActionDto>();
|
||||||
|
CreateMap<OutRes, OutResDto>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,37 @@
|
|||||||
namespace ReC.Application.OutResults.Queries;
|
using AutoMapper;
|
||||||
|
using DigitalData.Core.Abstraction.Application.Repository;
|
||||||
|
using DigitalData.Core.Exceptions;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using ReC.Application.Common.Dto;
|
||||||
|
using ReC.Domain.Entities;
|
||||||
|
|
||||||
public class ReadOutResQuery
|
namespace ReC.Application.OutResults.Queries;
|
||||||
|
|
||||||
|
public record ReadOutResQuery : IRequest<IEnumerable<OutResDto>>
|
||||||
{
|
{
|
||||||
public long? ProfileId { get; set; }
|
public long? ProfileId { get; init; }
|
||||||
|
|
||||||
public long? ActionId { get; set; }
|
public long? ActionId { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ReadOutResHandler(IRepository<OutRes> repo, IMapper mapper) : IRequestHandler<ReadOutResQuery, IEnumerable<OutResDto>>
|
||||||
|
{
|
||||||
|
public async Task<IEnumerable<OutResDto>> Handle(ReadOutResQuery request, CancellationToken cancel)
|
||||||
|
{
|
||||||
|
var q = repo.Query;
|
||||||
|
|
||||||
|
if(request.ActionId is long actionId)
|
||||||
|
q = q.Where(res => res.ActionId == actionId);
|
||||||
|
|
||||||
|
if(request.ProfileId is long profileId)
|
||||||
|
q = q.Where(res => res.Action!.ProfileId == profileId);
|
||||||
|
|
||||||
|
var resList = await q.ToListAsync(cancel);
|
||||||
|
|
||||||
|
if (resList.Count == 0)
|
||||||
|
throw new NotFoundException();
|
||||||
|
|
||||||
|
return mapper.Map<IEnumerable<OutResDto>>(resList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ public class ReadOutResQueryValidator : AbstractValidator<ReadOutResQuery>
|
|||||||
{
|
{
|
||||||
RuleFor(x => x)
|
RuleFor(x => x)
|
||||||
.Must(x => x.ActionId.HasValue || x.ProfileId.HasValue)
|
.Must(x => x.ActionId.HasValue || x.ProfileId.HasValue)
|
||||||
.WithMessage("At least one of ActionId or ProfileId must be provided.");
|
.WithMessage("At least one of ActionId or ProfileId must be provided.")
|
||||||
|
.WithName("Identifier");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,7 @@ namespace ReC.Application.RecActions.Commands;
|
|||||||
|
|
||||||
public class DeleteRecActionsCommand : IRequest
|
public class DeleteRecActionsCommand : IRequest
|
||||||
{
|
{
|
||||||
public long ProfileId { get; init; } = 2;
|
public required long ProfileId { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeleteRecActionsCommandHandler(IRepository<RecAction> repo) : IRequestHandler<DeleteRecActionsCommand>
|
public class DeleteRecActionsCommandHandler(IRepository<RecAction> repo) : IRequestHandler<DeleteRecActionsCommand>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using ReC.Application.RecActions.Queries;
|
using ReC.Application.RecActions.Queries;
|
||||||
|
|
||||||
@@ -12,11 +13,11 @@ public static class InvokeBatchRecActionsCommandExtensions
|
|||||||
=> sender.Send(new InvokeBatchRecActionsCommand { ProfileId = profileId }, cancel);
|
=> sender.Send(new InvokeBatchRecActionsCommand { ProfileId = profileId }, cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InvokeRecActionsCommandHandler(ISender sender, IHttpClientFactory clientFactory, ILogger<InvokeRecActionsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionsCommand>
|
public class InvokeRecActionsCommandHandler(ISender sender, IServiceScopeFactory scopeFactory, IHttpClientFactory clientFactory, ILogger<InvokeRecActionsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionsCommand>
|
||||||
{
|
{
|
||||||
public async Task Handle(InvokeBatchRecActionsCommand request, CancellationToken cancel)
|
public async Task Handle(InvokeBatchRecActionsCommand request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var actions = await sender.Send(request.ToReadQuery(), cancel);
|
var actions = await sender.Send(request.ToReadQuery(q => q.Invoked = false), cancel);
|
||||||
|
|
||||||
var http = clientFactory.CreateClient();
|
var http = clientFactory.CreateClient();
|
||||||
|
|
||||||
@@ -27,7 +28,9 @@ public class InvokeRecActionsCommandHandler(ISender sender, IHttpClientFactory c
|
|||||||
await semaphore.WaitAsync(cancel);
|
await semaphore.WaitAsync(cancel);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await sender.Send(action.ToInvokeCommand(), cancel);
|
using var scope = scopeFactory.CreateScope();
|
||||||
|
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
|
||||||
|
await sender.Send(action.ToInvokeCommand(), cancel);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,13 +12,20 @@ public record ReadRecActionQueryBase
|
|||||||
{
|
{
|
||||||
public long ProfileId { get; init; }
|
public long ProfileId { get; init; }
|
||||||
|
|
||||||
public ReadRecActionQuery ToReadQuery() => new(this);
|
public ReadRecActionQuery ToReadQuery(Action<ReadRecActionQuery> modify)
|
||||||
|
{
|
||||||
|
ReadRecActionQuery query = new(this);
|
||||||
|
modify(query);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record ReadRecActionQuery : ReadRecActionQueryBase, IRequest<IEnumerable<RecActionDto>>
|
public record ReadRecActionQuery : ReadRecActionQueryBase, IRequest<IEnumerable<RecActionDto>>
|
||||||
{
|
{
|
||||||
public ReadRecActionQuery(ReadRecActionQueryBase root) : base(root) { }
|
public ReadRecActionQuery(ReadRecActionQueryBase root) : base(root) { }
|
||||||
|
|
||||||
|
public bool? Invoked { get; set; } = null;
|
||||||
|
|
||||||
public ReadRecActionQuery() { }
|
public ReadRecActionQuery() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +33,12 @@ public class ReadRecActionQueryHandler(IRepository<RecActionView> repo, IMapper
|
|||||||
{
|
{
|
||||||
public async Task<IEnumerable<RecActionDto>> Handle(ReadRecActionQuery request, CancellationToken cancel)
|
public async Task<IEnumerable<RecActionDto>> Handle(ReadRecActionQuery request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
var actions = await repo.Where(x => x.ProfileId == request.ProfileId).ToListAsync(cancel);
|
var query = repo.Where(act => act.ProfileId == request.ProfileId);
|
||||||
|
|
||||||
|
if (request.Invoked is bool invoked)
|
||||||
|
query = invoked ? query.Where(act => act.Root!.OutRes != null) : query.Where(act => act.Root!.OutRes == null);
|
||||||
|
|
||||||
|
var actions = await query.ToListAsync(cancel);
|
||||||
|
|
||||||
if(actions.Count == 0)
|
if(actions.Count == 0)
|
||||||
throw new NotFoundException($"No actions found for the profile {request.ProfileId}.");
|
throw new NotFoundException($"No actions found for the profile {request.ProfileId}.");
|
||||||
|
|||||||
41
src/ReC.Client/DependencyInjection.cs
Normal file
41
src/ReC.Client/DependencyInjection.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
#if NETFRAMEWORK
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ReC.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides extension methods for setting up the ReC client in an <see cref="IServiceCollection"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class DependencyInjection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds and configures the <see cref="HttpClient"/> for the <see cref="ReCClient"/> to the specified <see cref="IServiceCollection"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
|
||||||
|
/// <param name="apiUri">The base URI of the ReC API.</param>
|
||||||
|
/// <returns>An <see cref="IHttpClientBuilder"/> that can be used to configure the client.</returns>
|
||||||
|
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, string apiUri)
|
||||||
|
{
|
||||||
|
services.AddScoped<ReCClient>();
|
||||||
|
return services.AddHttpClient(ReCClient.ClientName, client =>
|
||||||
|
{
|
||||||
|
client.BaseAddress = new Uri(apiUri);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds and configures the <see cref="HttpClient"/> for the <see cref="ReCClient"/> to the specified <see cref="IServiceCollection"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
|
||||||
|
/// <param name="configureClient">An action to configure the <see cref="HttpClient"/>.</param>
|
||||||
|
/// <returns>An <see cref="IHttpClientBuilder"/> that can be used to configure the client.</returns>
|
||||||
|
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, Action<HttpClient> configureClient)
|
||||||
|
{
|
||||||
|
services.AddScoped<ReCClient>();
|
||||||
|
return services.AddHttpClient(ReCClient.ClientName, configureClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,10 +2,36 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net462;net8.0</TargetFrameworks>
|
<TargetFrameworks>net462;net8.0</TargetFrameworks>
|
||||||
|
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildProjectName).xml</DocumentationFile>
|
||||||
|
<PackageId>ReC.Client</PackageId>
|
||||||
|
<Authors>Digital Data GmbH</Authors>
|
||||||
|
<Company>Digital Data GmbH</Company>
|
||||||
|
<Product>ReC.Client</Product>
|
||||||
|
<Copyright>Copyright 2025</Copyright>
|
||||||
|
<PackageIcon>icon.png</PackageIcon>
|
||||||
|
<RepositoryUrl>http://git.dd:3000/AppStd/Rec.git</RepositoryUrl>
|
||||||
|
<PackageTags>digital data rec api</PackageTags>
|
||||||
|
<Version>1.0.0-beta</Version>
|
||||||
|
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||||
|
<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>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(TargetFramework)' != 'net462'">
|
<PropertyGroup Condition="'$(TargetFramework)' != 'net462'">
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="..\..\assets\icon.png">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath>\</PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
|
||||||
|
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
124
src/ReC.Client/ReCClient.cs
Normal file
124
src/ReC.Client/ReCClient.cs
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
#if NETFRAMEWORK
|
||||||
|
using System;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace ReC.Client
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A client for interacting with the ReC API.
|
||||||
|
/// </summary>
|
||||||
|
public class ReCClient
|
||||||
|
{
|
||||||
|
private readonly HttpClient _http;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A unique name for the HttpClient used by the ReCClient.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly string ClientName = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ReCClient"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="httpClientFactory">The factory to create HttpClients.</param>
|
||||||
|
public ReCClient(IHttpClientFactory httpClientFactory)
|
||||||
|
{
|
||||||
|
_http = httpClientFactory.CreateClient(ClientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asynchronously invokes a ReC action for a specific profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method sends a POST request to the <c>api/RecAction/invoke/{profileId}</c> endpoint.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="profileId">The ID of the profile to invoke the action for.</param>
|
||||||
|
/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
|
||||||
|
/// <returns>A <see cref="Task{TResult}"/> that represents the asynchronous operation. The task result is <see langword="true"/> if the request was successful; otherwise, <see langword="false"/>.</returns>
|
||||||
|
public async Task<bool> InvokeRecActionAsync(int profileId, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var resp = await _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null, cancellationToken);
|
||||||
|
return resp.IsSuccessStatusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Synchronously invokes a ReC action for a specific profile.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method sends a POST request to the <c>api/RecAction/invoke/{profileId}</c> endpoint.
|
||||||
|
/// This is the synchronous version of <see cref="InvokeRecActionAsync(int, CancellationToken)"/>.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="profileId">The ID of the profile to invoke the action for.</param>
|
||||||
|
/// <returns><see langword="true"/> if the request was successful; otherwise, <see langword="false"/>.</returns>
|
||||||
|
[Obsolete("Use InvokeRecActionAsync instead to avoid potential deadlocks and improve performance.")]
|
||||||
|
public bool InvokeRecAction(int profileId)
|
||||||
|
{
|
||||||
|
var resp = _http.PostAsync($"api/RecAction/invoke/{profileId}", content: null).GetAwaiter().GetResult();
|
||||||
|
return resp.IsSuccessStatusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Static
|
||||||
|
private static readonly IServiceCollection Services = new ServiceCollection();
|
||||||
|
|
||||||
|
#if NET8_0_OR_GREATER
|
||||||
|
private static IServiceProvider? Provider = null;
|
||||||
|
#else
|
||||||
|
private static IServiceProvider Provider = null;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures and builds the static <see cref="IServiceProvider"/> for creating <see cref="ReCClient"/> instances.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method should only be called once during application startup.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="apiUri">The base URI of the ReC API.</param>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown if the static provider has already been built.</exception>
|
||||||
|
[Obsolete("Use a local service collection instead of the static provider.")]
|
||||||
|
public static void BuildStaticClient(string apiUri)
|
||||||
|
{
|
||||||
|
if(Provider != null)
|
||||||
|
throw new InvalidOperationException("Static Provider is already built.");
|
||||||
|
|
||||||
|
Services.AddRecClient(apiUri);
|
||||||
|
Provider = Services.BuildServiceProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configures and builds the static <see cref="IServiceProvider"/> for creating <see cref="ReCClient"/> instances.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This method should only be called once during application startup.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="configureClient">An action to configure the <see cref="HttpClient"/>.</param>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown if the static provider has already been built.</exception>
|
||||||
|
[Obsolete("Use a local service collection instead of the static provider.")]
|
||||||
|
public static void BuildStaticClient(Action<HttpClient> configureClient)
|
||||||
|
{
|
||||||
|
if (Provider != null)
|
||||||
|
throw new InvalidOperationException("Static Provider is already built.");
|
||||||
|
|
||||||
|
Services.AddRecClient(configureClient);
|
||||||
|
Provider = Services.BuildServiceProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="ReCClient"/> instance using the statically configured provider.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A new instance of the <see cref="ReCClient"/>.</returns>
|
||||||
|
/// <exception cref="InvalidOperationException">Thrown if <see cref="BuildStaticClient(string)"/> has not been called yet.</exception>
|
||||||
|
[Obsolete("Use a local service collection instead of the static provider.")]
|
||||||
|
public static ReCClient Create()
|
||||||
|
{
|
||||||
|
if (Provider == null)
|
||||||
|
throw new InvalidOperationException("Static Provider is not built. Call BuildStaticClient first.");
|
||||||
|
|
||||||
|
return Provider.GetRequiredService<ReCClient>();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,9 @@ public class OutRes
|
|||||||
[Column("ACTION_ID")]
|
[Column("ACTION_ID")]
|
||||||
public long? ActionId { get; set; }
|
public long? ActionId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("ActionId")]
|
||||||
|
public RecAction? Action { get; set; }
|
||||||
|
|
||||||
[Column("RESULT_HEADER")]
|
[Column("RESULT_HEADER")]
|
||||||
public string? Header { get; set; }
|
public string? Header { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -69,4 +69,6 @@ public class RecAction
|
|||||||
|
|
||||||
[Column("CHANGED_WHEN")]
|
[Column("CHANGED_WHEN")]
|
||||||
public DateTime? ChangedWhen { get; set; }
|
public DateTime? ChangedWhen { get; set; }
|
||||||
|
|
||||||
|
public OutRes? OutRes { get; set; }
|
||||||
}
|
}
|
||||||
@@ -17,9 +17,15 @@ public class RecActionView
|
|||||||
[Column("ACTION_ID")]
|
[Column("ACTION_ID")]
|
||||||
public required long Id { get; set; }
|
public required long Id { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("Id")]
|
||||||
|
public RecAction? Root { get; set; }
|
||||||
|
|
||||||
[Column("PROFILE_ID")]
|
[Column("PROFILE_ID")]
|
||||||
public long? ProfileId { get; set; }
|
public long? ProfileId { get; set; }
|
||||||
|
|
||||||
|
[ForeignKey("ProfileId")]
|
||||||
|
public Profile? Profile { get; set; }
|
||||||
|
|
||||||
[Column("PROFILE_NAME")]
|
[Column("PROFILE_NAME")]
|
||||||
[MaxLength(100)]
|
[MaxLength(100)]
|
||||||
public string? ProfileName { get; set; }
|
public string? ProfileName { get; set; }
|
||||||
|
|||||||
@@ -35,5 +35,10 @@ public class RecDbContext(DbContextOptions<RecDbContext> options) : DbContext(op
|
|||||||
modelBuilder.Entity<HeaderQueryResult>().HasNoKey();
|
modelBuilder.Entity<HeaderQueryResult>().HasNoKey();
|
||||||
|
|
||||||
modelBuilder.Entity<BodyQueryResult>().HasNoKey();
|
modelBuilder.Entity<BodyQueryResult>().HasNoKey();
|
||||||
|
|
||||||
|
modelBuilder.Entity<RecAction>()
|
||||||
|
.HasOne(act => act.OutRes)
|
||||||
|
.WithOne(res => res.Action)
|
||||||
|
.HasForeignKey<OutRes>(res => res.ActionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user