217 Commits

Author SHA1 Message Date
42db5460fc Mark callback-based variant as [Obsolete]
Add an informational note to clarify the usage of the callback-based variant of `StaticBuildConfiguration`. Highlight that it is marked as `[Obsolete]` with the message: "Use a local service collection instead of the static provider."

Emphasize that while the `StaticBuildConfiguration` variant is recommended within the static path, the static path itself remains a convenience API. Reference Chapter 6 for additional context.
2026-05-21 14:29:49 +02:00
68a2c6190a Update build config for project {DA3A6BDD-8045-478F-860B}
Modified the `ReC.sln` solution file to update the build
configuration for the project with GUID
`{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}`:
- Changed `Debug|Any CPU` configuration from `Debug|Any CPU`
  to `Release|Any CPU` for both `ActiveCfg` and `Build.0`.
- `Release|Any CPU` configuration remains unchanged.

No changes were made to other projects or configurations.
2026-05-21 14:08:53 +02:00
d215b2f567 Update ReC.Client version and metadata
Updated `<PackageTags>` to better describe the package as a client library. Incremented `<Version>` to 2.0.0-beta, reflecting a major update. Synchronized `<AssemblyVersion>` and `<FileVersion>` to 2.0.0.0 for consistency with the new version.
2026-05-21 12:58:36 +02:00
1703646927 Improve test robustness and dynamic profile resolution
Enhanced `RecActionApiTests` and `ResultApiTests` to handle flexible server responses, including `null` or `JsonElement` payloads, ensuring calls do not throw exceptions. Updated exception handling to allow undefined server behavior for unfiltered `GET` requests with no data.

Replaced hardcoded `FakeProfileId` with `TryResolveProfileIdAsync`, a dynamic method to resolve profile IDs from configuration or server queries. Added this method to `RecClientTestBase`.

Refactored `UpdateAsync_with_unknown_id` test to support idempotent behavior, passing on successful updates or verifying exceptions.

Included `System.Linq` and `System.Threading.Tasks` namespaces to support new functionality.
2026-05-21 12:55:08 +02:00
03a8736161 Add TryResolveProfileIdAsync method for test profiles
Introduced the `TryResolveProfileIdAsync` method in the `RecApplicationTestBase` class to resolve a usable profile ID for tests. The method prioritizes a configured `FakeProfileId` and falls back to querying the database for the first available profile. Added necessary namespaces (`System.Linq`, `System.Threading.Tasks`, and `MediatR`) to support LINQ, async operations, and the `ISender` interface. Implemented dependency injection for querying profiles and added error handling to ensure robustness.
2026-05-21 12:53:58 +02:00
f4240b6452 Refactor tests for UpdateResult and ReadResult queries
Updated `ResultProcedureTests` to use `UpdateResultDto` for better structure and clarity in the `UpdateResultProcedure_runs_via_mediator` test. Adjusted the `StatusId` value to `0` for consistency.

Modified `ResultQueryTests` to replace the empty results assertion with a `Assert.Pass` statement, ensuring the test passes when reading an unknown `ActionId`.
2026-05-21 12:53:29 +02:00
f66fbb30e8 Handle BadRequestException and improve test robustness
Added handling for BadRequestException in RecActionProcedureTests
to ensure data-related errors are gracefully handled. Updated
UpdateActionProcedure_runs_via_mediator to use UpdateActionDto
for better type safety. Refactored ReadRecActionViewQuery_returns_actions_for_profile
to dynamically resolve profile IDs, improving test reliability
and providing clearer feedback when test data is missing.
2026-05-21 12:53:06 +02:00
99269a51c4 Refactor tests and introduce UpdateProfileDto
Refactored `ProfileProcedureTests` to use `UpdateProfileDto` for the `Data` property in `UpdateProfileCommand`, improving code clarity.

Updated `ProfileQueryTests` to replace `FakeProfileId` retrieval with `TryResolveProfileIdAsync` and added a conditional check to ignore the test if no valid profile ID is available, enhancing test robustness and flexibility.
2026-05-21 12:52:48 +02:00
b68f9cd602 Refactor UpdateProfileCommand to use UpdateProfileDto
Refactored the `ExecuteUpdateProcedure_runs_with_changedWho`
test method to use the `UpdateProfileDto` class for the `Data`
property of the `UpdateProfileCommand`, improving encapsulation
and structure. Added the necessary `using` directive for
`ReC.Application.Common.Procedures.UpdateProcedure.Dto` to
support this change.
2026-05-21 12:52:24 +02:00
2579a157ca Refactor UpdateEndpointCommand initialization
Updated EndpointProcedureTests to use UpdateEndpointDto for the
Data property in UpdateEndpointCommand. Added a new using
directive for ReC.Application.Common.Procedures.UpdateProcedure.Dto
to include the required class.
2026-05-21 12:52:06 +02:00
c4776eda34 Refactor UpdateEndpointParamsCommand initialization
Refactored the `UpdateEndpointParamsCommand` to use the newly
introduced `UpdateEndpointParamsDto` class for encapsulating
the `Data` property. Added a `using` directive for the
`ReC.Application.Common.Procedures.UpdateProcedure.Dto`
namespace to support this change.
2026-05-21 12:51:50 +02:00
8842918071 Refactor UpdateEndpointAuthCommand test setup
Updated the `UpdateEndpointAuthProcedure_runs_via_mediator` test to use the `UpdateEndpointAuthDto` class for the `Data` property of the `UpdateEndpointAuthCommand`, improving clarity and aligning with the use of a dedicated DTO.

Added the necessary `using` directive for `ReC.Application.Common.Procedures.UpdateProcedure.Dto` to ensure the `UpdateEndpointAuthDto` class is accessible in the test file.
2026-05-21 12:51:35 +02:00
c63ecb7e45 Add tests for ReCClient static client initialization
Introduced `StaticReCClientTests` to validate the behavior of
the `ReCClient` static client, ensuring deterministic and
non-parallel execution due to process-wide state mutation.

Added tests to cover various scenarios:
- Null configuration callback throws `ArgumentNullException`.
- Missing `BaseAddress` or `ConfigureClient` throws.
- Conflicting `BaseAddress` and `ConfigureClient` throws.
- Successful static client build and resolution via `Create`.
- Subsequent `BuildStaticClient` calls throw exceptions.

Included helper types for `ConfigureServices` validation and
used `#pragma` directives to suppress warnings for obsolete
members. Ensured test order with `[Order]` attributes.
2026-05-21 09:29:17 +02:00
7298140648 Add tests for ReCClient dependency injection setup
Added a new `DependencyInjectionTests` class to validate the
dependency injection setup for the `ReCClient` class.

- Added tests to ensure `ReCClient` can be resolved when registered
  with a base URL or custom HTTP client configuration.
- Verified default options are registered when no callback is
  supplied and that options callbacks are applied correctly.
- Added tests to validate behavior when `LogSuccessfulRequests`
  is enabled, including scenarios with and without a registered
  logger.
- Included necessary `using` directives for DI, logging, options,
  HTTP client, and the `ReC.Client` namespace.
2026-05-21 09:28:57 +02:00
ce5ffaae44 Refactor ReCClient static provider functionality
Moved static provider logic to a new partial class `ReCClient.Static.cs` to support legacy scenarios (e.g., .NET Framework) without requiring an external `IServiceProvider`.

Introduced new static methods for building and resolving a static `IServiceProvider`:
- `BuildStaticClient(Action<StaticBuildConfiguration>)`
- Overloads for simpler configuration with `apiUri` or `HttpClient`.

Marked static methods as `[Obsolete]` to discourage use in modern DI-based applications.

Refactored `ReCClient` to focus solely on instance-level functionality, improving code organization and maintainability. Added documentation to clarify the intended use of static methods.
2026-05-21 09:17:39 +02:00
1fc395f495 Improve ReCClient static client and documentation
Updated `ReCClientOptions` to include a warning about the `LogSuccessfulRequests` option throwing an `InvalidOperationException` if no `ILogger` is registered via DI. Added validation and thread-safety to `BuildStaticClient` using `Lazy<IServiceProvider>`.

Introduced `StaticBuildConfiguration` for callback-based configuration and detailed its properties. Clarified usage patterns, added VB.NET and C# examples, and documented validation rules.

Marked older `BuildStaticClient` overloads as `[Obsolete]` while retaining functionality. Expanded context on static client use cases and synchronous wrappers. Improved documentation clarity and consistency.
2026-05-21 08:33:24 +02:00
9e1bee9ea3 Refactor and enhance static ReCClient configuration
Introduced a new `BuildStaticClient(Action<StaticBuildConfiguration>)` method for flexible and detailed static `IServiceProvider` configuration. Added the `StaticBuildConfiguration` class to encapsulate optional settings like `BaseAddress`, `ConfigureClient`, `Logger`, and more.

Refactored existing `BuildStaticClient` overloads to use the new method, ensuring consistency and reducing duplication. Added support for optional `ILogger` instances and improved validation to enforce proper configuration.

Marked existing `BuildStaticClient` methods as obsolete, recommending the new method. Enhanced thread-safety using `Interlocked.CompareExchange`. Updated XML documentation and added conditional compilation for `NETFRAMEWORK` compatibility.

These changes improve maintainability, usability, and alignment with modern .NET practices.
2026-05-21 08:32:04 +02:00
09c0a5f3cf Refactor static IServiceProvider initialization
Refactor static IServiceProvider initialization to use a thread-safe Lazy<IServiceProvider>, ensuring lazy creation and improved efficiency. Replace `Services` and `Provider` fields with `_staticConfigure` delegate for dynamic service collection configuration.

Update `BuildStaticClient` methods to use `Interlocked.CompareExchange` for safe initialization of `_staticConfigure`. Modify `Create` method to retrieve the provider via `LazyProvider`.

Mark `BuildStaticClient` and `Create` methods as obsolete, encouraging the use of local service collections. Adjust exception messages and documentation to reflect these changes.
2026-05-20 16:43:47 +02:00
46eccf7a9b Validate logger presence for LogSuccessfulRequests
Added a validation in the `ReCClient` constructor to ensure that
an `ILogger` instance is provided when the `LogSuccessfulRequests`
option in `ReCClientOptions` is enabled. Throws an
`InvalidOperationException` with a detailed message if no logger
is injected. The message includes guidance on resolving the issue
by either registering a logging provider or disabling the option.
2026-05-20 15:39:24 +02:00
275746afde Clarify static API and sync wrapper usage in ReC.Client
Expand documentation on `[Obsolete]` static APIs and sync wrappers,
emphasizing their maintained status and appropriate use cases.

- Added detailed examples for `BuildStaticClient` and `Create`
  in VB.NET and C#, including configuration options.
- Updated `TaskSyncExtensions.Sync` section with warnings about
  potential deadlocks and recommendations for `async/await`.
- Introduced "6.3 Mid-Term Recommendation" to guide migration
  to DI and async patterns.
- Highlighted scenarios where static APIs and sync wrappers
  remain appropriate, such as legacy .NET Framework projects
  or quick-start use cases.
- Clarified that `[Obsolete]` is a reminder, not a breaking change.
2026-05-20 15:35:17 +02:00
b06d8029c4 Add ReC.Client.xwiki to Solution Items in ReC.sln
The solution file (ReC.sln) was updated to include the new
documentation file `docs\ReC.Client.xwiki` under the "Solution
Items" section. This change ensures the file is part of the
solution for better organization and accessibility.
2026-05-20 15:15:47 +02:00
e69bc9cdb9 Refactor ReCClient API for async and DI compatibility
Updated `RecActions.InvokeAsync(...).Sync()` to align with migration guidelines, marking `Sync()` as `[Obsolete]` and recommending `async/await` for asynchronous patterns.

Enhanced `BuildStaticClient` methods to include an optional `configureOptions` parameter for flexible `ReCClientOptions` configuration. Added conditional compilation for nullable reference type compatibility across .NET Framework and modern .NET versions.

Updated `Services.AddRecClient` calls to support `configureOptions`. Retained `[Obsolete]` on static helpers to encourage dependency injection (`services.AddRecClient(...)`) for new code.

Revised migration notes to emphasize deprecation of synchronous methods, static helpers, and the importance of adopting modern async and DI patterns. Clarified changes to `GetAsync` methods, error handling with `ReCApiException`, and deserialization behavior.
2026-05-20 15:11:14 +02:00
983f3f76ad Update ReC.Client docs with DI, async, and API changes
Comprehensively updated the documentation for the ReC.Client
library to improve usability and align with modern .NET
development practices. Key changes include:

- Added an introduction to the library, its purpose, and
  supported frameworks (.NET 8 and .NET Framework 4.6.2).
- Documented core features like DI support, typed APIs,
  consistent error handling, and flexible GET methods.
- Provided installation and setup instructions with examples
  in VB.NET and C#.
- Explained usage patterns for GET endpoints (typed and
  dynamic), CRUD operations, and invoking RecActions.
- Highlighted error handling via ReCApiException with examples.
- Added a section on testing with in-process API testing
  recommendations.
- Marked static APIs and synchronous helpers as [Obsolete],
  explaining limitations and providing migration tips.
- Provided migration guidance for recent API changes, such as
  `GetAsync<T>` returning deserialized values and unified
  error handling.
- Addressed FAQs about new patterns and deprecated methods.

These updates aim to modernize the library, promote best
practices, and simplify adoption for developers.
2026-05-20 14:04:05 +02:00
afd5cd5fbd Refactor: Rename GetDynamicAsync to GetAsync
Renamed `GetDynamicAsync` to `GetAsync` across `ProfileApi.cs`,
`RecActionApi.cs`, and `ResultApi.cs` to improve consistency
and align with naming conventions for asynchronous methods.

Updated XML documentation to clarify that the non-generic
`GetAsync` overload returns a dynamically deserialized payload,
typically a `System.Text.Json.JsonElement`. Highlighted its
relation to the generic `GetAsync<T>` method.

Adjusted method signatures for both `NETFRAMEWORK` and
non-`NETFRAMEWORK` code paths. Updated test files
(`ProfileApiTests.cs`, `RecActionApiTests.cs`, and
`ResultApiTests.cs`) to reflect the renaming, including
test method names and assertions.

These changes enhance code readability, maintainability,
and consistency.
2026-05-20 13:50:55 +02:00
12f4bf8828 Mark TaskSyncExtensions methods as obsolete
The `TaskSyncExtensions` class and its methods (`Sync` and
`Sync<TResult>`) have been marked as `[System.Obsolete]`. These
methods are no longer recommended due to the risk of deadlocks
and unexpected behavior caused by synchronous blocking.

Developers are advised to use `async/await` patterns instead.
The warning messages indicate that these methods will be
removed in a future release.
2026-05-20 13:21:01 +02:00
d34af1ac86 Refactor tests to use async/await and improve naming
Updated all test methods to use asynchronous programming with
`async` and `await`, replacing synchronous calls with
`.GetAwaiter().GetResult()`. This improves readability and
aligns with modern C# practices.

Renamed test methods to reflect their asynchronous nature and
better describe their behavior. Updated exception handling to
validate HTTP methods and request URIs while maintaining
original assertions.

Applied changes consistently across multiple test classes,
including `CommonApiTests`, `EndpointAuthApiTests`,
`EndpointParamsApiTests`, `EndpointsApiTests`,
`ProfileApiTests`, `RecActionApiTests`, and `ResultApiTests`.
2026-05-20 13:18:13 +02:00
9e90efb781 Add Endpoints API integration tests
Added a new test class `EndpointsApiTests` to validate the `Endpoints` API functionality in the `ReC.Client`.
Tests include:
- Dependency injection resolution for the `Endpoints` API.
- Behavior of `CreateAsync` with minimal payload.
- Behavior of `UpdateAsync` with an unknown ID.
- Validation of `DeleteAsync` sending payload as query string.

Introduced necessary `using` directives and utilized the `CreateScopedClient` helper method for resource management.
2026-05-20 13:13:53 +02:00
ff2a519e95 Add EndpointParams API tests for ReC.Client library
Added `EndpointParamsApiTests` to validate the `EndpointParams`
API functionality. Introduced tests for dependency injection
resolution, `CreateAsync`, `UpdateAsync`, and `DeleteAsync`
methods to ensure proper behavior, including exception handling
and HTTP method verification. Utilized scoped clients for
resource management and introduced payload DTOs for API
operations.
2026-05-20 13:13:39 +02:00
c511f0edcd Add tests for EndpointAuth API functionality
Added the `EndpointAuthApiTests` class to test the `EndpointAuth` API.
Tests include:
- Dependency injection resolution (`ReCClient_endpoint_auth_api_is_resolvable_through_dependency_injection`).
- `CreateAsync` behavior with minimal payload.
- `UpdateAsync` behavior with an unknown ID.
- `DeleteAsync` behavior, ensuring payload is sent as a query string.

Introduced necessary `using` directives and utilized the `CreateScopedClient` helper method for scoped client creation. Added exception handling to validate API method behavior and ensure proper assertions on exceptions.
2026-05-20 13:13:20 +02:00
b9dfc15ae2 Add CommonApiTests for ReCClient functionality
Introduced the `CommonApiTests` class to validate the behavior of the `ReCClient`'s `Common` API.

- Added `using` directives for namespaces related to procedures and commands to support the new tests.
- Verified dependency injection resolution for `ReCClient` and its `Common` API.
- Added tests for `CreateAsync`, `UpdateAsync`, and `DeleteAsync` methods to ensure proper handling of payloads and expected behavior:
  - `CreateAsync_with_invalid_action_payload_throws_or_completes`: Tests invalid payload handling for `CreateAsync`.
  - `UpdateAsync_with_body_payload_throws_or_completes`: Tests payload handling for `UpdateAsync`.
  - `DeleteAsync_sends_payload_as_query_string`: Verifies query string construction for `DeleteAsync`.
2026-05-20 13:13:04 +02:00
0895e6bc29 Add ProfileApiTests for Profiles API functionality
Introduced a new `ProfileApiTests` class to test the `Profiles` API in the `ReC.Client`. Added test methods to verify API behavior, including dependency injection resolution, handling of unknown IDs, dynamic payload retrieval, update operations, and query string validation for delete operations.

Key changes:
- Added `ReCClient_profiles_api_is_resolvable_through_dependency_injection` test.
- Added `GetAsync_with_unknown_id_throws_not_found` test.
- Added `GetDynamicAsync_with_unknown_id_throws_not_found` test.
- Added `GetDynamicAsync_without_filters_returns_dynamic_payload_or_throws_not_found` test.
- Added `UpdateAsync_with_unknown_id_throws_or_completes` test.
- Added `DeleteAsync_sends_payload_as_query_string` test.

Included necessary `using` directives, scoped client creation, and exception handling to ensure robust test coverage for the `Profiles` API.
2026-05-20 13:12:26 +02:00
92f2511c63 Add ResultApiTests with comprehensive test coverage
Introduced the `ResultApiTests` class to validate the behavior of the `Results` API client. Added test cases to ensure proper dependency injection, handle various API operations (`GetAsync`, `GetDynamicAsync`, `CreateAsync`, `UpdateAsync`, `DeleteAsync`), and verify expected outcomes such as exceptions, payload handling, and dynamic responses. Included necessary `using` directives to support the new tests.
2026-05-20 13:11:32 +02:00
340349a2d5 Add tests for GetDynamicAsync method in RecActionApiTests
Added a `using` directive for `System.Text.Json` to support JSON
operations. Introduced two new test methods:
`GetDynamicAsync_without_filters_returns_dynamic_payload_or_throws_not_found`
to validate the behavior of `GetDynamicAsync` without filters, and
`GetDynamicAsync_with_unknown_profile_throws_not_found` to ensure
proper handling of unknown profile IDs.
2026-05-20 11:41:43 +02:00
bbc3524dd9 Add GetDynamicAsync methods for dynamic deserialization
Added `GetDynamicAsync` methods to `ProfileApi`, `RecActionApi`,
and `ResultApi` to enable dynamic payload deserialization.
These methods support optional parameters for filtering and
are conditionally compiled for `NETFRAMEWORK` and other
frameworks, with nullable reference type support where
applicable. Internally, they reuse the existing `GetAsync<object>`
method for data retrieval.
2026-05-20 11:39:39 +02:00
73d8068d8e Add unit tests for RecActions API client
Introduced a new test class `RecActionApiTests` to validate the behavior of the `RecActions` API client.

- Added tests for `GetAsync`, `CreateAsync`, `UpdateAsync`, `DeleteAsync`, and `InvokeAsync` methods to ensure proper handling of valid and invalid inputs.
- Verified dependency injection resolution for `RecClient` and `RecActions`.
- Included assertions for HTTP status codes, request methods, and query parameters.
- Handled edge cases such as missing test data with `Assert.Pass` or `Assert.Ignore`.
- Utilized scoped clients for test isolation and resource management.

These changes improve test coverage and ensure the reliability of the `RecActions` API client.
2026-05-20 11:34:09 +02:00
b724f2e5f4 Add RecClientTestBase for integration testing setup
Introduce `RecClientTestBase` to streamline integration tests for `ReCClient`.
This abstract class uses `WebApplicationFactory` to create a test server
for `ReC.API` and configures a `ServiceProvider` with necessary services.
It includes helper methods for creating scoped `ReCClient` instances and
ensures proper resource cleanup via `IDisposable`.

Update `ReC.Tests.csproj` to include:
- `Microsoft.AspNetCore.Mvc.Testing` package for integration testing.
- Project references to `ReC.API` and `ReC.Client` for testing purposes.

These changes establish a reusable and maintainable testing infrastructure.
2026-05-20 11:33:50 +02:00
a3aa6ea7ae Refactor Program.cs for exception handling and partial class
Updated the `try-catch` block in `Program.cs` to rethrow exceptions after logging them, ensuring proper error propagation. Added a `public partial class Program` declaration to enable splitting the `Program` class across multiple files. Adjusted closing braces to align with the new structure.
2026-05-20 11:31:34 +02:00
b6420fcc49 Refactor GetAsync methods to return deserialized data
Updated GetAsync methods in ProfileApi, RecActionApi, and
ResultApi to return deserialized objects of type <T> instead
of raw HttpResponseMessage, improving usability.

Added conditional compilation (#if NETFRAMEWORK) to handle
nullable return types (T?) for non-NET Framework targets,
ensuring compatibility across .NET versions.

Replaced direct Http.GetAsync calls with using blocks for
proper disposal of HTTP responses. Introduced response
handling and deserialization via ReCClientHelpers to
streamline processing and logging.

Updated XML documentation to reflect the new behavior and
removed redundant parameters.
2026-05-20 11:31:02 +02:00
8976620205 Refactor HTTP response handling and add JSON support
Enhanced `HandleResponseAsync` to return response body as a string and log successful responses. Introduced `JsonOptions` for consistent JSON serialization/deserialization. Added a generic `Deserialize<T>` method for deserializing JSON responses. Updated method signatures to support nullable reference types.
2026-05-20 11:24:01 +02:00
d37eda0d6d Refactor API methods for improved query handling
Updated `DeleteAsync` in `BaseCrudApi.cs` to serialize payloads into query strings to align with API expectations.

Added `UpdateAsync` to `CommonApi.cs` for payload-based updates, overriding inherited CRUD helpers to match the API's behavior.

Enhanced `GetAsync` in `ProfileApi.cs` to support optional profile filtering and default `includeActions` to `true`.

Refactored `InvokeAsync` in `RecActionApi.cs` to use `long` for `profileId`, support nullable `references`, and handle batches of RecActions.

Extended `GetAsync` in `ResultApi.cs` with new optional filters (`batchId`, `includeAction`, `includeProfile`, `lastBatch`) and updated query-building logic.
2026-05-20 09:22:41 +02:00
5239c2f071 Add BuildQueryFromObject<T> method for query strings
Enhanced ReCClientHelpers.cs with a new utility method:
- Added `BuildQueryFromObject<T>` to serialize objects into query strings.
- Skips `null` properties and escapes names/values for safety.
- Added `System.Collections` and `System.Reflection` namespaces to support reflection and collection operations.

This improves HTTP request handling by enabling dynamic query string generation from object payloads.
2026-05-20 09:19:18 +02:00
6d8e51ad70 Add ReCClientOptions for configurable client behavior
Introduced a new `ReCClientOptions` property to `BaseCrudApi`
and its derived classes to enhance flexibility and control
over client behavior. Updated constructors to accept an
optional `ReCClientOptions` parameter, with default options
applied when omitted.

Modified `CreateAsync`, `UpdateAsync`, and other methods in
`BaseCrudApi` to utilize the `Options.LogSuccessfulRequests`
property for more granular logging control. Updated derived
API classes (`CommonApi`, `EndpointAuthApi`, `EndpointParamsApi`,
`EndpointsApi`, `ProfileApi`, `RecActionApi`, and `ResultApi`)
to pass the `options` parameter to the base constructor.

Ensured compatibility with both `NETFRAMEWORK` and other
frameworks by using nullable annotations where applicable.
These changes improve the extensibility and maintainability
of the API client.
2026-05-19 19:20:54 +02:00
01ac7ece1e Add optional logging control to HandleResponseAsync
The HandleResponseAsync method was updated to include a new
optional parameter, `logSuccess`, which allows control over
whether successful HTTP responses are logged. The default
value is `true`. This change applies to both `NETFRAMEWORK`
and non-`NETFRAMEWORK` builds. The method's XML documentation
was updated to reflect this new behavior.
2026-05-19 19:20:37 +02:00
e0c2aab2b1 Add support for configurable options in ReCClient
Updated `ReCClient` to support dependency injection for
`IOptions<ReCClientOptions>` and `ILogger`. Modified the
constructor to include an optional `IOptions` parameter,
allowing the use of configurable client options with
default values when omitted. Updated API component
initialization to pass `ReCClientOptions` for enhanced
configuration.

Added `Microsoft.Extensions.Logging` and
`Microsoft.Extensions.Options` to `using` directives.
Ensured compatibility with both `NETFRAMEWORK` and other
target frameworks by updating constructor signatures
accordingly.
2026-05-19 19:20:28 +02:00
a43d1ebc20 Add optional ReCClientOptions configuration support
Added an optional `configureOptions` parameter to `AddRecClient`
methods, enabling configuration of `ReCClientOptions`. Introduced
conditional compilation to handle nullability differences between
.NET Framework and other frameworks.

Implemented a private helper method `AddRecClientOptions` to ensure
default options are registered even when no configuration action is
provided. Updated `AddRecClient` overloads to use this helper.

Included `System.Net.Http` in `#if NETFRAMEWORK` directives to
maintain compatibility with .NET Framework.
2026-05-19 19:20:17 +02:00
f96ad1ac7e Add ReCClientOptions for configurable logging behavior
Introduce the `ReCClientOptions` class in the new `ReC.Client`
namespace. This class includes the `LogSuccessfulRequests`
property, which allows users to enable or disable logging for
successful API requests via the injected `ILogger`. Failed
requests are unaffected and will always throw `ReCApiException`.
The property defaults to `true`. XML documentation is included
to describe the class and its behavior.
2026-05-19 19:19:32 +02:00
20766091a9 Add logging to HandleResponseAsync in ReCClientHelpers
Refactored the `EnsureSuccessAsync` method to `HandleResponseAsync`
and added optional `ILogger` support for logging HTTP request
and response details.

- Added `using Microsoft.Extensions.Logging;` for logging.
- Log success responses with HTTP method, URI, status code,
  and reason phrase.
- Updated exception message construction for clarity.
- Added conditional compilation for nullable `ILogger?`
  in non-NET Framework targets.
- Improved code maintainability by consolidating logic.
2026-05-19 19:09:51 +02:00
91c166dc4d Add ILogger support for enhanced API call logging
Introduced optional ILogger support across BaseCrudApi and its
derived classes to enable logging of API call outcomes. Updated
constructors to accept an optional ILogger parameter, with
conditional compilation for .NET Framework compatibility.

Replaced EnsureSuccessAsync with HandleResponseAsync in CRUD
methods to integrate logging. Updated derived API classes
(CommonApi, EndpointAuthApi, EndpointParamsApi, EndpointsApi,
ProfileApi, RecActionApi, ResultApi) to pass ILogger to the base
class.

Added Microsoft.Extensions.Logging imports and ensured backward
compatibility by making ILogger optional and handling nullable
reference types in non-.NET Framework environments.
2026-05-19 19:09:08 +02:00
7ed348832c Add logging support to ReCClient and related APIs
Updated the `ReCClient` constructor to include an optional `ILogger` parameter for logging API call outcomes. Added support for both .NET Framework and other frameworks by using non-generic and generic `ILogger` types, respectively. Updated API-related objects (`RecActionApi`, `ResultApi`, etc.) to accept and utilize the `ILogger` instance for enhanced logging functionality.
2026-05-19 19:08:30 +02:00
190d41489e Refactor InvokeAsync to return Task and improve docs
The return type of the `InvokeAsync` method has been changed from `Task<bool>` to `Task` for both overloads, removing the boolean return value for success indication.

The `<returns>` XML documentation tag has been removed, and a new `<exception>` tag has been added to document the potential `ReCApiException` thrown when the API responds with a non-success status code.

The implementation now uses `ReCClientHelpers.EnsureSuccessAsync` to handle API responses, replacing the previous `resp.IsSuccessStatusCode` check.

These changes improve clarity and align the method's behavior with standard practices for handling asynchronous operations and exceptions.
2026-05-19 18:57:33 +02:00
dfcf1fb536 Refactor BaseCrudApi methods to improve error handling
Updated `CreateAsync`, `UpdateAsync`, and `DeleteAsync` methods to return `Task` instead of `Task<bool>`. Removed `<returns>` documentation and added `<exception>` tags to indicate that a `ReCApiException` is thrown for non-successful API responses. Replaced `resp.IsSuccessStatusCode` checks with `ReCClientHelpers.EnsureSuccessAsync` to enforce exception-based error handling. These changes align with modern asynchronous error-handling practices.
2026-05-19 18:57:21 +02:00
136c2fcb30 Add EnsureSuccessAsync method for HTTP error handling
Introduced the `EnsureSuccessAsync` method in `ReCClientHelpers.cs` to handle HTTP response validation asynchronously. This method throws a `ReCApiException` for non-success status codes, including detailed error information such as status code, reason phrase, HTTP method, URI, and response body (if available).

Updated `using` directives to support asynchronous operations and cancellation tokens. Removed redundant `#if NETFRAMEWORK` directive around `using System.Net.Http;` and adjusted `using System.Net.Http.Json;` placement for consistency.

Added exception handling for response body read failures to ensure status information is still propagated. Enhanced error reporting for failed HTTP requests.
2026-05-19 18:57:05 +02:00
71defc0e4c Add ReCApiException class for API error handling
A new `ReCApiException` class was introduced in the `ReC.Client` namespace to represent errors returned by the ReC API.

The class includes properties for detailed error information:
- `StatusCode`, `ReasonPhrase`, `ResponseBody`, `Method`, and `RequestUri`.

A constructor was added to initialize these properties. Conditional compilation directives ensure compatibility between .NET Framework and other .NET targets. The class is marked as `[Serializable]` for non-.NET Framework targets.
2026-05-19 18:56:43 +02:00
992395dec3 Ensure proper disposal of resources in InvokeAsync
Updated the `InvokeAsync` method in the `ReC.Client.Api` namespace to use `using` statements for the `content` and `resp` objects. This change ensures proper disposal of these resources, improving memory management and preventing potential leaks. The functional behavior of the method remains unchanged.
2026-05-19 18:44:55 +02:00
82ec333f23 Refactor API methods to return bool for success status
Updated `CreateAsync<T>`, `UpdateAsync<T>`, and `DeleteAsync<T>`
methods to return a `bool` indicating success instead of
`HttpResponseMessage`. Added `using` statements to ensure proper
disposal of HTTP content and response objects. Simplified the
interface for better usability by leveraging `IsSuccessStatusCode`
to determine operation success.
2026-05-19 18:44:44 +02:00
a924e32291 Bump version to 2.4.0-beta in ReC.API.csproj
Updated the project version, assembly version, file version, and informational version from 2.3.0-beta to 2.4.0-beta in the ReC.API.csproj file. This prepares the project for the next beta release.
2026-04-17 15:14:32 +02:00
28a4146069 Auto-detect Content-Type and Accept headers if enabled
Add AutoDetectHeaders option to RecAction config and handler. When enabled, automatically set Content-Type based on body content (JSON or XML) and default Accept to application/json if missing. Log warnings when headers are auto-detected. Improves robustness and makes header detection configurable.
2026-04-17 15:13:33 +02:00
17d40817f2 Update version to 2.3.0-beta
Bump Version, AssemblyVersion, FileVersion, and InformationalVersion to 2.3.0-beta in ReC.API.csproj.
2026-04-17 12:42:04 +02:00
330443d2c9 Add config options for EF Core logging and error details
EnableSensitiveDataLogging and EnableDetailedErrors are now configurable via appsettings.json under the "EfCore" section. Program.cs reads these values from configuration instead of hardcoding them, allowing runtime control of EF Core logging and error detail behavior.
2026-04-17 12:41:45 +02:00
6ca876c762 Improve HTTP header handling and error resilience
Enhance InvokeRecActionViewCommandHandler to robustly handle invalid or non-strict HTTP header values. "Content-Type" and "Authorization" headers are now set using strict parsing with fallback to TryAddWithoutValidation on failure, logging warnings for easier debugging. General headers and API key headers also use this strict-then-fallback approach, making HTTP request construction more tolerant of malformed values and reducing runtime errors.
2026-04-17 12:17:41 +02:00
e89af1cbcd Improve HTTP header handling and add logging to handler
Inject optional ILogger into InvokeRecActionViewCommandHandler for enhanced logging. When adding HTTP headers, catch FormatException and log a warning with relevant context, then fall back to TryAddWithoutValidation. This increases robustness and observability for malformed or non-standard headers.
2026-04-17 12:01:15 +02:00
761fd208e5 Bump version to 2.2.1-beta
Updated Version, AssemblyVersion, and FileVersion in ReC.API.csproj from 2.2.0-beta/2.2.0.0 to 2.2.1-beta/2.2.1.0. No other changes made.
2026-04-17 00:34:40 +02:00
d149cbea3a Improve error handling in query behaviors for SQL execution
Wrap ExecuteScalarAsync in try-catch blocks in BodyQueryBehavior and HeaderQueryBehavior. Throw DataIntegrityException with detailed context if SQL execution fails, aiding in diagnosing malformed or problematic stored SQL queries.
2026-04-17 00:34:01 +02:00
bb2dd4d63b Stricter error handling in BodyQuery and HeaderQuery behaviors
Throw DataIntegrityException when body or header queries return
null, no result, or invalid JSON. Remove ILogger and related
logging from HeaderQueryBehavior for simplification. This change
ensures data integrity issues are surfaced immediately.
2026-04-17 00:23:36 +02:00
4bde1d090f Refactor query behaviors to process action collections
Refactored BodyQueryBehavior and HeaderQueryBehavior to operate on collections of RecActionViewDto instead of single instances. Moved SQL execution and property assignment logic into private helper methods using ADO.NET commands. Improved null checks and logging, and updated type constraints to reflect the new usage. Behaviors now return the modified collection after processing.
2026-04-17 00:15:52 +02:00
6681e56afc Refactor entity selection to use EntityType enum
Replaced string-based entity identifiers in CRUD procedure and command classes with a strongly-typed EntityType enum. Updated all relevant handlers and records to use the new enum property, improving type safety and maintainability. Added necessary using directives and updated documentation comments to reflect these changes.
2026-04-16 17:14:29 +02:00
d61f5ce885 Update validators to use IsInEnum for Entity property
Refactored DeleteObjectProcedureValidator, InsertObjectProcedureValidator, and UpdateObjectProcedureValidator to use .IsInEnum() for validating the Entity property. This replaces custom or hardcoded checks with enum-based validation, improving consistency, maintainability, and robustness across all validators.
2026-04-16 17:13:00 +02:00
6374a5c257 Add EntityType enum and support in StoredProcedureBuilder
Introduced the EntityType enum to represent target entities for stored procedure operations, along with XML documentation and mapping comments. Added EntityTypeExtensions with a ToDbString method for consistent DB string conversion. Updated StoredProcedureBuilder to support adding EntityType parameters, improving type safety and maintainability. Minor formatting and using directive adjustments included.
2026-04-16 17:12:19 +02:00
3b4954d387 Remove FakeRequest class and ResultType enum
Deleted FakeRequest.cs and ResultType.cs, removing the FakeRequest class (with Body and Header properties) and the ResultType enum (Full, OnlyHeader, OnlyBody). These types are no longer needed in the codebase.
2026-04-16 14:55:10 +02:00
42d586604e Add UpdateObjectProcedureValidator with validation rules
Introduced UpdateObjectProcedureValidator using FluentValidation to enforce constraints on UpdateObjectProcedure fields, including ID checks and maximum length restrictions on various properties and nested objects.
2026-04-16 14:50:00 +02:00
4088a52196 Add FluentValidation for ReadResultViewQuery filters
Introduced ReadResultViewQueryValidator to enforce that at least one filter (Id, ActionId, ProfileId, or BatchId) is provided. Also validates that numeric IDs are greater than 0 and BatchId is not empty when present.
2026-04-16 14:48:09 +02:00
58b3c8ec95 Add validator for ReadRecActionViewQuery ProfileId
Introduced ReadRecActionViewQueryValidator using FluentValidation to ensure ProfileId, if provided, is greater than 0. Returns a specific validation message if the rule is violated.
2026-04-16 14:46:07 +02:00
68b3eb53c0 Add ReadProfileViewQueryValidator for Id validation
Introduced ReadProfileViewQueryValidator using FluentValidation to ensure the Id property, if provided, is greater than 0. Includes a custom error message for invalid Id values.
2026-04-16 14:39:26 +02:00
0d9489203f Add InsertResultCommandValidator with validation rules
Introduce InsertResultCommandValidator using FluentValidation to enforce required and value constraints on ActionId and References.BatchId properties, including custom error messages.
2026-04-16 14:38:45 +02:00
0a564d8aa8 Add DeleteObjectProcedureValidator with validation rules
Introduced DeleteObjectProcedureValidator using FluentValidation to ensure Start is greater than 0 and End is greater than or equal to Start, with custom error messages for each rule.
2026-04-16 14:36:43 +02:00
f5b2db0296 Update tests to expect ValidationException for BatchId dupes
Refactored InvokeBatchDuplicateGuardTests to expect and assert
FluentValidation's ValidationException instead of the custom
BadRequestException when a duplicate BatchId is submitted.
Assertions and comments were updated accordingly, and the
DigitalData.Core.Exceptions import was removed. Test logic
remains unchanged.
2026-04-16 14:15:21 +02:00
7a22024624 Remove batch result check from rec action invocation
Removed the check that blocked rec action invocation if results
already existed for a batch. Also updated using directives for
exception handling and logging.
2026-04-16 14:14:19 +02:00
c9cd92a55a Add validator for InvokeBatchRecActionViewsCommand
Introduced InvokeBatchRecActionViewsCommandValidator using FluentValidation. This validator ensures BatchId is provided and checks asynchronously via MediatR that no results exist for the given BatchId before allowing the command to proceed. Provides a clear validation message if results are already present.
2026-04-16 14:13:06 +02:00
93adaba322 Update error message to omit result count in exception
Removed the count of existing results from the BadRequestException
message when invoking rec actions for a batch. The error now simply
states that results are already associated with the batch.
2026-04-16 11:28:46 +02:00
c16cb2a1c4 Bump version to 2.2.0-beta in ReC.API.csproj
Updated project version fields in ReC.API.csproj from 2.1.0-beta to 2.2.0-beta, including Version, AssemblyVersion, FileVersion, and InformationalVersion.
2026-04-16 10:55:59 +02:00
c20162e051 Update build package output path to M: drive
Changed DesktopBuildPackageLocation in IISProfile.pubxml to output the build package to the M:\App&Service directory instead of the P: drive. This ensures published packages are stored in the new target location.
2026-04-16 10:53:30 +02:00
70c2f7342d Refactor result view query to support LastBatch retrieval
Replaced Last with LastBatch in ReadResultViewQuery to enable fetching all results from the most recent batch. Updated handler logic and tests accordingly, and added GetLastBatchEntitiesAsync to retrieve entities by latest BatchId.
2026-04-16 10:49:15 +02:00
a10f917084 Add tests for batch duplicate guard in rec action invoke
Added InvokeBatchDuplicateGuardTests to verify that invoking batch rec actions with an existing BatchId throws BadRequestException, while using a new BatchId does not trigger the duplicate guard. Tests use MediatR ISender and real database data for integration coverage. Added necessary using directives.
2026-04-16 10:40:34 +02:00
e1c3f74cd4 Prevent rec action invocation if batch has results
Add validation in InvokeRecActionViewsCommandHandler to check
for existing results before invoking rec actions for a batch.
Throw BadRequestException if results are found to avoid
duplicate processing. Add necessary using statements for
exceptions and queries.
2026-04-16 10:22:31 +02:00
e45aeea2b9 Add BatchId filter to ReadResultViewQuery and handler
Added an optional BatchId property to ReadResultViewQuery to enable filtering by BatchId. Updated ReadResultViewQueryHandler to apply this filter when BatchId is provided. Also adjusted the order of IncludeAction logic for clarity.
2026-04-16 10:20:57 +02:00
38f91aae84 Add AnyResultViewQuery to check for matching ResultView
Introduced AnyResultViewQuery and its handler to determine if any ResultView entity exists matching optional filters (Id, ActionId, ProfileId, BatchId). The handler builds the query dynamically and uses AnyAsync for efficient existence checks.
2026-04-16 10:20:18 +02:00
9bb5c97df6 Require non-null References for batch rec action invoke
Enforce non-nullable References in RecActionController and InvokeBatchRecActionViewsCommand. Update tests to always provide References and add missing using directive. Improves type safety and ensures consistent reference handling.
2026-04-16 10:02:34 +02:00
d8c7499436 Add BatchId and AddedWho to DTO; make BatchId nullable
Added BatchId and AddedWho properties to ResultViewDto. Changed BatchId in ResultView from required to nullable to align with DTO and support optional batch IDs.
2026-04-16 09:58:46 +02:00
6d86760354 Make BatchId in ResultView a required string
Changed the BatchId property in the ResultView class from a nullable string to a required non-nullable string. This ensures that BatchId must always be provided when creating a ResultView instance, improving data integrity.
2026-04-16 09:55:57 +02:00
6b1daf77cb Make References required in InsertResultCommand
Changed the References property in InsertResultCommand from a nullable type to required. References must now always be provided and cannot be null when creating an InsertResultCommand instance. This enforces stricter data integrity for command creation.
2026-04-16 09:55:26 +02:00
d3d5ebac61 Rename InvokeReferencesDto to InvokeReferences project-wide
Replaced all usages of InvokeReferencesDto with InvokeReferences across controllers, commands, and DTOs. This change standardizes the reference type naming by removing the "Dto" suffix, with no changes to the structure or behavior.
2026-04-16 09:51:15 +02:00
b1924f2a4a Make References and BatchId required for RecAction invoke
Updated InvokeRecActionViewCommand and InvokeReferencesDto to require non-null References and BatchId. Updated RecActionApi.InvokeAsync to require InvokeReferences and added an overload accepting batchId for convenience. This enforces stricter input validation and aligns client and backend requirements.
2026-04-16 09:50:52 +02:00
c27ed1e744 Change RecStatus enum type from short to byte
Reduced the underlying type of the RecStatus enum from short to byte to decrease memory usage. No changes were made to the enum values or their definitions.
2026-04-15 17:02:28 +02:00
9eb54565cb Make Info non-nullable in InsertResultCommand
Changed the Info property from short? to short in InsertResultCommand,
making it a required field and ensuring it cannot be null. This enforces
that all InsertResultCommand instances must provide a value for Info.
2026-04-15 16:57:45 +02:00
05dfb6f424 Update pRESULT_STATUS_ID to TinyInt in procedure handlers
Changed SQL parameter type for pRESULT_STATUS_ID from SmallInt to TinyInt in both InsertObjectProcedureHandler and UpdateObjectProcedureHandler to align with database schema and ensure type consistency.
2026-04-15 16:40:16 +02:00
cf6c90ad05 Auto-set SqlDbType.DateTime for DateTime parameters
Automatically assigns SqlDbType.DateTime to parameters when the value is a DateTime and no dbType is specified. This ensures correct SQL type mapping for DateTime values in stored procedures.
2026-04-15 15:31:52 +02:00
4a9c4341c2 Add BatchId to InvokeReferences; clean up property layout
Added BatchId property to InvokeReferences for batch identification.
Refactored Reference3-5 property declarations for clarity and
consistency by removing unnecessary line breaks.
2026-04-15 14:36:36 +02:00
ead12b6095 Add pRESULT_BATCH_ID parameter to update procedure
Added support for the pRESULT_BATCH_ID parameter in the database command, sourcing its value from request.Result.References?.BatchId. This enables batch ID information to be included in update operations when available.
2026-04-15 14:35:56 +02:00
3c7fcb71c0 Add pRESULT_BATCH_ID parameter to insert procedure
Added support for the pRESULT_BATCH_ID parameter in the database command, allowing the batch ID from request.Result?.References?.BatchId to be included when inserting objects. This enables tracking and referencing of batch operations.
2026-04-15 14:35:37 +02:00
0b01b4a658 Add BatchId property to InvokeReferencesDto
Added an optional BatchId property to the InvokeReferencesDto record, enabling support for batch identification alongside existing reference fields.
2026-04-15 14:34:44 +02:00
8d511ec81a Add BatchId property to ResultView class
Added the BatchId property to the ResultView class, mapping it to the "BATCH_ID" column in the database. This property is of type string? and allows tracking of batch identifiers in result records.
2026-04-15 14:33:54 +02:00
685c5abca7 Remove HTTP status formatting/parsing from ResultView
Removed FormatHttpStatusInfo, ParseHttpStatusInfo, and the related Regex from the ResultView class. These methods are no longer needed and have been deleted to simplify the codebase.
2026-04-15 14:33:06 +02:00
b7aea848a9 Add InvokeReferences support to InvokeAsync method
Added InvokeReferences class for passing optional reference values (Reference1–Reference5) when invoking a profile. Updated InvokeAsync to accept and serialize these references in the POST request. Improved XML docs to reflect the new parameter.
2026-04-15 13:57:42 +02:00
e5eb0f19e7 Add optional references to RecAction invoke endpoint
The Invoke action in RecActionController now accepts an optional InvokeReferencesDto from the request body. This enables clients to provide reference values that are passed through to all result records. The method signature, XML documentation, and command dispatch have been updated to support this enhancement.
2026-04-15 13:37:40 +02:00
859ff5902e Include References in InsertResultCommand for all results
Add request.References to InsertResultCommand in both
PreprocessingBehavior and PostprocessingBehavior, ensuring
references are recorded with both success and error results.
2026-04-15 13:33:39 +02:00
42789567f0 Refactor UpdateResultDto to use InvokeReferencesDto
Replaced five separate reference string properties in UpdateResultDto with a single References property of type InvokeReferencesDto for improved structure and maintainability. Added the necessary using directive for the new type.
2026-04-15 13:32:17 +02:00
46eef255ca Add References support to batch rec action commands
Added an optional References property to InvokeBatchRecActionViewsCommand. Updated the handler to pass this property to each individual InvokeRecActionViewCommand. Also included the ReC.Domain.Constants namespace for required types.
2026-04-15 13:31:54 +02:00
aae42949b6 Refactor InsertResultCommand references into DTO
Replaced Reference1–5 string properties in InsertResultCommand with a single References property of type InvokeReferencesDto? for better maintainability. Added necessary using directive for the new DTO.
2026-04-15 13:14:17 +02:00
bdf273c8e1 Add support for references in InvokeRecAction commands
Introduced the InvokeReferencesDto record to encapsulate up to five optional reference strings. Updated InvokeRecActionViewCommand to include an optional References property. Modified InvokeRecActionViewCommandHandler to pass these references to InsertResultCommand, ensuring reference data is associated with command execution and results.
2026-04-15 12:57:13 +02:00
ba8ab28b03 Refactor: group Result reference fields into References obj
Refactored InsertObjectProcedureHandler and UpdateObjectProcedureHandler to access RESULT_REFERENCE1-5 via the new Result.References object instead of individual fields. This improves encapsulation and organizes related reference data within the Result model.
2026-04-15 12:54:51 +02:00
4cc8d22756 Update InsertResultCommand Info property to use integer
Changed the Info property in InsertResultCommand initialization from a string ("200") to an integer (200) to match the expected data type. This ensures type consistency in the test setup.
2026-04-15 11:48:38 +02:00
2a4378eb9a Set Info to numeric HTTP status code in result object
Changed the Info property to store the raw (short) HTTP status code
from response.StatusCode instead of using the formatted output from
ResultView.FormatHttpStatusInfo. This provides a simpler, numeric
representation of the HTTP status in the result.
2026-04-15 11:48:20 +02:00
cb5bbfb722 Change Info to short? and update DB param to pRESULT_INFO_ID
Changed UpdateResultDto.Info from string? to short? for type safety. Updated UpdateObjectProcedureHandler to use pRESULT_INFO_ID with SqlDbType.SmallInt, reflecting the new type.
2026-04-15 11:46:40 +02:00
2736a78d4f Change Info from string to short and update parameter name
Changed the Info property in InsertResultCommand from string? to short?.
Renamed the related parameter in InsertObjectProcedureHandler from pRESULT_INFO to pRESULT_INFO_ID and set its type to SqlDbType.SmallInt to match the new property type.
2026-04-15 11:45:46 +02:00
ddb8b2673e Add support for five new RESULT_REFERENCE parameters
Added pRESULT_REFERENCE1 through pRESULT_REFERENCE5 to the stored procedure call, mapping them to the corresponding Reference1–Reference5 properties in request.Result. This allows passing additional reference data with the procedure execution.
2026-04-14 20:43:43 +02:00
a70aee6e28 Add Reference1-5 properties to UpdateResultDto
Added five optional string properties (Reference1 through Reference5) to UpdateResultDto for storing additional reference information related to update results. This enhances the DTO's flexibility for carrying extra context as needed.
2026-04-14 20:43:01 +02:00
f329543793 Add support for five new RESULT_REFERENCE parameters
Added pRESULT_REFERENCE1 through pRESULT_REFERENCE5 to the procedure handler, mapping them from the corresponding Reference1-5 properties in request.Result. This enables passing additional reference data to the stored procedure.
2026-04-14 20:42:41 +02:00
645891150c Add Reference1-5 properties to InsertResultCommand
Added five optional string properties (Reference1-5) to the InsertResultCommand record to support storing additional reference information with each command instance. This enhances flexibility for passing extra data as needed.
2026-04-14 20:41:53 +02:00
95cb34394c Add ProfileTypeName property to RecActionView
Added the ProfileTypeName string property to RecActionView, mapped to the "PROFILE_TYPE" column, to store the profile type name alongside the existing ProfileType property.
2026-04-14 20:40:16 +02:00
83d6832236 Add InfoId and Reference fields to ResultView model
Added InfoId and Reference1–Reference5 properties to the ResultView class, each mapped to corresponding database columns. These fields enable storage and retrieval of additional result-related information and references.
2026-04-14 20:40:00 +02:00
e816340755 Improve HTTP status info formatting in result views
Replaced the simple status code string with ResultView.FormatHttpStatusInfo for the Info field, providing more descriptive HTTP status information. Added the ReC.Domain.Views namespace import to support this change.
2026-04-02 21:02:32 +02:00
64e8e2a5cc Add HTTP status formatting/parsing to ResultView
Added FormatHttpStatusInfo and ParseHttpStatusInfo methods to ResultView for converting between HttpStatusCode values and "statusCode statusName" strings. Included supporting Regex and necessary using directives.
2026-04-02 21:02:15 +02:00
0edf2626a7 Add Info property to InsertResultCommand in test
The InsertResultProcedure_runs_via_mediator test now sets the Info property to "200" when initializing InsertResultCommand, ensuring the command includes this field during testing.
2026-04-02 20:39:05 +02:00
1d16276a8a Add InfoDetail property to InsertResultCommand
Added a nullable string property InfoDetail to InsertResultCommand to allow storing additional detailed information with each result. No other changes were made.
2026-04-02 20:38:55 +02:00
4eae092031 Update result handling and error status in command handler
Removed unused statusCode variable and now store HTTP status code as a string in the Info field. Changed exception handling to set Status to RecStatus.Error instead of RecStatus.Failed.
2026-04-02 20:38:01 +02:00
ce7fe03525 Add InfoDetail property to ResultView model
Added the InfoDetail property to the ResultView class, mapping it to the RESULT_INFO_DETAIL column in the database. This allows for storing and retrieving additional result detail information.
2026-04-02 20:37:46 +02:00
a93780df5c Add Info, InfoDetail, and Error to UpdateResultDto
Extended UpdateResultDto with Info, InfoDetail, and Error fields. Updated UpdateObjectProcedureHandler to pass these new properties as parameters to the stored procedure, enabling richer result and error reporting in database updates.
2026-04-02 20:37:29 +02:00
d7a2a01421 Add pRESULT_INFO_DETAIL param to InsertObjectProcedureHandler
Added support for the pRESULT_INFO_DETAIL parameter in the database command, mapping it from request.Result?.InfoDetail to enable passing detailed result information to the stored procedure.
2026-04-02 20:36:51 +02:00
329e441ede Standardize InsertResultCommand status and info fields
Updated InsertResultCommand usage to replace QuerySuccess with OK and Failed with Error for status reporting. Changed Info to InfoDetail for both preprocessing and postprocessing behaviors to ensure consistent result and error handling.
2026-04-02 20:36:35 +02:00
1ad7ff3b34 Add InfoDetail property to ResultViewDto
Added a nullable string property InfoDetail with a public setter to the ResultViewDto record for storing additional detailed information. No changes were made to the existing Error property.
2026-04-02 20:36:03 +02:00
bcfbd851bd Simplify RecStatus to OK/Error and update extensions
Refactored the RecStatus enum to only include OK and Error values,
removing all HTTP status code mappings and related documentation.
Updated RecStatusExtensions to map HTTP 2xx codes to OK and all
others to Error, and removed obsolete conversion and success logic.
This clarifies the separation between general operation status and
protocol-specific details.
2026-04-02 20:35:48 +02:00
2e157656a7 Update validator registration assembly in DI setup
Changed validator registration to use the assembly containing InsertObjectProcedureValidator instead of AuthScopedValidator, ensuring the correct set of validators are included in the dependency injection container.
2026-03-30 15:36:18 +02:00
8042a6f898 Update project version to 2.1.0-beta
Bump version numbers in ReC.API.csproj from 2.0.2-beta to 2.1.0-beta, including Version, AssemblyVersion, FileVersion, and InformationalVersion fields. No other changes were made.
2026-03-30 14:53:01 +02:00
f25fc627fe Update AutoMapper to version 16.1.1
Upgraded the AutoMapper NuGet package in ReC.Application.csproj from version 15.1.0 to 16.1.1 to ensure compatibility with the latest features and bug fixes. No other dependencies were changed.
2026-03-30 14:48:17 +02:00
d6af24cd91 Remove PlaceholderResolutionException class
Deleted the PlaceholderResolutionException class and its namespace. This exception was previously used for unresolved placeholders due to missing properties. All related properties and custom messages have been removed.
2026-03-30 14:33:23 +02:00
bb5eac023c Change ReplacePlaceholders to return NULL for unresolved
Previously, ReplacePlaceholders threw PlaceholderResolutionException when a placeholder could not be resolved. Now, unresolved placeholders are replaced with "NULL" instead. All exception references and related tests have been updated to reflect this new behavior. Documentation has also been revised accordingly.
2026-03-30 14:33:13 +02:00
77baf395ce Update ReplacePlaceholders mapping to use single argument
Removed src.Profile from ReplacePlaceholders calls in DtoMappingProfile for PreprocessingQuery and PostprocessingQuery mappings, now passing only src as the argument. This simplifies the mapping logic and aligns with the updated method signature.
2026-03-30 14:32:31 +02:00
6c9eab6df6 Refactor ResultViewDto status and add info/error fields
Replaced StatusCode with a RecStatus Status property in ResultViewDto. Added Info and Error string properties to provide additional result details. Imported ReC.Domain.Constants for RecStatus usage.
2026-03-30 13:21:48 +02:00
c64794755d Remove "EXEC" from stored procedure call in builder
Standardize StoredProcedureBuilder usage by omitting the "EXEC" keyword when specifying the procedure name. This ensures consistent and correct invocation of stored procedures.
2026-03-30 13:21:11 +02:00
de2185bf0a Specify byte as underlying type for ResultType enum
Changed ResultType enum declaration to explicitly use byte as its underlying type for improved memory efficiency and clarity.
2026-03-30 13:20:40 +02:00
fde9735b27 Remove redundant Result property validation in InsertObject
Removed the rule requiring Result to have StatusId, Info, or Error set. Now only ResultActionId is required when Result is present.
2026-03-30 13:20:21 +02:00
0342b9e0c6 Unify error status code as RecStatus.Failed
Renamed RecStatus.QueryFailed to RecStatus.Failed and updated all usages and documentation to reflect its broader purpose as a general failure code for any operation, not just SQL queries. Improved consistency in error handling and status reporting across the codebase.
2026-03-30 11:55:58 +02:00
47698b9046 Rename ToStatus to ToRecStatus for HttpStatusCode conversion
Standardize extension method naming by renaming ToStatus to ToRecStatus for converting HttpStatusCode to RecStatus across the codebase. Updated all usages and related tests for consistency and clarity.
2026-03-30 11:40:26 +02:00
a03d21ebc6 Rename StatusExtensions to RecStatusExtensions for clarity
Renamed the StatusExtensions class and related XML documentation references to RecStatusExtensions to better reflect its association with the RecStatus enum and improve code clarity and consistency.
2026-03-30 11:39:37 +02:00
acff0aca89 Rename Status enum to RecStatus across the codebase
Refactored all usages of the Status enum to RecStatus to improve clarity and prevent naming conflicts with other status enums (e.g., HTTP status codes). Updated command handlers, behaviors, data models, and extension methods to use RecStatus, and adjusted related serialization logic accordingly. This makes the domain-specific status handling more explicit and maintainable.
2026-03-30 11:35:22 +02:00
ce0e53baf6 Update test for InsertResultCommand Status property change
Refactored InsertResultProcedure_runs_via_mediator to use the new Status property (set via HttpStatusCode.OK.ToStatus()) instead of the old StatusId integer. Added necessary using directives to support updated types and methods.
2026-03-30 11:33:42 +02:00
620c0eff22 Add ToStatus extension for HttpStatusCode to Status conversion
Introduced a ToStatus extension method in StatusExtensions to enable direct conversion from HttpStatusCode to Status by casting. This simplifies mapping between HTTP status codes and internal Status values.
2026-03-30 11:33:28 +02:00
68f4486fa1 Make Status required in InsertResultCommand
Changed the Status property in InsertResultCommand from nullable to required, ensuring that a Status value must always be provided when creating an instance. This improves data integrity and prevents accidental omission of the Status field.
2026-03-30 11:33:08 +02:00
2b5e63cb45 Update result status handling in InsertResultCommand
Replaced StatusId with Status property in InsertResultCommand, mapping HTTP status codes to application-specific status enums using ToStatus(). Exception handling now sets Status to QueryFailed. Removed usage of StatusId.
2026-03-30 11:22:57 +02:00
e9e697fa0d Update to use Result.Status instead of StatusId in insert proc
Changed the parameter for "pRESULT_STATUS_ID" from request.Result?.StatusId to request.Result?.Status in InsertObjectProcedureHandler. This aligns with updates to the data model or business logic, ensuring the correct status property is used when inserting objects.
2026-03-30 11:22:27 +02:00
606eccb855 Add Status to InsertResultCommand for query outcome reporting
Enhance PostprocessingBehavior and PreprocessingBehavior to set the Status property on InsertResultCommand. Status is now set to QuerySuccess on successful execution and QueryFailed on exceptions, improving clarity of query execution results.
2026-03-30 11:11:51 +02:00
3146acfa45 Refactor InsertResultCommand to use Status enum
Replaced StatusId (short?) with Status (Status?) in InsertResultCommand, moving from a numeric status identifier to a more descriptive or structured status representation from ReC.Domain.Constants.
2026-03-30 11:11:28 +02:00
f363872e7a Refactor ResultView: replace StatusCode with Status object
Replaced the short? StatusCode property in ResultView with a Status object to provide a more descriptive representation of status information. This change improves code clarity and supports richer status handling.
2026-03-30 10:51:58 +02:00
ed4683323d Change Status enum underlying type to short
Explicitly set the Status enum's underlying type to short instead of the default int to optimize memory usage and clarify intent. No other changes were made.
2026-03-30 10:50:33 +02:00
4aeef10ef7 Add StatusExtensions with HTTP status mapping methods
Added StatusExtensions.cs with extension methods for Status and HttpStatusCode:
- ToHttpStatusCode maps Status to nullable HttpStatusCode if possible.
- IsSuccess checks if a Status or HttpStatusCode represents a successful response.
- Handles both direct Status values and those convertible to HTTP codes.
2026-03-30 10:41:39 +02:00
e04e90d8c6 Add Status enum for HTTP and SQL operation status codes
Introduced Status enum in ReC.Domain.Constants to unify status reporting for both HTTP responses and SQL query execution results. The enum includes all standard HTTP status codes and custom codes for SQL query success/failure, with detailed documentation for each value. This standardizes status handling across web and database operations.
2026-03-30 10:41:09 +02:00
93b5f976d3 Refactor stored procedure SQL construction and execution
Centralize stored procedure SQL generation in StoredProcedureBuilder,
allowing handlers to specify procedure name and return variable.
Removes manual SQL string building from DeleteObjectProcedure and
UpdateObjectProcedure handlers, reducing boilerplate and improving
maintainability.
2026-03-30 09:30:07 +02:00
b66a49f74d Refactor: add StoredProcedureBuilder for SQL calls
Introduce StoredProcedureBuilder to centralize and simplify the construction of SQL stored procedure calls and parameter lists. Refactor DeleteObjectProcedureHandler, InsertObjectProcedureHandler, and UpdateObjectProcedureHandler to use this utility, replacing manual StringBuilder and parameter management. Improves code readability, reduces duplication, and standardizes parameter handling, including output parameters.
2026-03-27 15:11:16 +01:00
70dc52139d Refactor SQL param and command construction in procedures
Refactored InsertObject, UpdateObject, and DeleteObject procedure handlers to dynamically build SQL command strings and parameter lists. Introduced local Add functions to include only non-null parameters, improving code clarity and reducing unnecessary SQL parameter passing. The logic for handling stored procedure results and exceptions remains unchanged.
2026-03-27 14:58:56 +01:00
210ed9be8d Refactor SQL construction with StringBuilder for clarity
Refactored DeleteObjectProcedureHandler, InsertObjectProcedureHandler, and UpdateObjectProcedureHandler to use StringBuilder for building SQL command strings. This improves readability and maintainability without changing the logic or parameters. Added System.Text using directives as needed.
2026-03-27 14:54:27 +01:00
b2544b64e3 Refactor: use named params in SP calls, cleanup usings
Updated Delete, Insert, and Update object procedure handlers to use named parameters in SQL stored procedure calls instead of positional parameters, improving clarity and reducing risk of misalignment. Also removed unused using statements from UpdateObjectProcedure.cs.
2026-03-27 14:21:45 +01:00
0b1e0d25ca Explicitly set SqlDbType.TinyInt for relevant SQL parameters
Updated InsertObjectProcedureHandler and UpdateObjectProcedureHandler to explicitly specify SqlDbType.TinyInt for parameters representing TINYINT columns. Also improved handling of nullable and enum values for these parameters to ensure correct type casting and null handling. This enhances type safety and prevents potential SQL type conversion issues.
2026-03-27 14:19:19 +01:00
c1027abfc6 Specify SqlDbType.SmallInt for relevant SqlParameters
Explicitly set SqlDbType.SmallInt for parameters related to small integer fields in UpdateObjectProcedureHandler. This improves type safety and prevents potential data conversion issues by ensuring correct parameter types are sent to SQL Server.
2026-03-27 13:30:28 +01:00
40c8fa359c Specify SqlDbType.SmallInt for relevant SqlParameters
Explicitly set SqlDbType.SmallInt for parameters related to endpoint params, SQL connection, profile language, and endpoint params group. This ensures correct type handling and prevents potential data conversion issues with the database.
2026-03-27 13:29:43 +01:00
1375f5f0e4 Set @pRESULT_STATUS_ID param type to SmallInt explicitly
Explicitly specify SqlDbType.SmallInt for the @pRESULT_STATUS_ID parameter when calling the stored procedure. This change ensures correct type handling and helps prevent potential SQL type mismatches or conversion errors.
2026-03-27 13:13:36 +01:00
29bc0cf8b5 Relax RESULT validation to allow StatusId, Info, or Error
Previously, RESULT required a non-null StatusId. Now, validation passes if at least one of StatusId, Info, or Error is provided, making the requirements more flexible.
2026-03-27 09:46:43 +01:00
c8b264cef6 Improve null safety in InsertObjectProcedureValidator
Updated validation logic to use null-forgiving operators and added null checks for nested properties in When clauses. This ensures rules are only applied when parent objects are not null, preventing possible null reference errors and improving overall robustness.
2026-03-27 09:40:33 +01:00
078525d85d Refactor RecAction invoke endpoint to use profileId param
Changed the HTTP POST route to accept a profileId instead of a command object, updated XML documentation accordingly, and refactored the method to construct the command internally using the provided profileId before sending it to the mediator. This improves clarity and API usability.
2026-03-27 09:26:13 +01:00
b3dfdd1e5c Update namespaces to Common.Dto for DTO-related files
Refactored PlaceholderExtensions, DtoMappingProfile, and InvokeActionTests
to use the ReC.Application.Common.Dto namespace instead of
ReC.Application.Common.Behaviors.Action. Updated using directives and
namespaces to improve code organization for DTO-related logic.
2026-03-26 16:52:54 +01:00
bd78ada686 Remove all DTO class definitions from application
Deleted the contents of several DTO files, including ConnectionDto, EndpointAuthDto, EndpointDto, EndpointParamDto, OutResDto, ProfileDto, and RecActionDto. These files previously contained record definitions for data transfer objects used throughout the application. All related code, including properties and using directives, has been removed, leaving the files empty.
2026-03-26 15:48:49 +01:00
2b4773a4c0 Remove Root and ActionId from ResultViewDto
Removed the Root (OutResDto?) and ActionId (long?) properties from the ResultViewDto record to simplify its structure and remove unused fields.
2026-03-26 15:48:35 +01:00
ff7d6c99ae Update RecActionViewDto mapping and add Profile property
Refactored DtoMappingProfile to pass both the source object and its Profile to ReplacePlaceholders when mapping queries. Added a nullable Profile property to RecActionViewDto to include full profile details in the DTO.
2026-03-26 15:48:06 +01:00
fa438e70cb Allow ReplacePlaceholders to handle null objects safely
Updated ReplacePlaceholders to accept nullable objects and skip nulls during placeholder resolution, preventing NullReferenceExceptions when nulls are passed in the objects array.
2026-03-26 15:32:00 +01:00
4931d3b8aa Map queries with placeholders replaced in DTOs
Updated RecActionView to RecActionViewDto mapping to replace placeholders in PreprocessingQuery and PostprocessingQuery using ReplacePlaceholders. Added necessary using directive for the extension method.
2026-03-26 15:28:08 +01:00
6aae26bfb6 Update using directive to new Action namespace
Replaced the using directive for InvokeAction with Action in InvokeActionTests.cs to reflect recent namespace reorganization. No other changes were made.
2026-03-26 15:23:30 +01:00
38d8ef6e93 Update namespace in PlaceholderExtensions.cs
Changed namespace from ReC.Application.Common.Behaviors.InvokeAction to ReC.Application.Common.Behaviors.Action for consistency. No other code changes were made.
2026-03-26 14:58:01 +01:00
7bc5428bd4 Refactor: move query behaviors to Action namespace
Updated the namespaces for BodyQueryBehavior and HeaderQueryBehavior from ReC.Application.Common.Behaviors to ReC.Application.Common.Behaviors.Action. Adjusted related imports in DependencyInjection.cs to reflect this change for improved code organization.
2026-03-26 14:40:50 +01:00
c405f369ac Add unit tests for InvokeAction placeholder replacement
Introduce InvokeActionTests.cs with comprehensive tests for:
- Placeholder replacement logic (ReplacePlaceholders) across int, bool, string, DateTime, DateTimeOffset types, multiple placeholders, and various prefix formats.
- Value extraction by column name (GetValueByColumnName), including models with and without [Column] attributes.
- Exception handling for unresolvable placeholders and invalid input scenarios.
These tests ensure robust coverage of both normal and error cases.
2026-03-26 14:37:58 +01:00
c2e073dade Add ReplacePlaceholders for SQL-style string interpolation
Introduce ReplacePlaceholders to PlaceholderExtensions, enabling replacement of {#...#COLUMN_NAME} placeholders in strings with property values from provided objects. Uses a generated regex for matching and converts values to SQL-compatible literals. Throws PlaceholderResolutionException if a column cannot be resolved. Refactored class to partial to support regex generation.
2026-03-26 14:37:29 +01:00
7a11ac3635 Add PlaceholderResolutionException for unresolved placeholders
Introduced PlaceholderResolutionException in the ReC.Application.Common.Exceptions namespace. This exception provides detailed context when a placeholder cannot be resolved due to a missing property with a specific column name, including the placeholder, column name, and input string.
2026-03-26 14:36:35 +01:00
a91e3264b4 Remove Action folder reference from project file
The <Folder Include="Common\Behaviors\Action\" /> entry was removed from ReC.Application.csproj, so the folder is no longer explicitly included in the project structure. No code or project references were affected.
2026-03-26 14:35:39 +01:00
2ae5251550 Rename class and update namespace for placeholder logic
Renamed the ReflectionExtensions class to PlaceholderExtensions and moved it from the ReC.Domain.Extensions namespace to ReC.Application.Common.Behaviors.InvokeAction to better reflect its purpose and location within the project structure.
2026-03-26 13:48:16 +01:00
56730c0d4e Make GetValueByColumnName a generic extension method
Refactored GetValueByColumnName to use a generic type parameter constrained to class types. This enhances type safety and enables better type inference and static analysis when accessing property values by column name.
2026-03-26 13:42:45 +01:00
d8aa032a57 Add ReflectionExtensions for property lookup by column name
Introduced a static ReflectionExtensions class with a GetValueByColumnName extension method to retrieve property values by their [Column] attribute name. Also removed an unused folder reference from the project file.
2026-03-26 13:16:04 +01:00
e96773f3c4 Remove DbModelConfigurationException and related logic
Removed the DbModelConfigurationException class and all its usages from DbModelOptions and EntityOptions. Indexers in these classes no longer throw this exception when configuration is missing. Updated the project file to include the Common\Options\DbModel\ folder.
2026-03-26 10:34:24 +01:00
06e92b588f Remove DbModel configuration and related JSON file
Removed all references to DbModel configuration from Program.cs and RecApplicationTestBase.cs. Deleted appsettings.DbModel.json, eliminating custom entity and column mapping definitions. The application no longer loads or uses DbModel configuration from JSON.
2026-03-26 10:34:05 +01:00
b922cbbb30 Remove ConfigureDbModel from dependency injection setup
Eliminated all references to ConfigureDbModel in DependencyInjection.cs, including related imports, configuration methods, and required service tracking. Dependency injection configuration is otherwise unchanged.
2026-03-26 10:32:24 +01:00
6c56375e3e Refactor RecDbContext to remove dynamic view mapping
Removed dependency on DbModelOptions and IOptions. Entity-to-view mappings are now hardcoded in OnModelCreating with fixed view names and schema. Property-to-column mappings now use EF Core conventions. Simplifies configuration and maintenance, but reduces flexibility for schema changes. Entity relationships remain explicitly configured.
2026-03-26 10:31:48 +01:00
fa9aa23f32 Add EF Core data annotations to view models
Added [Key], [Column], and [Table] attributes to ProfileView, RecActionView, and ResultView classes to explicitly map properties to database columns and views. Expanded model properties for clearer schema alignment and improved maintainability with Entity Framework Core.
2026-03-26 10:30:00 +01:00
b86d0c0f99 Add [Column] mapping attributes to query result classes
Added [Column] attributes to properties in BodyQueryResult, HeaderQueryResult, and InsertObjectResult to explicitly map them to their respective database columns. Also included necessary using directives for DataAnnotations.Schema to support these mappings. This enhances ORM compatibility and ensures correct property-to-column mapping.
2026-03-26 10:28:52 +01:00
b0d89ceba4 Remove properties from RecActionOptions class
Removed AddedWho and UseHttp1ForNtlm properties from RecActionOptions, leaving the class empty. This change cleans up unused configuration options.
2026-03-25 16:13:32 +01:00
11ebfdd21e Refactor DbModelOptions to use indexers for lookups
Replaced GetEntity and GetColumn extension methods with indexers
on DbModelOptions and EntityOptions. Updated all usages to use
the new indexer syntax, improving code clarity and error handling
for missing entity or column configurations.
2026-03-25 16:10:50 +01:00
1467acc4a1 Refactor DbModel options to use generic entity mapping
Replaces strongly-typed view options classes with a generic EntityOptions class and a dictionary-based configuration for entity-to-view and property-to-column mappings. Updates appsettings.DbModel.json to match the new structure. Refactors RecDbContext to use extension methods for mapping configuration. Removes obsolete options classes and simplifies exception handling for missing mappings. This change improves flexibility and maintainability of database view configuration.
2026-03-25 15:25:29 +01:00
e761fbd1ca Add DbModel config to Rec services setup
Added options.ConfigureDbModel to the AddRecServices configuration, enabling Rec services to use settings from the "DbModel" section of the app configuration for enhanced database model customization.
2026-03-25 13:30:12 +01:00
2e83d4a24a Make RecDbContext model mapping fully configurable
Refactored RecDbContext to use DbModelOptions injected via IOptions, replacing hardcoded view and column names with configuration-driven mappings. This enables dynamic control of entity-to-database mapping through appsettings.json, improving flexibility and maintainability.
2026-03-25 13:29:29 +01:00
37ba85d681 Add support for configuring DbModelOptions via DI
Introduce ConfigureDbModel methods to DependencyInjection for setting up DbModelOptions from code or configuration. Update required services tracking and add usage in Program.cs to enable structured DbModelOptions injection.
2026-03-25 13:26:54 +01:00
a46cd08122 Refactor DbModel options to use explicit, typed classes
Replaced the old generic, dictionary-based entity configuration system with a new, strongly-typed options structure under ReC.Application.Common.Options.DbModel. Introduced specific options classes for each major database view and result type, each with clear property mappings and defaults. Added a ViewOptions class for view/schema info. Removed all legacy entity mapping infrastructure, resulting in a more maintainable and type-safe configuration approach.
2026-03-25 12:53:10 +01:00
3d46901af5 Add DbModel view mappings to appsettings.DbModel.json
Added a new "DbModel" section to appsettings.DbModel.json, defining property-to-column mappings for RecActionView, ProfileView, ResultView, HeaderQueryResult, BodyQueryResult, and InsertObjectResult. This centralizes and standardizes database view and query result configurations.
2026-03-25 12:44:12 +01:00
90e8adbd36 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.
2026-03-25 11:43:30 +01:00
aef59def7f Add ResultType to InsertResultCommand in all handlers
Added the Type property (ResultType) to every InsertResultCommand sent in PostprocessingBehavior, PreprocessingBehavior, and InvokeRecActionViewCommand. This ensures each result now includes its context (Post, Pre, or Main), both in normal and exception flows.
2026-03-25 11:17:38 +01:00
d7783b6e81 Make InsertObjectProcedure properties nullable, require ResultType
Updated InsertObjectProcedure to make related command properties nullable and removed default initializations. Updated handler to use null-conditional access for these properties. Changed InsertResultCommand.Type to required and updated tests accordingly. Improves null safety and clarifies required fields.
2026-03-25 11:17:21 +01:00
4126f984e4 Expand and refactor OutResDto for richer data support
Refactored OutResDto to include additional properties such as Action, Profile, Status, and Type, and made several fields nullable. This enhances flexibility and allows for more comprehensive and optional data representation in API responses.
2026-03-25 11:06:07 +01:00
0e2328c287 Add support for Result.Info, Error, and Type in insert proc
Extended InsertObjectProcedureHandler to include Result.Info, Result.Error, and Result.Type in both the SQL parameter list and the command string. This ensures these fields are correctly passed to and handled by the stored procedure.
2026-03-25 11:02:56 +01:00
e04e054151 Add optional ResultType to InsertResultCommand
Added a nullable Type property of ResultType to InsertResultCommand for enhanced result categorization. Also included the required using directive for ReC.Domain.Constants.
2026-03-25 11:02:35 +01:00
6082a637fe Add mapping for result type fields in RecDbContext
Added entity property mappings for RESULT_TYPE_ID (Type) and RESULT_TYPE (TypeName) columns in RecDbContext to support storing and retrieving result type information.
2026-03-25 11:00:12 +01:00
93669a6358 Add Type and TypeName to ResultView model
Imported ResultType and added Type (ResultType?) and TypeName (string?) properties to ResultView to support representing result types alongside status information.
2026-03-25 10:59:33 +01:00
fecd9219b4 Add ResultType enum to ReC.Domain.Constants
Introduced a new ResultType enum with values Pre, Main, and Post to represent different result stages. Pre is explicitly set to 1.
2026-03-25 10:58:45 +01:00
bd07b4482c Remove CS0618 warning suppression for ExceptionHandlingMiddleware
Removed #pragma directives that suppressed CS0618 (obsolete API usage) warnings around app.UseMiddleware<ExceptionHandlingMiddleware>(). Obsolete warnings for this middleware will now be shown during compilation.
2026-03-25 10:28:49 +01:00
520aec427b Remove obsolete attribute and add exception using directive
Removed [Obsolete] from ExceptionHandlingMiddleware, indicating it is no longer deprecated. Added using directive for ReC.Application.Common.Exceptions to support updated exception handling.
2026-03-25 10:27:41 +01:00
26b7a82451 Handle RecActionException in middleware with 422 response
Added specific handling for RecActionException in the exception middleware. Now logs a warning with ActionId and ProfileId, returns a 422 Unprocessable Entity status, and provides detailed error information in the response.
2026-03-25 10:26:24 +01:00
08c0d29d84 Improve error handling and logging in batch rec actions
Add ILogger support to InvokeRecActionViewsCommandHandler for enhanced error and warning logging. Log and continue on handled exceptions when appropriate, and rethrow for critical errors. Clean up and reorder using directives. This increases robustness and traceability during batch rec action processing.
2026-03-25 10:25:52 +01:00
405b5f3ab1 Add ActionId and ProfileId properties to RecActionException
Expose ActionId and ProfileId as public properties in the
RecActionException class, allowing external access to these
values from exception instances. Refactored the constructor
to use a block body.
2026-03-25 10:17:24 +01:00
32af65d30c Remove InvokeBatchRecActionViewsCommand extension method
Deleted the InvokeBatchRecActionViewsCommandExtensions class and its InvokeBatchRecActionView extension method for ISender. The command record and handler remain unchanged.
2026-03-25 10:07:15 +01:00
30ccf05c57 Use RecActionException for contextual error handling
Replaced generic exception with RecActionException in PostprocessingBehavior when ErrorAction is Stop, providing ActionId and ProfileId for better error context. Added necessary using statements for the new exception and related namespaces.
2026-03-25 09:58:02 +01:00
a14d5ff112 Improve error handling with RecActionException
Wrap exceptions in PreprocessingBehavior with RecActionException, including ActionId and ProfileId for better context and debugging. This enhances error reporting when ErrorAction is set to Stop.
2026-03-25 09:57:46 +01:00
fec125b0d5 Improve exception context in action error handling
Updated InvokeRecActionViewCommandHandler to throw a RecActionException with action Id and ProfileId when an error occurs and ErrorAction is set to Stop. This change enhances error traceability by providing more contextual information in exceptions.
2026-03-25 09:56:58 +01:00
82ae4c5957 Add RecActionException custom exception class
Introduced RecActionException in ReC.Application.Common.Exceptions to encapsulate errors related to rec actions, including actionId, optional profileId, and inner exception details in the error message.
2026-03-25 09:55:52 +01:00
127 changed files with 4052 additions and 936 deletions

View File

@@ -18,6 +18,7 @@ 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
docs\ReC.Client.xwiki = docs\ReC.Client.xwiki
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "infrastructure", "infrastructure", "{3F88DACC-CEC0-4D9A-8BAA-37F67B02DC04}"
@@ -52,8 +53,8 @@ Global
{109645F5-441D-476B-B7D2-FBEAA8EBAE14}.Debug|Any CPU.Build.0 = Debug|Any CPU
{109645F5-441D-476B-B7D2-FBEAA8EBAE14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{109645F5-441D-476B-B7D2-FBEAA8EBAE14}.Release|Any CPU.Build.0 = Release|Any CPU
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Debug|Any CPU.Build.0 = Release|Any CPU
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA3A6BDD-8045-478F-860B-D1F0EB97F02B}.Release|Any CPU.Build.0 = Release|Any CPU
{457ED5AC-F4A0-41C3-9758-4A3C272EDC11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

556
docs/ReC.Client.xwiki Normal file
View File

@@ -0,0 +1,556 @@
== 1. Einleitung ==
**ReC.Client** ist eine .NET-Client-Bibliothek für den typisierten und bequemen Zugriff auf die **ReC.API**. Anstatt direkt mit `HttpClient` zu arbeiten, bietet die Bibliothek thematisch geordnete API-Klassen (z. B. `RecActionApi`, `ResultApi`, `ProfileApi`, `EndpointAuthApi`, `EndpointParamsApi`, `EndpointsApi`, `CommonApi`) und integriert sich nahtlos in **Microsoft.Extensions.DependencyInjection**.
Die Bibliothek unterstützt sowohl **.NET 8** als auch **.NET Framework 4.6.2** (Multi-Targeting).
=== 1.1 Kernmerkmale ===
* **DI-orientiert**: Registrierung über `services.AddRecClient(...)`.
* **Typisierte API-Klassen**: jede Domäne hat eine eigene API-Klasse als Eigenschaft auf `ReCClient`.
* **Konsistente Fehlerbehandlung**: Bei HTTP-Fehlerstatus wird einheitlich eine `ReCApiException` geworfen, inklusive Statuscode, Methode, URI, Body usw.
* **Flexibles Lesen**: GET-Endpunkte unterstützen sowohl typisierte (`GetAsync<T>(...)`) als auch dynamische (`GetAsync(...)` ohne Typparameter, liefert `dynamic` / `JsonElement`) Abfragen.
* **Optionen**: Logging und Verhalten lassen sich über `ReCClientOptions` steuern.
== 2. Installation und Setup ==
=== 2.1 Konfiguration mit Dependency Injection (empfohlen) ===
Registrieren Sie den Client in `Program.cs` / `Startup.cs` über `AddRecClient`. Sie können entweder eine Basis-URL als String oder einen Konfigurations-Delegate für den zugrunde liegenden `HttpClient` übergeben.
{{code language="vb.net"}}
Imports Microsoft.Extensions.Hosting
Imports Microsoft.Extensions.DependencyInjection
Imports ReC.Client
Module Program
Sub Main(args As String())
Dim builder = Host.CreateDefaultBuilder(args)
builder.ConfigureServices(
Sub(services)
' Variante A: Basis-URL als String
services.AddRecClient("https://ihre-rec-api-adresse.com/")
' Variante B: HttpClient feinkonfigurieren
' services.AddRecClient(Sub(client)
' client.BaseAddress = New Uri("https://ihre-rec-api-adresse.com/")
' client.Timeout = TimeSpan.FromSeconds(30)
' End Sub)
End Sub)
Dim app = builder.Build()
app.Run()
End Sub
End Module
{{/code}}
{{code language="csharp"}}
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using ReC.Client;
var builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices(services =>
{
// Variant A: base URL as string
services.AddRecClient("https://ihre-rec-api-adresse.com/");
// Variant B: configure HttpClient explicitly
// services.AddRecClient(client =>
// {
// client.BaseAddress = new Uri("https://ihre-rec-api-adresse.com/");
// client.Timeout = TimeSpan.FromSeconds(30);
// });
});
var app = builder.Build();
app.Run();
{{/code}}
=== 2.2 Konstruktor-Injektion ===
Sobald registriert, kann `ReCClient` per Konstruktor in jeden Dienst injiziert werden.
{{code language="vb.net"}}
Imports ReC.Client
Public Class MeinDienst
Private ReadOnly _recClient As ReCClient
Public Sub New(recClient As ReCClient)
_recClient = recClient
End Sub
End Class
{{/code}}
{{code language="csharp"}}
using ReC.Client;
public class MeinDienst
{
private readonly ReCClient _recClient;
public MeinDienst(ReCClient recClient)
{
_recClient = recClient;
}
}
{{/code}}
=== 2.3 Optionen über ReCClientOptions ===
Über `ReCClientOptions` lässt sich das Verhalten des Clients steuern, z. B. ob erfolgreiche Anfragen geloggt werden sollen.
{{code language="vb.net"}}
services.AddRecClient("https://ihre-rec-api-adresse.com/")
services.Configure(Of ReCClientOptions)(
Sub(opt)
opt.LogSuccessfulRequests = True
End Sub)
{{/code}}
{{code language="csharp"}}
services.AddRecClient("https://ihre-rec-api-adresse.com/");
services.Configure<ReCClientOptions>(opt =>
{
opt.LogSuccessfulRequests = true;
});
{{/code}}
{{warning}}
Wenn `LogSuccessfulRequests = true` gesetzt, aber **kein** `ILogger` über DI registriert ist, wirft der `ReCClient`-Konstruktor eine `InvalidOperationException`. Stellen Sie sicher, dass ein Logging-Provider (z. B. `services.AddLogging(...)`) registriert ist, oder lassen Sie die Option auf `false`.
{{/warning}}
== 3. Überblick über die API-Klassen ==
`ReCClient` bündelt mehrere thematische API-Klassen als Eigenschaften:
* `RecActions` (`RecActionApi`) Verwaltung und Auslösen von RecActions (CRUD + Invoke)
* `Results` (`ResultApi`) Lesen, Anlegen, Aktualisieren und Löschen von Result-Datensätzen
* `Profiles` (`ProfileApi`) Verwaltung der Profile
* `EndpointAuth` (`EndpointAuthApi`) Verwaltung der Endpoint-Authentifizierungsdaten
* `EndpointParams` (`EndpointParamsApi`) Verwaltung der Endpoint-Parameter
* `Endpoints` (`EndpointsApi`) Verwaltung der Endpoints
* `Common` (`CommonApi`) Gemeinsame Operationen, die nicht entitätsspezifisch sind
Alle entitätsspezifischen Klassen erben von `BaseCrudApi` und bieten ein konsistentes CRUD-Schema.
== 4. Verwendung ==
=== 4.1 GET-Endpunkte: typisiert oder dynamisch ===
Die GET-Methoden in `RecActionApi`, `ProfileApi` und `ResultApi` existieren jeweils als **zwei Overloads**:
* **Generisch**: `GetAsync<T>(...)` führt die Anfrage aus, liest den Response-Body **einmal** und deserialisiert ihn in den Typ `T`.
* **Nicht-generisch**: `GetAsync(...)` identische Parameterliste, gibt aber ein `dynamic` (in der Praxis `System.Text.Json.JsonElement`) zurück. Intern wird `GetAsync<object>(...)` aufgerufen.
Beide Overloads teilen sich Implementierung und Fehlerbehandlung: bei HTTP-Fehlerstatus wird **`ReCApiException`** geworfen.
{{info}}
Da der nicht-generische Overload eine andere Signatur als der generische besitzt (kein Typparameter), gibt es **keinen Konflikt**. Welcher Overload aufgerufen wird, hängt davon ab, ob Sie einen Typparameter angeben oder nicht.
{{/info}}
==== 4.1.1 Typisiertes Lesen ====
{{code language="vb.net"}}
Imports ReC.Application.Common.Dto
' Alle Actions für ein Profil als typisiertes Array
Dim actions As RecActionViewDto() =
Await recClient.RecActions.GetAsync(Of RecActionViewDto())(profileId:=42)
For Each a In actions
Console.WriteLine($"Action {a.Id} -> Endpoint {a.EndpointUri}")
Next
{{/code}}
{{code language="csharp"}}
using ReC.Application.Common.Dto;
// All actions for a profile as a typed array
var actions = await recClient.RecActions.GetAsync<RecActionViewDto[]>(profileId: 42);
foreach (var a in actions!)
{
Console.WriteLine($"Action {a.Id} -> Endpoint {a.EndpointUri}");
}
{{/code}}
==== 4.1.2 Dynamisches Lesen ====
Wenn das Schema flexibel ist oder Sie das Ergebnis nur weiterleiten möchten, können Sie den nicht-generischen Overload verwenden:
{{code language="vb.net"}}
Imports System.Text.Json
Dim payload As Object = Await recClient.RecActions.GetAsync(profileId:=42)
Dim element As JsonElement = CType(payload, JsonElement)
If element.ValueKind = JsonValueKind.Array Then
For Each item In element.EnumerateArray()
Console.WriteLine(item.GetProperty("id").GetInt64())
Next
End If
{{/code}}
{{code language="csharp"}}
using System.Text.Json;
dynamic? payload = await recClient.RecActions.GetAsync(profileId: 42);
var element = (JsonElement)payload!;
if (element.ValueKind == JsonValueKind.Array)
{
foreach (var item in element.EnumerateArray())
{
Console.WriteLine(item.GetProperty("id").GetInt64());
}
}
{{/code}}
=== 4.2 Eine RecAction auslösen (Invoke) ===
`RecActionApi.InvokeAsync` startet die Stapelverarbeitung der Actions eines Profils. Es gibt zwei Overloads: einen mit `InvokeReferences`-Objekt und einen Komfort-Overload mit nur einer Batch-ID.
{{code language="vb.net"}}
Imports ReC.Client.Api
Public Async Function FuehreProfilAktionenAus(recClient As ReCClient, profilId As Long) As Task
Try
Await recClient.RecActions.InvokeAsync(
profilId,
New InvokeReferences With {.BatchId = "batch-" & Guid.NewGuid().ToString("N")})
Catch ex As ReC.Client.ReCApiException
' Auswertung von ex.StatusCode, ex.Method, ex.RequestUri, ex.ResponseBody
Throw
End Try
End Function
{{/code}}
{{code language="csharp"}}
using ReC.Client;
using ReC.Client.Api;
public async Task ExecuteProfileActionsAsync(ReCClient recClient, long profileId)
{
try
{
await recClient.RecActions.InvokeAsync(
profileId,
new InvokeReferences { BatchId = $"batch-{Guid.NewGuid():N}" });
}
catch (ReCApiException ex)
{
// Inspect ex.StatusCode, ex.Method, ex.RequestUri, ex.ResponseBody
throw;
}
}
{{/code}}
Komfort-Overload nur mit Batch-ID:
{{code language="vb.net"}}
Await recClient.RecActions.InvokeAsync(profilId, "batch-001")
{{/code}}
{{code language="csharp"}}
await recClient.RecActions.InvokeAsync(profileId, "batch-001");
{{/code}}
=== 4.3 Anlegen, Aktualisieren, Löschen (CRUD) ===
Alle CRUD-Operationen sind asynchron und werfen bei Fehlern eine `ReCApiException`.
* `CreateAsync(payload)` HTTP POST mit JSON-Body.
* `UpdateAsync(id, payload)` HTTP PUT auf `/{ResourcePath}/{id}` mit JSON-Body.
* `DeleteAsync(payload)` HTTP DELETE; das Payload wird in den **Query-String** serialisiert (die API bindet Delete-Parameter aus der URL).
{{code language="vb.net"}}
Imports ReC.Application.RecActions.Commands
Imports ReC.Application.Common.Procedures.UpdateProcedure.Dto
' POST
Await recClient.RecActions.CreateAsync(New InsertActionCommand With {
.ProfileId = 1,
.EndpointId = 1,
.Active = True,
.Sequence = 1
})
' PUT
Await recClient.RecActions.UpdateAsync(123, New UpdateActionDto With {
.Active = False,
.Sequence = 2
})
' DELETE (Payload wird zu Query-String)
Await recClient.RecActions.DeleteAsync(New DeleteActionCommand With {
.Start = 100,
.End = 110,
.Force = False
})
{{/code}}
{{code language="csharp"}}
using ReC.Application.RecActions.Commands;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
// POST
await recClient.RecActions.CreateAsync(new InsertActionCommand
{
ProfileId = 1,
EndpointId = 1,
Active = true,
Sequence = 1
});
// PUT
await recClient.RecActions.UpdateAsync(123, new UpdateActionDto
{
Active = false,
Sequence = 2
});
// DELETE (payload becomes query string)
await recClient.RecActions.DeleteAsync(new DeleteActionCommand
{
Start = 100,
End = 110,
Force = false
});
{{/code}}
=== 4.4 Fehlerbehandlung mit ReCApiException ===
Sobald die API einen Statuscode außerhalb von 2xx zurückgibt, wirft die Bibliothek eine `ReCApiException`. Diese enthält folgende Informationen:
* `StatusCode` `HttpStatusCode` der Antwort (z. B. 404, 400, 500)
* `ReasonPhrase` Optionaler HTTP-Reason-Phrase
* `ResponseBody` Roher Response-Body als String (sofern lesbar)
* `Method` HTTP-Methode der ursprünglichen Anfrage (z. B. `GET`, `POST`)
* `RequestUri` Aufgerufene URI mit Pfad und Query
{{code language="vb.net"}}
Try
Dim profile = Await recClient.Profiles.GetAsync(Of ProfileViewDto)(id:=42)
Catch ex As ReCApiException
If ex.StatusCode = Net.HttpStatusCode.NotFound Then
' Profil existiert nicht
Else
' Allgemeiner Fehler
Console.WriteLine($"{ex.Method} {ex.RequestUri} -> {ex.StatusCode}: {ex.ResponseBody}")
Throw
End If
End Try
{{/code}}
{{code language="csharp"}}
try
{
var profile = await recClient.Profiles.GetAsync<ProfileViewDto>(id: 42);
}
catch (ReCApiException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
{
// Profile does not exist
}
catch (ReCApiException ex)
{
Console.WriteLine($"{ex.Method} {ex.RequestUri} -> {ex.StatusCode}: {ex.ResponseBody}");
throw;
}
{{/code}}
== 5. Testen ==
Das Testprojekt verwendet `Microsoft.AspNetCore.Mvc.Testing`, um die `ReC.API` mit `WebApplicationFactory<Program>` **in-process** zu starten. Der `ReCClient` wird über DI konfiguriert und auf den in-process HTTP-Handler verdrahtet. So müssen Tests die API nicht extern starten.
Empfehlungen:
* Schreiben Sie Tests als `async Task` und verwenden Sie `await` **vermeiden** Sie `GetAwaiter().GetResult()` oder `TaskSyncExtensions.Sync(...)`.
* Verwenden Sie `Assert.ThrowsAsync<ReCApiException>(...)`, um Fehlerpfade zu prüfen, und werten Sie `StatusCode`, `Method` und `RequestUri` aus.
* Für GET-Tests reicht eine einzelne Methode pro Verhalten (typisiert vs. dynamisch) statt redundanter Setups.
== 6. Komfort-APIs: statischer Provider und synchrone Wrapper ==
Neben dem empfohlenen DI-basierten Ansatz bietet **ReC.Client** absichtlich auch einen **statischen Komfort-Pfad** sowie **synchrone Wrapper** an. Diese Bestandteile sind nicht „veraltet im Sinne von eingefroren" sie werden weiterhin gepflegt und bei Bedarf um neue Funktionen erweitert. Sie sind jedoch bewusst mit `[Obsolete]` markiert, damit Aufrufer sie nicht „aus Versehen" auswählen, sondern eine bewusste Entscheidung treffen.
Hintergrund
* In Projekten, die noch auf **.NET Framework 4.6.2** basieren, ist `Microsoft.Extensions.DependencyInjection` häufig nicht etabliert und die Einführung einer DI-Infrastruktur kostet Zeit. Damit Entwickler dort nicht ins Stocken geraten, gibt es einen statischen Einstieg, der **sofort einsatzbereit** ist.
* Synchroner Code in älteren Codebasen kann nicht überall sofort auf `async/await` umgestellt werden. Für solche Stellen existieren die `Sync()`-Erweiterungen als pragmatische Brücke.
Status
* **Aktiv gepflegt**: Beide Pfade erhalten weiterhin Funktionalitäts- und Komfort-Updates.
* **`[Obsolete]`-Markierung als Erinnerung**: Die Compiler-Warnung soll bewusst sichtbar bleiben, damit Teams die Übergangslösung nicht vergessen und mittelfristig zu DI + `async/await` migrieren.
* **Kein Breaking-Change-Risiko**: Aufrufe bleiben kompilierbar und ausführbar.
Wann der statische Pfad sinnvoll ist
* Bestehender VB.NET-/C#-Code auf .NET Framework 4.6.2 ohne eigene DI-Infrastruktur.
* Kleine Werkzeuge, Skripte oder Konsolenanwendungen, bei denen ein vollständiges Host-Setup übertrieben wäre.
* Schneller Einstieg in die Bibliothek, um ein erstes Ergebnis zu sehen, bevor die endgültige Architektur entschieden wird.
Wann besser DI verwenden
* Lang laufende Prozesse, Serveranwendungen, Tests.
* Sobald in der Anwendung ohnehin `IServiceCollection` / `IHostBuilder` vorhanden ist.
* Wenn `HttpClient`-Lebenszyklen, Logging-Scopes oder Optionen sauber verwaltet werden sollen.
=== 6.1 Statischer Client mit BuildStaticClient / Create ===
`ReCClient.BuildStaticClient(...)` baut intern eine `IServiceCollection` auf, ruft `AddRecClient(...)` auf und legt einen **statischen, thread-safen `Lazy<IServiceProvider>`** an. Der eigentliche `IServiceProvider` wird **erst beim ersten Aufruf von `ReCClient.Create()`** und genau einmal gebaut.
Wichtig:
* `BuildStaticClient` darf **nur einmal** beim Anwendungsstart aufgerufen werden. Ein zweiter Aufruf egal welcher Overload wirft `InvalidOperationException("Static Provider is already built.")`.
* Die Konstruktion des `IServiceProvider` ist **threadsicher** (`Lazy<T>` mit `LazyThreadSafetyMode.ExecutionAndPublication`).
==== 6.1.1 Empfohlene Form: BuildStaticClient mit StaticBuildConfiguration ====
Da der statische Pfad mehrere optionale Bestandteile hat (Basis-URL **oder** `HttpClient`-Konfiguration, `ReCClientOptions`, eigener `ILogger`, zusätzliche Service-Registrierungen), gibt es einen Callback-basierten Overload, der alle Optionen in einem `StaticBuildConfiguration`-Objekt bündelt:
{{code language="vb.net"}}
Imports Microsoft.Extensions.DependencyInjection
Imports Microsoft.Extensions.Logging
ReCClient.BuildStaticClient(
Sub(cfg)
cfg.BaseAddress = "https://ihre-rec-api-adresse.com/"
cfg.ConfigureOptions = Sub(opt)
opt.LogSuccessfulRequests = True
End Sub
' Optional: eigene zusätzliche Registrierungen, z. B. Logging-Provider
cfg.ConfigureServices = Sub(services)
services.AddLogging(Sub(b) b.AddConsole())
End Sub
End Sub)
{{/code}}
{{code language="csharp"}}
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
ReCClient.BuildStaticClient(cfg =>
{
cfg.BaseAddress = "https://ihre-rec-api-adresse.com/";
cfg.ConfigureOptions = opt =>
{
opt.LogSuccessfulRequests = true;
};
// Optional: additional service registrations, e.g. logging
cfg.ConfigureServices = services =>
{
services.AddLogging(b => b.AddConsole());
};
});
{{/code}}
Eigenschaften von `StaticBuildConfiguration`:
* `BaseAddress` Basis-URI der ReC.API. **Schließt sich gegenseitig** mit `ConfigureClient` aus.
* `ConfigureClient` Delegate zum direkten Konfigurieren des `HttpClient` (z. B. `BaseAddress` + `Timeout` + Header). Schließt sich gegenseitig mit `BaseAddress` aus.
* `ConfigureOptions` Optionaler Delegate für `ReCClientOptions` (z. B. `LogSuccessfulRequests`).
* `Logger` Optionale `ILogger`-Instanz, die als Singleton in die interne `IServiceCollection` registriert wird.
* `ConfigureServices` Optionaler Delegate, mit dem der Aufrufer beliebige zusätzliche Registrierungen auf der internen `IServiceCollection` vornehmen kann (z. B. `AddLogging(...)` oder eigene Abhängigkeiten).
Validierung beim Aufruf:
* `BuildStaticClient` wirft `ArgumentNullException`, wenn der `configure`-Callback `null` ist.
* `BuildStaticClient` wirft `InvalidOperationException`, wenn weder `BaseAddress` noch `ConfigureClient` gesetzt sind, **oder** wenn beide gleichzeitig gesetzt sind.
{{info}}
Auch diese callback-basierte Variante ist mit `[Obsolete]` markiert — der Hinweistext lautet hier jedoch *"Use a local service collection instead of the static provider."* Damit wird klargestellt, dass innerhalb des statischen Pfades die `StaticBuildConfiguration`-Variante die empfohlene Form ist, der statische Pfad als Ganzes aber weiterhin bewusst als Komfort-API gekennzeichnet bleibt (siehe Einleitung von Kapitel 6).
{{/info}}
Variante mit `HttpClient`-Feinkonfiguration:
{{code language="vb.net"}}
ReCClient.BuildStaticClient(
Sub(cfg)
cfg.ConfigureClient = Sub(http)
http.BaseAddress = New Uri("https://ihre-rec-api-adresse.com/")
http.Timeout = TimeSpan.FromSeconds(30)
End Sub
End Sub)
{{/code}}
{{code language="csharp"}}
ReCClient.BuildStaticClient(cfg =>
{
cfg.ConfigureClient = http =>
{
http.BaseAddress = new Uri("https://ihre-rec-api-adresse.com/");
http.Timeout = TimeSpan.FromSeconds(30);
};
});
{{/code}}
Nach dem `BuildStaticClient`-Aufruf liefert `ReCClient.Create()` Instanzen aus dem statischen Provider:
{{code language="vb.net"}}
Dim client As ReCClient = ReCClient.Create()
Await client.RecActions.InvokeAsync(profilId, "batch-001")
{{/code}}
{{code language="csharp"}}
var client = ReCClient.Create();
await client.RecActions.InvokeAsync(profileId, "batch-001");
{{/code}}
==== 6.1.2 Ältere Komfort-Overloads ====
Aus Bequemlichkeit existieren zwei weitere Overloads, die intern an die `StaticBuildConfiguration`-Variante delegieren. Sie sind als `Obsolete` markiert mit dem Hinweis, die `Action<StaticBuildConfiguration>`-Variante zu verwenden, bleiben aber funktionsfähig:
{{code language="vb.net"}}
' Variante mit Basis-URL als String
ReCClient.BuildStaticClient("https://ihre-rec-api-adresse.com/")
' Mit Options-Callback und optionalem Logger
ReCClient.BuildStaticClient(
"https://ihre-rec-api-adresse.com/",
Sub(opt) opt.LogSuccessfulRequests = True,
myLogger)
{{/code}}
{{code language="csharp"}}
// Variant with base URL string
ReCClient.BuildStaticClient("https://ihre-rec-api-adresse.com/");
// With options callback and optional logger
ReCClient.BuildStaticClient(
"https://ihre-rec-api-adresse.com/",
opt => opt.LogSuccessfulRequests = true,
myLogger);
{{/code}}
=== 6.2 Synchrone Wrapper über TaskSyncExtensions ===
`TaskSyncExtensions.Sync()` bzw. `Sync<TResult>()` blockieren den aktuellen Thread, bis die `Task` abgeschlossen ist. Sie sind nützlich, wenn der umliegende Code (noch) nicht asynchron sein kann.
{{code language="vb.net"}}
Imports ReC.Client
' Blockiert bis die Task fertig ist
recClient.RecActions.InvokeAsync(profilId, "batch-001").Sync()
{{/code}}
{{code language="csharp"}}
using ReC.Client;
// Blocks until the task completes
recClient.RecActions.InvokeAsync(profileId, "batch-001").Sync();
{{/code}}
Hinweis: In Umgebungen mit einem `SynchronizationContext` (z. B. WinForms, WPF oder bestimmte Test-Runner) kann blockierendes Warten zu Deadlocks führen. Für Konsolen- und Hintergrundprozesse ist das Risiko in der Regel gering. Wo immer möglich: `async/await` bevorzugen.
=== 6.3 Mittelfristige Empfehlung ===
* **`BuildStaticClient` / `Create`**: für Legacy-Einstiege okay; sobald `IServiceCollection` vorhanden ist, auf `services.AddRecClient(...)` und Konstruktor-Injektion umstellen.
* **`TaskSyncExtensions.Sync`**: nur lokal kapseln. Wenn eine Methode bereits `async` sein darf, direkt `await` verwenden.
* Die `[Obsolete]`-Warnung dient als **dauerhafter Reminder**, dass es sich um einen bewussten Komfort-Pfad handelt sie ist kein Hinweis darauf, dass die APIs entfernt werden.

0
docs/ReC.Client.xwiki.md Normal file
View File

View File

@@ -13,14 +13,19 @@ public class RecActionController(IMediator mediator) : ControllerBase
/// <summary>
/// Invokes a batch of RecActions for a given profile.
/// </summary>
/// <param name="command">The command containing the profile ID.</param>
/// <param name="profileId">The identifier of the profile whose RecActions should be invoked.</param>
/// <param name="references">Optional reference values that are passed through to all result records.</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/{command}")]
[HttpPost("invoke/{profileId}")]
[ProducesResponseType(StatusCodes.Status202Accepted)]
public async Task<IActionResult> Invoke([FromRoute] InvokeBatchRecActionViewsCommand command, CancellationToken cancel)
public async Task<IActionResult> Invoke([FromRoute] long profileId, [FromBody] InvokeReferences references, CancellationToken cancel = default)
{
await mediator.Send(command, cancel);
await mediator.Send(new InvokeBatchRecActionViewsCommand
{
ProfileId = profileId,
References = references
}, cancel);
return Accepted();
}

View File

@@ -7,13 +7,11 @@ using System.Text.Json;
namespace ReC.API.Middleware;
//TODO: Fix and use DigitalData.Core.Exceptions.Middleware
/// <summary>
/// Middleware for handling exceptions globally in the application.
/// Captures exceptions thrown during the request pipeline execution,
/// logs them, and returns an appropriate HTTP response with a JSON error details.
/// </summary>
[Obsolete("Use DigitalData.Core.Exceptions.Middleware")]
public class ExceptionHandlingMiddleware
{
private readonly RequestDelegate _next;
@@ -164,6 +162,22 @@ public class ExceptionHandlingMiddleware
};
break;
case RecActionException recActionEx:
logger.LogWarning(
recActionEx,
"Rec action failed. ActionId: {ActionId}, ProfileId: {ProfileId}",
recActionEx.ActionId,
recActionEx.ProfileId);
context.Response.StatusCode = (int)HttpStatusCode.UnprocessableEntity;
details = new()
{
Title = "Rec Action Failed",
Detail = recActionEx.InnerException?.Message
?? "An error occurred while executing the rec action. Check the logs for more details."
};
break;
default:
logger.LogError(exception, "Unhandled exception occurred.");
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

View File

@@ -1,8 +0,0 @@
namespace ReC.API.Models;
public class FakeRequest
{
public Dictionary<string, object>? Body { get; init; }
public Dictionary<string, object>? Header { get; init; }
}

View File

@@ -1,17 +0,0 @@
namespace ReC.API.Models;
public enum ResultType
{
/// <summary>
/// Return the full result object.
/// </summary>
Full,
/// <summary>
/// Return only the header part of the result.
/// </summary>
OnlyHeader,
/// <summary>
/// Return only the body part of the result.
/// </summary>
OnlyBody
}

View File

@@ -48,10 +48,13 @@ try
?? throw new InvalidOperationException("Connection string is not found.");
var logger = provider.GetRequiredService<ILogger<RecDbContext>>();
var enableSensitiveDataLogging = config.GetValue("EfCore:EnableSensitiveDataLogging", true);
var enableDetailedErrors = config.GetValue("EfCore:EnableDetailedErrors", false);
opt.UseSqlServer(cnnStr)
.LogTo(log => logger.LogInformation("{log}", log), LogLevel.Trace)
.EnableSensitiveDataLogging()
.EnableDetailedErrors();
.EnableSensitiveDataLogging(enableSensitiveDataLogging)
.EnableDetailedErrors(enableDetailedErrors);
});
});
@@ -70,9 +73,7 @@ try
var app = builder.Build();
#pragma warning disable CS0618
app.UseMiddleware<ExceptionHandlingMiddleware>();
#pragma warning restore CS0618
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment() || config.GetValue<bool>("UseSwagger"))
@@ -97,3 +98,5 @@ catch(Exception ex)
logger.Error(ex, "Stopped program because of exception");
throw;
}
public partial class Program;

View File

@@ -9,7 +9,7 @@
<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>
<DesktopBuildPackageLocation>M:\App&amp;Service\0 DD - Smart UP\ReC\API\$(Version)\Rec.API.zip</DesktopBuildPackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<DeployIisAppPath>Rec.API</DeployIisAppPath>
<_TargetId>IISWebDeployPackage</_TargetId>

View File

@@ -10,10 +10,10 @@
<Product>ReC.API</Product>
<PackageIcon>Assets\icon.ico</PackageIcon>
<PackageTags>digital data rest-caller rec api</PackageTags>
<Version>2.0.2-beta</Version>
<AssemblyVersion>2.0.2.0</AssemblyVersion>
<FileVersion>2.0.2.0</FileVersion>
<InformationalVersion>2.0.1-beta</InformationalVersion>
<Version>2.4.0-beta</Version>
<AssemblyVersion>2.4.0.0</AssemblyVersion>
<FileVersion>2.4.0.0</FileVersion>
<InformationalVersion>2.4.0-beta</InformationalVersion>
<Copyright>Copyright © 2025 Digital Data GmbH. All rights reserved.</Copyright>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>

View File

@@ -5,9 +5,13 @@
},
"AllowedHosts": "*",
"LuckyPennySoftwareLicenseKey": "eyJhbGciOiJSUzI1NiIsImtpZCI6Ikx1Y2t5UGVubnlTb2Z0d2FyZUxpY2Vuc2VLZXkvYmJiMTNhY2I1OTkwNGQ4OWI0Y2IxYzg1ZjA4OGNjZjkiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2x1Y2t5cGVubnlzb2Z0d2FyZS5jb20iLCJhdWQiOiJMdWNreVBlbm55U29mdHdhcmUiLCJleHAiOiIxNzg0ODUxMjAwIiwiaWF0IjoiMTc1MzM2MjQ5MSIsImFjY291bnRfaWQiOiIwMTk4M2M1OWU0YjM3MjhlYmZkMzEwM2MyYTQ4NmU4NSIsImN1c3RvbWVyX2lkIjoiY3RtXzAxazB5NmV3MmQ4YTk4Mzg3aDJnbTRuOWswIiwic3ViX2lkIjoiLSIsImVkaXRpb24iOiIwIiwidHlwZSI6IjIifQ.ZqsFG7kv_-xGfxS6ACk3i0iuNiVUXX2AvPI8iAcZ6-z2170lGv__aO32tWpQccD9LCv5931lBNLWSblKS0MT3gOt-5he2TEftwiSQGFwoIBgtOHWsNRMinUrg2trceSp3IhyS3UaMwnxZDrCvx4-0O-kpOzVpizeHUAZNr5U7oSCWO34bpKdae6grtM5e3f93Z1vs7BW_iPgItd-aLvPwApbaG9VhmBTKlQ7b4Jh64y7UXJ9mKP7Qb_Oa97oEg0oY5DPHOWTZWeE1EzORgVr2qkK2DELSHuZ_EIUhODojkClPNAKtvEl_qEjpq0HZCIvGwfCCRlKlSkQqIeZdFkiXg",
"EfCore": {
"EnableSensitiveDataLogging": true,
"EnableDetailedErrors": false
},
"RecAction": {
"AddedWho": "ReC.API",
"UseHttp1ForNtlm": false
"UseHttp1ForNtlm": false,
"AutoDetectHeaders": false
},
// Bad request SqlException numbers numbers can be updated at runtime; no restart required.
"SqlException": {

View File

@@ -0,0 +1,54 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using ReC.Application.Common.Dto;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Interfaces;
namespace ReC.Application.Common.Behaviors.Action;
public class BodyQueryBehavior<TRequest, TResponse>(IRecDbContext dbContext) : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull
where TResponse : IEnumerable<RecActionViewDto>
{
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancel)
{
var actions = await next(cancel);
foreach (var action in actions)
await SetBody(action, cancel);
return actions;
}
private async Task SetBody(RecActionViewDto action, CancellationToken cancel)
{
if (action.BodyQuery is not string bodyQuery)
return;
await using var command = dbContext.Database.GetDbConnection().CreateCommand();
command.CommandText = bodyQuery;
await dbContext.Database.OpenConnectionAsync(cancel);
try
{
object? scalar;
try
{
scalar = await command.ExecuteScalarAsync(cancel);
}
catch (Exception ex)
{
throw new DataIntegrityException(
$"Body query execution failed. The stored SQL may be malformed. ActionId: {action.Id}, ProfileId: {action.ProfileId}, Error: {ex.Message}");
}
action.Body = scalar as string
?? throw new DataIntegrityException(
$"Body query returned no result or a null value. ActionId: {action.Id}, ProfileId: {action.ProfileId}");
}
finally
{
await dbContext.Database.CloseConnectionAsync();
}
}
}

View File

@@ -0,0 +1,61 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using ReC.Application.Common.Dto;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Interfaces;
using System.Text.Json;
namespace ReC.Application.Common.Behaviors.Action;
public class HeaderQueryBehavior<TRequest, TResponse>(IRecDbContext dbContext) : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull
where TResponse : IEnumerable<RecActionViewDto>
{
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancel)
{
var actions = await next(cancel);
foreach (var action in actions)
await SetHeader(action, cancel);
return actions;
}
private async Task SetHeader(RecActionViewDto action, CancellationToken cancel)
{
if (action.HeaderQuery is not string headerQuery)
return;
await using var command = dbContext.Database.GetDbConnection().CreateCommand();
command.CommandText = headerQuery;
await dbContext.Database.OpenConnectionAsync(cancel);
try
{
object? scalar;
try
{
scalar = await command.ExecuteScalarAsync(cancel);
}
catch (Exception ex)
{
throw new DataIntegrityException(
$"Header query execution failed. The stored SQL may be malformed. ActionId: {action.Id}, ProfileId: {action.ProfileId}, Error: {ex.Message}");
}
if (scalar is not string rawHeader)
throw new DataIntegrityException(
$"Header query returned no result or a null value. ActionId: {action.Id}, ProfileId: {action.ProfileId}");
var headerDict = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(rawHeader)
?? throw new DataIntegrityException(
$"Header query returned invalid JSON. ActionId: {action.Id}, ProfileId: {action.ProfileId}");
action.Headers = headerDict.ToDictionary(header => header.Key, kvp => kvp.Value.ToString());
}
finally
{
await dbContext.Database.CloseConnectionAsync();
}
}
}

View File

@@ -1,23 +0,0 @@
using MediatR;
using ReC.Application.Common.Dto;
using ReC.Application.Common.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace ReC.Application.Common.Behaviors;
public class BodyQueryBehavior<TRequest, TResponse>(IRecDbContext dbContext) : IPipelineBehavior<TRequest, TResponse>
where TRequest : RecActionViewDto
where TResponse : notnull
{
public async Task<TResponse> Handle(TRequest action, RequestHandlerDelegate<TResponse> next, CancellationToken cancel)
{
if (action.BodyQuery is null)
return await next(cancel);
var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).SingleOrDefaultAsync(cancel);
action.Body = result?.RawBody;
return await next(cancel);
}
}

View File

@@ -1,43 +0,0 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using ReC.Application.Common.Dto;
using ReC.Application.Common.Interfaces;
using System.Text.Json;
namespace ReC.Application.Common.Behaviors;
public class HeaderQueryBehavior<TRequest, TResponse>(IRecDbContext dbContext, ILogger<HeaderQueryBehavior<TRequest, TResponse>>? logger = null) : IPipelineBehavior<TRequest, TResponse>
where TRequest : RecActionViewDto
where TResponse : notnull
{
public async Task<TResponse> Handle(TRequest action, RequestHandlerDelegate<TResponse> next, CancellationToken cancel)
{
if (action.HeaderQuery is null)
return await next(cancel);
var result = await dbContext.HeaderQueryResults.FromSqlRaw(action.HeaderQuery).SingleOrDefaultAsync(cancel);
if (result?.RawHeader is null)
{
logger?.LogWarning("Header query did not return a result or returned a null REQUEST_HEADER. Profile ID: {ProfileId}, Action ID: {Id}", action.ProfileId, action.Id);
return await next(cancel);
}
var headerDict = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(result.RawHeader);
if(headerDict is null)
{
logger?.LogWarning(
"Header JSON deserialization returned null. RawHeader: {RawHeader}, ProfileId: {ProfileId}, Id: {Id}",
result.RawHeader, action.ProfileId, action.Id);
return await next(cancel);
}
action.Headers = headerDict.ToDictionary(header => header.Key, kvp => kvp.Value.ToString());
return await next(cancel);
}
}

View File

@@ -1,11 +1,12 @@
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.Action;
namespace ReC.Application.Common.Behaviors.InvokeAction;
public class PostprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, Unit>
{
@@ -22,8 +23,11 @@ public class PostprocessingBehavior(IRecDbContext context, ISender sender) : IPi
await sender.Send(new InsertResultCommand()
{
Status = RecStatus.OK,
ActionId = request.Action.Id,
Info = info
InfoDetail = info,
Type = ResultType.Post,
References = request.References
}, cancel);
}
}
@@ -33,12 +37,15 @@ public class PostprocessingBehavior(IRecDbContext context, ISender sender) : IPi
await sender.Send(new InsertResultCommand()
{
Status = RecStatus.Error,
ActionId = request.Action.Id,
Error = error
Error = error,
Type = ResultType.Post,
References = request.References
}, cancel);
if (request.Action.ErrorAction == ErrorAction.Stop)
throw;
throw new RecActionException(request.Action.Id, request.Action.ProfileId, ex);
}
return Unit.Value;

View File

@@ -1,11 +1,12 @@
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.Action;
namespace ReC.Application.Common.Behaviors.InvokeAction;
public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPipelineBehavior<InvokeRecActionViewCommand, Unit>
{
@@ -19,8 +20,11 @@ public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPip
await sender.Send(new InsertResultCommand()
{
Status = RecStatus.OK,
ActionId = request.Action.Id,
Info = JsonSerializer.Serialize(result)
InfoDetail = JsonSerializer.Serialize(result),
Type = ResultType.Pre,
References = request.References
}, cancel);
}
}
@@ -28,12 +32,15 @@ public class PreprocessingBehavior(IRecDbContext context, ISender sender) : IPip
{
await sender.Send(new InsertResultCommand()
{
Status = RecStatus.Error,
ActionId = request.Action.Id,
Error = ex.ToString()
Error = ex.ToString(),
Type = ResultType.Pre,
References = request.References
}, cancel);
if (request.Action.ErrorAction == ErrorAction.Stop)
throw;
throw new RecActionException(request.Action.Id, request.Action.ProfileId, ex);
}
return await next(cancel);

View File

@@ -1,32 +0,0 @@
namespace ReC.Application.Common.Dto;
public record ConnectionDto
{
public short? Id { get; set; }
public string? Bezeichnung { get; set; }
public string? SqlProvider { get; set; }
public string? Server { get; set; }
public string? Datenbank { get; set; }
public string? Username { get; set; }
public string? Password { get; set; }
public string? Bemerkung { get; set; }
public bool? Aktiv { get; set; }
public string? ErstelltWer { get; set; }
public DateTime? ErstelltWann { get; set; }
public string? GeandertWer { get; set; }
public DateTime? GeaendertWann { get; set; }
public bool? SysConnection { get; set; }
}

View File

@@ -1,4 +1,4 @@
using ReC.Domain.Views;
using ReC.Domain.Views;
namespace ReC.Application.Common.Dto;
@@ -6,7 +6,12 @@ public class DtoMappingProfile : AutoMapper.Profile
{
public DtoMappingProfile()
{
CreateMap<RecActionView, RecActionViewDto>();
CreateMap<RecActionView, RecActionViewDto>()
.ForMember(dest => dest.PreprocessingQuery, opt => opt.MapFrom((src, _) =>
src.PreprocessingQuery?.ReplacePlaceholders(src)))
.ForMember(dest => dest.PostprocessingQuery, opt => opt.MapFrom((src, _) =>
src.PostprocessingQuery?.ReplacePlaceholders(src)));
CreateMap<ResultView, ResultViewDto>();
CreateMap<ProfileView, ProfileViewDto>();
}

View File

@@ -1,39 +0,0 @@
using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Application.Common.Dto;
public record EndpointAuthDto
{
public long? Id { get; set; }
public bool? Active { get; set; }
public string? Description { get; set; }
public EndpointAuthType? Type { get; set; }
public string? ApiKey { get; set; }
public string? ApiValue { get; set; }
public ApiKeyLocation? ApiKeyAddTo { get; set; }
public string? Token { get; set; }
public string? Username { get; set; }
public string? Password { get; set; }
public string? Domain { get; set; }
public string? Workstation { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,22 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Application.Common.Dto;
public record EndpointDto
{
public long Id { get; set; }
public bool? Active { get; set; }
public string? Description { get; set; }
public string? Uri { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,33 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Application.Common.Dto;
/// <summary>
/// Represents the TBREC_CFG_ENDPOINT_PARAMS table.
/// All properties are nullable to provide flexibility on the database side,
/// preventing breaking changes if columns are altered to be nullable in production.
/// </summary>
public record EndpointParamDto
{
public long? Id { get; set; }
public bool? Active { get; set; }
public string? Description { get; set; }
public short? GroupId { get; set; }
public byte? Sequence { get; set; }
public string? Key { get; set; }
public string? Value { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,24 +0,0 @@
namespace ReC.Application.Common.Dto;
public record OutResDto
{
public long Id { get; set; }
public long ActionId { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
public string? Info { get; set; }
public string? Error { get; set; }
public string AddedWho { get; set; } = null!;
public DateTime AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -0,0 +1,60 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
using System.Text.RegularExpressions;
namespace ReC.Application.Common.Dto;
public static partial class PlaceholderExtensions
{
[GeneratedRegex(@"\{#[^#]+#[^}]+\}")]
private static partial Regex PlaceholderRegex();
/// <summary>
/// Replaces placeholders in the format <c>{#ANY_STRING#COLUMN_NAME}</c> with the corresponding
/// property value resolved via <see cref="GetValueByColumnName{T}"/> from the provided objects.
/// Values are converted to SQL-compatible string representations.
/// If a placeholder cannot be resolved, it is replaced with <c>NULL</c>.
/// </summary>
public static string ReplacePlaceholders(this string str, params object?[] objects)
{
return PlaceholderRegex().Replace(str, match =>
{
var placeholder = match.Value;
var inner = placeholder[2..^1]; // remove {# and }
var lastHash = inner.LastIndexOf('#');
var columnName = inner[(lastHash + 1)..];
foreach (var obj in objects)
{
if (obj is null)
continue;
var value = obj.GetValueByColumnName(columnName);
if (value is not null)
return ToSqlLiteral(value);
}
return "NULL";
});
}
private static string ToSqlLiteral(object value) => value switch
{
bool b => b ? "TRUE" : "FALSE",
DateTime dt => dt.ToString("yyyy-MM-dd HH:mm:ss"),
DateTimeOffset dto => dto.ToString("yyyy-MM-dd HH:mm:ss zzz"),
_ => value.ToString() ?? string.Empty
};
/// <summary>
/// Gets the value of a property by its column name defined in <see cref="ColumnAttribute"/>.
/// Returns <c>null</c> if no property with the given column name exists.
/// </summary>
public static object? GetValueByColumnName<T>(this T obj, string columnName) where T : class
{
var property = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
.FirstOrDefault(p => p.GetCustomAttribute<ColumnAttribute>()?.Name == columnName);
return property?.GetValue(obj);
}
}

View File

@@ -1,30 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Application.Common.Dto;
public record ProfileDto
{
public long Id { get; set; }
public bool? Active { get; set; }
public string? Type { get; set; }
public string? Mandantor { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? LogLevel { get; set; }
public string? Language { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -1,53 +0,0 @@
using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Application.Common.Dto;
public record RecActionDto
{
public long? Id { get; set; }
public long? ProfileId { get; set; }
public ProfileDto? Profile { get; set; }
public bool? Active { get; set; }
public byte? Sequence { get; set; }
public long? EndpointId { get; set; }
public EndpointDto? Endpoint { get; set; }
public long? EndpointAuthId { get; set; }
public EndpointAuthDto? EndpointAuth { get; set; }
public short? EndpointParamsId { get; set; }
public short? SqlConnectionId { get; set; }
public ConnectionDto? SqlConnection { get; set; }
public string? Type { get; set; }
public string? PreprocessingQuery { get; set; }
public string? HeaderQuery { get; set; }
public string? BodyQuery { get; set; }
public string? PostprocessingQuery { get; set; }
public ErrorAction? ErrorAction { get; set; }
public string? AddedWho { get; set; }
public DateTime? AddedWhen { get; set; }
public string? ChangedWho { get; set; }
public DateTime? ChangedWhen { get; set; }
public OutResDto? OutRes { get; set; }
}

View File

@@ -8,6 +8,8 @@ public record RecActionViewDto
public long? ProfileId { get; init; }
public ProfileViewDto? Profile { get; init; }
public string? ProfileName { get; init; }
public ProfileType? ProfileType { get; init; }

View File

@@ -1,11 +1,11 @@
namespace ReC.Application.Common.Dto;
using ReC.Domain.Constants;
namespace ReC.Application.Common.Dto;
public record ResultViewDto
{
public long Id { get; init; }
public OutResDto? Root { get; init; }
public long? ActionId { get; init; }
public RecActionViewDto? Action { get; init; }
@@ -16,7 +16,7 @@ public record ResultViewDto
public string? ProfileName { get; init; }
public short? StatusCode { get; init; }
public RecStatus Status { get; set; }
public string? StatusName { get; init; }
@@ -24,6 +24,14 @@ public record ResultViewDto
public string? Body { get; init; }
public string? Info { get; set; }
public string? InfoDetail { get; set; }
public string? Error { get; set; }
public string? BatchId { get; set; }
public string? AddedWho { get; init; }
public DateTime? AddedWhen { get; init; }

View File

@@ -0,0 +1,9 @@
namespace ReC.Application.Common.Exceptions;
public class RecActionException(long actionId, long? profileId, Exception innerException)
: Exception($"Rec action failed. ActionId: {actionId}, ProfileId: {profileId}", innerException)
{
public long ActionId { get; } = actionId;
public long? ProfileId { get; } = profileId;
}

View File

@@ -2,7 +2,6 @@
public class RecActionOptions
{
public string AddedWho { get; set; } = null!;
public bool UseHttp1ForNtlm { get; set; } = false;
public bool AutoDetectHeaders { get; set; } = false;
}

View File

@@ -11,9 +11,9 @@ namespace ReC.Application.Common.Procedures.DeleteProcedure;
public record DeleteObjectProcedure : IRequest<int>
{
/// <summary>
/// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT
/// Target entity for the delete operation.
/// </summary>
public string Entity { get; set; } = null!;
public required EntityType Entity { get; set; }
/// <summary>
/// Start GUID/ID (inclusive)
@@ -35,25 +35,16 @@ public class DeleteObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlE
{
public async Task<int> Handle(DeleteObjectProcedure request, CancellationToken cancel)
{
var parameters = new[]
{
new SqlParameter("@pENTITY", request.Entity ?? (object)DBNull.Value),
new SqlParameter("@pSTART", request.Start.ToString()),
new SqlParameter("@pEND", request.End.ToString()),
new SqlParameter("@pFORCE", (object?)request.Force ?? DBNull.Value)
};
var sp = new StoredProcedureBuilder("[dbo].[PRREC_DELETE_OBJECT]", "RC")
.Add("pENTITY", request.Entity)
.Add("pSTART", request.Start.ToString())
.Add("pEND", request.End.ToString())
.Add("pFORCE", request.Force);
try
{
var result = await repo.ExecuteQueryRawAsync(
"DECLARE @RC SMALLINT = 0; " +
"EXEC @RC = [dbo].[PRREC_DELETE_OBJECT] " +
"@pENTITY, @pSTART, @pEND, @pFORCE; " +
"SELECT @RC;",
parameters,
cancel);
var result = await repo.ExecuteQueryRawAsync(sp.BuildSql(), sp.BuildParameters(), cancel);
// The stored procedure returns 0 on success, error codes > 0 on failure
if (result > 0)
{
throw new DeleteObjectFailedException(request, $"DeleteObject stored procedure failed with error code: {result}");

View File

@@ -0,0 +1,51 @@
namespace ReC.Application.Common.Procedures;
/// <summary>
/// Represents the target entity type for stored procedure operations (Insert, Update, Delete).
/// </summary>
public enum EntityType
{
/// <summary>
/// A scheduled or configured action within a profile that invokes an endpoint (maps to TBREC_CFG_ACTION).
/// </summary>
Action,
/// <summary>
/// A REST endpoint URI configuration (maps to TBREC_CFG_ENDPOINT).
/// </summary>
Endpoint,
/// <summary>
/// Authentication credentials for an endpoint such as API key, Bearer token, or NTLM (maps to TBREC_CFG_ENDPOINT_AUTH).
/// </summary>
EndpointAuth,
/// <summary>
/// Key-value parameters attached to an endpoint (maps to TBREC_CFG_ENDPOINT_PARAMS).
/// </summary>
EndpointParams,
/// <summary>
/// A profile that groups one or more actions and defines execution settings (maps to TBREC_CFG_PROFILE).
/// </summary>
Profile,
/// <summary>
/// The outcome of an action invocation including HTTP status, headers, body, and error details (maps to TBREC_OUT_RESULT).
/// </summary>
Result
}
public static class EntityTypeExtensions
{
public static string ToDbString(this EntityType entityType) => entityType switch
{
EntityType.Action => "ACTION",
EntityType.Endpoint => "ENDPOINT",
EntityType.EndpointAuth => "ENDPOINT_AUTH",
EntityType.EndpointParams => "ENDPOINT_PARAMS",
EntityType.Profile => "PROFILE",
EntityType.Result => "RESULT",
_ => throw new ArgumentOutOfRangeException(nameof(entityType), $"Not expected entity type value: {entityType}")
};
}

View File

@@ -11,112 +11,95 @@ using ReC.Application.Endpoints.Commands;
using ReC.Application.Profile.Commands;
using ReC.Application.RecActions.Commands;
using ReC.Application.Results.Commands;
using System.Data;
namespace ReC.Application.Common.Procedures.InsertProcedure;
public record InsertObjectProcedure : IRequest<long>
{
/// <summary>
/// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT
/// Target entity for the insert operation.
/// </summary>
public string Entity { get; set; } = null!;
public required EntityType Entity { get; set; }
//TODO: update to set in authentication middleware or similar, and remove from procedure properties
internal string? AddedWho { get; private set; } = "ReC.API";
public InsertActionCommand Action { get; set; } = new();
public InsertEndpointCommand Endpoint { get; set; } = new();
public InsertEndpointAuthCommand EndpointAuth { get; set; } = new();
public InsertProfileCommand Profile { get; set; } = new();
public InsertResultCommand Result { get; set; } = new();
public InsertEndpointParamsCommand EndpointParams { get; set; } = new();
public InsertActionCommand? Action { get; set; }
public InsertEndpointCommand? Endpoint { get; set; }
public InsertEndpointAuthCommand? EndpointAuth { get; set; }
public InsertProfileCommand? Profile { get; set; }
public InsertResultCommand? Result { get; set; }
public InsertEndpointParamsCommand? EndpointParams { get; set; }
}
public class InsertObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlExceptionOptions> sqlExOpt) : IRequestHandler<InsertObjectProcedure, long>
{
public async Task<long> Handle(InsertObjectProcedure request, CancellationToken cancel)
{
var parameters = new[]
{
new SqlParameter("@pENTITY", request.Entity ?? (object)DBNull.Value),
new SqlParameter("@pADDED_WHO", (object?)request.AddedWho ?? DBNull.Value),
new SqlParameter("@pADDED_WHEN", (object?)DateTime.UtcNow ?? DBNull.Value),
new SqlParameter("@pACTION_PROFILE_ID", (object?)request.Action.ProfileId ?? DBNull.Value),
new SqlParameter("@pACTION_ACTIVE", (object?)request.Action.Active ?? DBNull.Value),
new SqlParameter("@pACTION_SEQUENCE", (object?)request.Action.Sequence ?? DBNull.Value),
new SqlParameter("@pACTION_ENDPOINT_ID", (object?)request.Action.EndpointId ?? DBNull.Value),
new SqlParameter("@pACTION_ENDPOINT_AUTH_ID", (object?)request.Action.EndpointAuthId ?? DBNull.Value),
new SqlParameter("@pACTION_ENDPOINT_PARAMS_ID", (object?)request.Action.EndpointParamsId ?? DBNull.Value),
new SqlParameter("@pACTION_SQL_CONNECTION_ID", (object?)request.Action.SqlConnectionId ?? DBNull.Value),
new SqlParameter("@pACTION_TYPE_ID", (object?)(byte?)request.Action.TypeId ?? DBNull.Value),
new SqlParameter("@pACTION_PRE_SQL", (object?)request.Action.PreSql ?? DBNull.Value),
new SqlParameter("@pACTION_HEADER_SQL", (object?)request.Action.HeaderSql ?? DBNull.Value),
new SqlParameter("@pACTION_BODY_SQL", (object?)request.Action.BodySql ?? DBNull.Value),
new SqlParameter("@pACTION_POST_SQL", (object?)request.Action.PostSql ?? DBNull.Value),
new SqlParameter("@pACTION_ERROR_ACTION_ID", (object?)request.Action.ErrorActionId ?? DBNull.Value),
new SqlParameter("@pENDPOINT_ACTIVE", (object?)request.Endpoint.Active ?? DBNull.Value),
new SqlParameter("@pENDPOINT_DESCRIPTION", (object?)request.Endpoint.Description ?? DBNull.Value),
new SqlParameter("@pENDPOINT_URI", (object?)request.Endpoint.Uri ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_ACTIVE", (object?)request.EndpointAuth.Active ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_DESCRIPTION", (object?)request.EndpointAuth.Description ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_TYPE_ID", (object?)request.EndpointAuth.TypeId ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_API_KEY", (object?)request.EndpointAuth.ApiKey ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_API_VALUE", (object?)request.EndpointAuth.ApiValue ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_API_KEY_ADD_TO_ID", (object?)request.EndpointAuth.ApiKeyAddToId ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_TOKEN", (object?)request.EndpointAuth.Token ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_USERNAME", (object?)request.EndpointAuth.Username ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_PASSWORD", (object?)request.EndpointAuth.Password ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_DOMAIN", (object?)request.EndpointAuth.Domain ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_WORKSTATION", (object?)request.EndpointAuth.Workstation ?? DBNull.Value),
new SqlParameter("@pPROFILE_ACTIVE", (object?)request.Profile.Active ?? DBNull.Value),
new SqlParameter("@pPROFILE_TYPE_ID", (object?)request.Profile.TypeId ?? DBNull.Value),
new SqlParameter("@pPROFILE_MANDANTOR", (object?)request.Profile.Mandantor ?? DBNull.Value),
new SqlParameter("@pPROFILE_NAME", (object?)request.Profile.Name ?? DBNull.Value),
new SqlParameter("@pPROFILE_DESCRIPTION", (object?)request.Profile.Description ?? DBNull.Value),
new SqlParameter("@pPROFILE_LOG_LEVEL_ID", (object?)request.Profile.LogLevelId ?? DBNull.Value),
new SqlParameter("@pPROFILE_LANGUAGE_ID", (object?)request.Profile.LanguageId ?? DBNull.Value),
new SqlParameter("@pRESULT_ACTION_ID", (object?)request.Result.ActionId ?? DBNull.Value),
new SqlParameter("@pRESULT_STATUS_ID", (object?)request.Result.StatusId ?? DBNull.Value),
new SqlParameter("@pRESULT_HEADER", (object?)request.Result.Header ?? DBNull.Value),
new SqlParameter("@pRESULT_BODY", (object?)request.Result.Body ?? DBNull.Value),
new SqlParameter("@pRESULT_INFO", (object?)request.Result.Info ?? DBNull.Value),
new SqlParameter("@pRESULT_ERROR", (object?)request.Result.Error ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_ACTIVE", (object?)request.EndpointParams.Active ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_DESCRIPTION", (object?)request.EndpointParams.Description ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_GROUP_ID", (object?)request.EndpointParams.GroupId ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_SEQUENCE", (object?)request.EndpointParams.Sequence ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_KEY", (object?)request.EndpointParams.Key ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_VALUE", (object?)request.EndpointParams.Value ?? DBNull.Value),
new SqlParameter
{
ParameterName = "@oGUID",
SqlDbType = System.Data.SqlDbType.BigInt,
Direction = System.Data.ParameterDirection.Output
}
};
var sp = new StoredProcedureBuilder("[dbo].[PRREC_INSERT_OBJECT]")
.Add("pENTITY", request.Entity)
.Add("pADDED_WHO", request.AddedWho)
.Add("pADDED_WHEN", DateTime.UtcNow)
.Add("pACTION_PROFILE_ID", request.Action?.ProfileId)
.Add("pACTION_ACTIVE", request.Action?.Active)
.Add("pACTION_SEQUENCE", request.Action?.Sequence, SqlDbType.TinyInt)
.Add("pACTION_ENDPOINT_ID", request.Action?.EndpointId)
.Add("pACTION_ENDPOINT_AUTH_ID", request.Action?.EndpointAuthId)
.Add("pACTION_ENDPOINT_PARAMS_ID", request.Action?.EndpointParamsId, SqlDbType.SmallInt)
.Add("pACTION_SQL_CONNECTION_ID", request.Action?.SqlConnectionId, SqlDbType.SmallInt)
.Add("pACTION_TYPE_ID", request.Action?.TypeId is not null ? (byte)request.Action.TypeId : null, SqlDbType.TinyInt)
.Add("pACTION_PRE_SQL", request.Action?.PreSql)
.Add("pACTION_HEADER_SQL", request.Action?.HeaderSql)
.Add("pACTION_BODY_SQL", request.Action?.BodySql)
.Add("pACTION_POST_SQL", request.Action?.PostSql)
.Add("pACTION_ERROR_ACTION_ID", request.Action?.ErrorActionId, SqlDbType.TinyInt)
.Add("pENDPOINT_ACTIVE", request.Endpoint?.Active)
.Add("pENDPOINT_DESCRIPTION", request.Endpoint?.Description)
.Add("pENDPOINT_URI", request.Endpoint?.Uri)
.Add("pENDPOINT_AUTH_ACTIVE", request.EndpointAuth?.Active)
.Add("pENDPOINT_AUTH_DESCRIPTION", request.EndpointAuth?.Description)
.Add("pENDPOINT_AUTH_TYPE_ID", request.EndpointAuth?.TypeId, SqlDbType.TinyInt)
.Add("pENDPOINT_AUTH_API_KEY", request.EndpointAuth?.ApiKey)
.Add("pENDPOINT_AUTH_API_VALUE", request.EndpointAuth?.ApiValue)
.Add("pENDPOINT_AUTH_API_KEY_ADD_TO_ID", request.EndpointAuth?.ApiKeyAddToId)
.Add("pENDPOINT_AUTH_TOKEN", request.EndpointAuth?.Token)
.Add("pENDPOINT_AUTH_USERNAME", request.EndpointAuth?.Username)
.Add("pENDPOINT_AUTH_PASSWORD", request.EndpointAuth?.Password)
.Add("pENDPOINT_AUTH_DOMAIN", request.EndpointAuth?.Domain)
.Add("pENDPOINT_AUTH_WORKSTATION", request.EndpointAuth?.Workstation)
.Add("pPROFILE_ACTIVE", request.Profile?.Active)
.Add("pPROFILE_TYPE_ID", request.Profile?.TypeId, SqlDbType.TinyInt)
.Add("pPROFILE_MANDANTOR", request.Profile?.Mandantor)
.Add("pPROFILE_NAME", request.Profile?.Name)
.Add("pPROFILE_DESCRIPTION", request.Profile?.Description)
.Add("pPROFILE_LOG_LEVEL_ID", request.Profile?.LogLevelId, SqlDbType.TinyInt)
.Add("pPROFILE_LANGUAGE_ID", request.Profile?.LanguageId, SqlDbType.SmallInt)
.Add("pRESULT_ACTION_ID", request.Result?.ActionId)
.Add("pRESULT_STATUS_ID", request.Result?.Status, SqlDbType.TinyInt)
.Add("pRESULT_TYPE_ID", request.Result?.Type is not null ? (byte)request.Result.Type : null, SqlDbType.TinyInt)
.Add("pRESULT_HEADER", request.Result?.Header)
.Add("pRESULT_BODY", request.Result?.Body)
.Add("pRESULT_INFO_ID", request.Result?.Info, SqlDbType.SmallInt)
.Add("pRESULT_INFO_DETAIL", request.Result?.InfoDetail)
.Add("pRESULT_ERROR", request.Result?.Error)
.Add("pRESULT_BATCH_ID", request.Result?.References?.BatchId)
.Add("pRESULT_REFERENCE1", request.Result?.References?.Reference1)
.Add("pRESULT_REFERENCE2", request.Result?.References?.Reference2)
.Add("pRESULT_REFERENCE3", request.Result?.References?.Reference3)
.Add("pRESULT_REFERENCE4", request.Result?.References?.Reference4)
.Add("pRESULT_REFERENCE5", request.Result?.References?.Reference5)
.Add("pENDPOINT_PARAMS_ACTIVE", request.EndpointParams?.Active)
.Add("pENDPOINT_PARAMS_DESCRIPTION", request.EndpointParams?.Description)
.Add("pENDPOINT_PARAMS_GROUP_ID", request.EndpointParams?.GroupId, SqlDbType.SmallInt)
.Add("pENDPOINT_PARAMS_SEQUENCE", request.EndpointParams?.Sequence, SqlDbType.TinyInt)
.Add("pENDPOINT_PARAMS_KEY", request.EndpointParams?.Key)
.Add("pENDPOINT_PARAMS_VALUE", request.EndpointParams?.Value)
.AddOutput("oGUID", SqlDbType.BigInt);
try
{
await repo.ExecuteQueryRawAsync(
"EXEC [dbo].[PRREC_INSERT_OBJECT] " +
"@pENTITY, @pADDED_WHO, @pADDED_WHEN, " +
"@pACTION_PROFILE_ID, @pACTION_ACTIVE, @pACTION_SEQUENCE, @pACTION_ENDPOINT_ID, @pACTION_ENDPOINT_AUTH_ID, @pACTION_ENDPOINT_PARAMS_ID, @pACTION_SQL_CONNECTION_ID, @pACTION_TYPE_ID, @pACTION_PRE_SQL, @pACTION_HEADER_SQL, @pACTION_BODY_SQL, @pACTION_POST_SQL, @pACTION_ERROR_ACTION_ID, " +
"@pENDPOINT_ACTIVE, @pENDPOINT_DESCRIPTION, @pENDPOINT_URI, " +
"@pENDPOINT_AUTH_ACTIVE, @pENDPOINT_AUTH_DESCRIPTION, @pENDPOINT_AUTH_TYPE_ID, @pENDPOINT_AUTH_API_KEY, @pENDPOINT_AUTH_API_VALUE, @pENDPOINT_AUTH_API_KEY_ADD_TO_ID, @pENDPOINT_AUTH_TOKEN, @pENDPOINT_AUTH_USERNAME, @pENDPOINT_AUTH_PASSWORD, @pENDPOINT_AUTH_DOMAIN, @pENDPOINT_AUTH_WORKSTATION, " +
"@pPROFILE_ACTIVE, @pPROFILE_TYPE_ID, @pPROFILE_MANDANTOR, @pPROFILE_NAME, @pPROFILE_DESCRIPTION, @pPROFILE_LOG_LEVEL_ID, @pPROFILE_LANGUAGE_ID, " +
"@pRESULT_ACTION_ID, @pRESULT_STATUS_ID, @pRESULT_HEADER, @pRESULT_BODY, " +
"@pENDPOINT_PARAMS_ACTIVE, @pENDPOINT_PARAMS_DESCRIPTION, @pENDPOINT_PARAMS_GROUP_ID, @pENDPOINT_PARAMS_SEQUENCE, @pENDPOINT_PARAMS_KEY, @pENDPOINT_PARAMS_VALUE, " +
"@oGUID OUTPUT",
parameters,
cancel);
await repo.ExecuteQueryRawAsync(sp.BuildSql(), sp.BuildParameters(), cancel);
}
catch (SqlException ex)
{
@@ -126,12 +109,12 @@ public class InsertObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlE
throw;
}
var guidParam = parameters.Last();
var guidParam = sp.GetParameter("oGUID");
if (guidParam.Value != DBNull.Value)
if (guidParam.Value is long longValue)
if (guidParam?.Value != DBNull.Value)
if (guidParam!.Value is long longValue)
return longValue;
else if (long.TryParse(guidParam.Value.ToString(), out var guid))
else if (long.TryParse(guidParam.Value?.ToString(), out var guid))
return guid;
throw new InsertObjectFailedException(request, "InsertObject stored procedure did not return a valid identifier.");

View File

@@ -0,0 +1,81 @@
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Data;
using System.Text;
namespace ReC.Application.Common.Procedures;
internal sealed class StoredProcedureBuilder(string procedureName, string? returnVariable = null)
{
private readonly StringBuilder _execSql = returnVariable is not null
? new StringBuilder($"EXEC @{returnVariable} = {procedureName}")
: new StringBuilder($"EXEC {procedureName}");
private readonly List<SqlParameter> _parameters = [];
private char _separator = ' ';
public StoredProcedureBuilder Add(string name, object? value, SqlDbType? dbType = null)
{
if (value is null) return this;
_execSql.AppendLine($"{_separator}@{name} = @{name}");
_separator = ',';
if (!dbType.HasValue && value is DateTime)
dbType = SqlDbType.DateTime;
if (dbType.HasValue)
_parameters.Add(new SqlParameter($"@{name}", dbType.Value) { Value = value });
else
_parameters.Add(new SqlParameter($"@{name}", value));
return this;
}
public StoredProcedureBuilder Add(string name, EntityType entityType)
{
var entityTypeStr = entityType switch
{
EntityType.Action => "ACTION",
EntityType.Endpoint => "ENDPOINT",
EntityType.EndpointAuth => "ENDPOINT_AUTH",
EntityType.EndpointParams => "ENDPOINT_PARAMS",
EntityType.Profile => "PROFILE",
EntityType.Result => "RESULT",
_ => throw new ArgumentOutOfRangeException(nameof(entityType), $"Not expected entity type value: {entityType}")
};
return Add(name, entityTypeStr);
}
public StoredProcedureBuilder AddOutput(string name, SqlDbType dbType)
{
_execSql.AppendLine($"{_separator}@{name} = @{name} OUTPUT");
_separator = ',';
_parameters.Add(new SqlParameter
{
ParameterName = $"@{name}",
SqlDbType = dbType,
Direction = ParameterDirection.Output
});
return this;
}
public string BuildSql()
{
if (returnVariable is null)
return _execSql.ToString();
return new StringBuilder()
.AppendLine($"DECLARE @{returnVariable} SMALLINT = 0;")
.Append(_execSql).AppendLine(";")
.AppendLine($"SELECT @{returnVariable};")
.ToString();
}
public SqlParameter[] BuildParameters() => [.. _parameters];
public SqlParameter? GetParameter(string name) =>
_parameters.Find(p => p.ParameterName == $"@{name}");
}

View File

@@ -1,4 +1,6 @@
namespace ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.RecActions.Commands;
namespace ReC.Application.Common.Procedures.UpdateProcedure.Dto;
public record UpdateResultDto
{
@@ -6,4 +8,8 @@ public record UpdateResultDto
public short? StatusId { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
public short? Info { get; set; }
public string? InfoDetail { get; set; }
public string? Error { get; set; }
public InvokeReferences? References { get; set; }
}

View File

@@ -6,21 +6,16 @@ using Microsoft.Extensions.Options;
using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Options;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.EndpointAuth.Commands;
using ReC.Application.EndpointParams.Commands;
using ReC.Application.Endpoints.Commands;
using ReC.Application.Profile.Commands;
using ReC.Application.RecActions.Commands;
using ReC.Application.Results.Commands;
using System.Data;
namespace ReC.Application.Common.Procedures.UpdateProcedure;
public record UpdateObjectProcedure : IRequest<int>
{
/// <summary>
/// Target entity: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT
/// Target entity for the update operation.
/// </summary>
public string Entity { get; set; } = null!;
public required EntityType Entity { get; set; }
/// <summary>
/// Target GUID to update (required)
@@ -42,85 +37,72 @@ public class UpdateObjectProcedureHandler(IRepository repo, IOptionsMonitor<SqlE
{
public async Task<int> Handle(UpdateObjectProcedure request, CancellationToken cancel)
{
var parameters = new[]
{
new SqlParameter("@pENTITY", request.Entity ?? (object)DBNull.Value),
new SqlParameter("@pGUID", (object?)request.Id ?? DBNull.Value),
new SqlParameter("@pCHANGED_WHO", (object?)request.ChangedWho ?? DBNull.Value),
new SqlParameter("@pCHANGED_WHEN", (object?)DateTime.UtcNow ?? DBNull.Value),
new SqlParameter("@pACTION_PROFILE_ID", (object?)request.Action.ProfileId ?? DBNull.Value),
new SqlParameter("@pACTION_ACTIVE", (object?)request.Action.Active ?? DBNull.Value),
new SqlParameter("@pACTION_SEQUENCE", (object?)request.Action.Sequence ?? DBNull.Value),
new SqlParameter("@pACTION_ENDPOINT_ID", (object?)request.Action.EndpointId ?? DBNull.Value),
new SqlParameter("@pACTION_ENDPOINT_AUTH_ID", (object?)request.Action.EndpointAuthId ?? DBNull.Value),
new SqlParameter("@pACTION_ENDPOINT_PARAMS_ID", (object?)request.Action.EndpointParamsId ?? DBNull.Value),
new SqlParameter("@pACTION_SQL_CONNECTION_ID", (object?)request.Action.SqlConnectionId ?? DBNull.Value),
new SqlParameter("@pACTION_TYPE_ID", (object?)request.Action.TypeId ?? DBNull.Value),
new SqlParameter("@pACTION_PRE_SQL", (object?)request.Action.PreSql ?? DBNull.Value),
new SqlParameter("@pACTION_HEADER_SQL", (object?)request.Action.HeaderSql ?? DBNull.Value),
new SqlParameter("@pACTION_BODY_SQL", (object?)request.Action.BodySql ?? DBNull.Value),
new SqlParameter("@pACTION_POST_SQL", (object?)request.Action.PostSql ?? DBNull.Value),
new SqlParameter("@pACTION_ERROR_ACTION_ID", (object?)request.Action.ErrorActionId ?? DBNull.Value),
new SqlParameter("@pENDPOINT_ACTIVE", (object?)request.Endpoint.Active ?? DBNull.Value),
new SqlParameter("@pENDPOINT_DESCRIPTION", (object?)request.Endpoint.Description ?? DBNull.Value),
new SqlParameter("@pENDPOINT_URI", (object?)request.Endpoint.Uri ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_ACTIVE", (object?)request.EndpointAuth.Active ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_DESCRIPTION", (object?)request.EndpointAuth.Description ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_TYPE_ID", (object?)request.EndpointAuth.TypeId ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_API_KEY", (object?)request.EndpointAuth.ApiKey ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_API_VALUE", (object?)request.EndpointAuth.ApiValue ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_API_KEY_ADD_TO_ID", (object?)request.EndpointAuth.ApiKeyAddToId ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_TOKEN", (object?)request.EndpointAuth.Token ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_USERNAME", (object?)request.EndpointAuth.Username ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_PASSWORD", (object?)request.EndpointAuth.Password ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_DOMAIN", (object?)request.EndpointAuth.Domain ?? DBNull.Value),
new SqlParameter("@pENDPOINT_AUTH_WORKSTATION", (object?)request.EndpointAuth.Workstation ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_ACTIVE", (object?)request.EndpointParams.Active ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_DESCRIPTION", (object?)request.EndpointParams.Description ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_GROUP_ID", (object?)request.EndpointParams.GroupId ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_SEQUENCE", (object?)request.EndpointParams.Sequence ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_KEY", (object?)request.EndpointParams.Key ?? DBNull.Value),
new SqlParameter("@pENDPOINT_PARAMS_VALUE", (object?)request.EndpointParams.Value ?? DBNull.Value),
new SqlParameter("@pPROFILE_ACTIVE", (object?)request.Profile.Active ?? DBNull.Value),
new SqlParameter("@pPROFILE_TYPE_ID", (object?)request.Profile.TypeId ?? DBNull.Value),
new SqlParameter("@pPROFILE_MANDANTOR", (object?)request.Profile.Mandantor ?? DBNull.Value),
new SqlParameter("@pPROFILE_NAME", (object?)request.Profile.Name ?? DBNull.Value),
new SqlParameter("@pPROFILE_DESCRIPTION", (object?)request.Profile.Description ?? DBNull.Value),
new SqlParameter("@pPROFILE_LOG_LEVEL_ID", (object?)request.Profile.LogLevelId ?? DBNull.Value),
new SqlParameter("@pPROFILE_LANGUAGE_ID", (object?)request.Profile.LanguageId ?? DBNull.Value),
new SqlParameter("@pPROFILE_FIRST_RUN", (object?)request.Profile.FirstRun ?? DBNull.Value),
new SqlParameter("@pPROFILE_LAST_RUN", (object?)request.Profile.LastRun ?? DBNull.Value),
new SqlParameter("@pPROFILE_LAST_RESULT", (object?)request.Profile.LastResult ?? DBNull.Value),
new SqlParameter("@pRESULT_ACTION_ID", (object?)request.Result.ActionId ?? DBNull.Value),
new SqlParameter("@pRESULT_STATUS_ID", (object?)request.Result.StatusId ?? DBNull.Value),
new SqlParameter("@pRESULT_HEADER", (object?)request.Result.Header ?? DBNull.Value),
new SqlParameter("@pRESULT_BODY", (object?)request.Result.Body ?? DBNull.Value)
};
var sp = new StoredProcedureBuilder("[dbo].[PRREC_UPDATE_OBJECT]", "RC")
.Add("pENTITY", request.Entity)
.Add("pGUID", request.Id)
.Add("pCHANGED_WHO", request.ChangedWho)
.Add("pCHANGED_WHEN", DateTime.UtcNow)
.Add("pACTION_PROFILE_ID", request.Action.ProfileId)
.Add("pACTION_ACTIVE", request.Action.Active)
.Add("pACTION_SEQUENCE", request.Action.Sequence, SqlDbType.TinyInt)
.Add("pACTION_ENDPOINT_ID", request.Action.EndpointId)
.Add("pACTION_ENDPOINT_AUTH_ID", request.Action.EndpointAuthId)
.Add("pACTION_ENDPOINT_PARAMS_ID", request.Action.EndpointParamsId, SqlDbType.SmallInt)
.Add("pACTION_SQL_CONNECTION_ID", request.Action.SqlConnectionId, SqlDbType.SmallInt)
.Add("pACTION_TYPE_ID", request.Action.TypeId, SqlDbType.TinyInt)
.Add("pACTION_PRE_SQL", request.Action.PreSql)
.Add("pACTION_HEADER_SQL", request.Action.HeaderSql)
.Add("pACTION_BODY_SQL", request.Action.BodySql)
.Add("pACTION_POST_SQL", request.Action.PostSql)
.Add("pACTION_ERROR_ACTION_ID", request.Action.ErrorActionId, SqlDbType.TinyInt)
.Add("pENDPOINT_ACTIVE", request.Endpoint.Active)
.Add("pENDPOINT_DESCRIPTION", request.Endpoint.Description)
.Add("pENDPOINT_URI", request.Endpoint.Uri)
.Add("pENDPOINT_AUTH_ACTIVE", request.EndpointAuth.Active)
.Add("pENDPOINT_AUTH_DESCRIPTION", request.EndpointAuth.Description)
.Add("pENDPOINT_AUTH_TYPE_ID", request.EndpointAuth.TypeId, SqlDbType.TinyInt)
.Add("pENDPOINT_AUTH_API_KEY", request.EndpointAuth.ApiKey)
.Add("pENDPOINT_AUTH_API_VALUE", request.EndpointAuth.ApiValue)
.Add("pENDPOINT_AUTH_API_KEY_ADD_TO_ID", request.EndpointAuth.ApiKeyAddToId)
.Add("pENDPOINT_AUTH_TOKEN", request.EndpointAuth.Token)
.Add("pENDPOINT_AUTH_USERNAME", request.EndpointAuth.Username)
.Add("pENDPOINT_AUTH_PASSWORD", request.EndpointAuth.Password)
.Add("pENDPOINT_AUTH_DOMAIN", request.EndpointAuth.Domain)
.Add("pENDPOINT_AUTH_WORKSTATION", request.EndpointAuth.Workstation)
.Add("pENDPOINT_PARAMS_ACTIVE", request.EndpointParams.Active)
.Add("pENDPOINT_PARAMS_DESCRIPTION", request.EndpointParams.Description)
.Add("pENDPOINT_PARAMS_GROUP_ID", request.EndpointParams.GroupId, SqlDbType.SmallInt)
.Add("pENDPOINT_PARAMS_SEQUENCE", request.EndpointParams.Sequence, SqlDbType.TinyInt)
.Add("pENDPOINT_PARAMS_KEY", request.EndpointParams.Key)
.Add("pENDPOINT_PARAMS_VALUE", request.EndpointParams.Value)
.Add("pPROFILE_ACTIVE", request.Profile.Active)
.Add("pPROFILE_TYPE_ID", request.Profile.TypeId, SqlDbType.TinyInt)
.Add("pPROFILE_MANDANTOR", request.Profile.Mandantor)
.Add("pPROFILE_NAME", request.Profile.Name)
.Add("pPROFILE_DESCRIPTION", request.Profile.Description)
.Add("pPROFILE_LOG_LEVEL_ID", request.Profile.LogLevelId, SqlDbType.TinyInt)
.Add("pPROFILE_LANGUAGE_ID", request.Profile.LanguageId, SqlDbType.SmallInt)
.Add("pPROFILE_FIRST_RUN", request.Profile.FirstRun)
.Add("pPROFILE_LAST_RUN", request.Profile.LastRun)
.Add("pPROFILE_LAST_RESULT", request.Profile.LastResult)
.Add("pRESULT_ACTION_ID", request.Result.ActionId)
.Add("pRESULT_STATUS_ID", request.Result.StatusId, SqlDbType.TinyInt)
.Add("pRESULT_HEADER", request.Result.Header)
.Add("pRESULT_BODY", request.Result.Body)
.Add("pRESULT_INFO_ID", request.Result.Info, SqlDbType.SmallInt)
.Add("pRESULT_INFO_DETAIL", request.Result.InfoDetail)
.Add("pRESULT_ERROR", request.Result.Error)
.Add("pRESULT_BATCH_ID", request.Result.References?.BatchId)
.Add("pRESULT_REFERENCE1", request.Result.References?.Reference1)
.Add("pRESULT_REFERENCE2", request.Result.References?.Reference2)
.Add("pRESULT_REFERENCE3", request.Result.References?.Reference3)
.Add("pRESULT_REFERENCE4", request.Result.References?.Reference4)
.Add("pRESULT_REFERENCE5", request.Result.References?.Reference5);
try
{
var result = await repo.ExecuteQueryRawAsync(
"DECLARE @RC SMALLINT = 0; " +
"EXEC @RC = [dbo].[PRREC_UPDATE_OBJECT] " +
"@pENTITY, @pGUID, @pCHANGED_WHO, @pCHANGED_WHEN, " +
"@pACTION_PROFILE_ID, @pACTION_ACTIVE, @pACTION_SEQUENCE, @pACTION_ENDPOINT_ID, @pACTION_ENDPOINT_AUTH_ID, @pACTION_ENDPOINT_PARAMS_ID, @pACTION_SQL_CONNECTION_ID, @pACTION_TYPE_ID, @pACTION_PRE_SQL, @pACTION_HEADER_SQL, @pACTION_BODY_SQL, @pACTION_POST_SQL, @pACTION_ERROR_ACTION_ID, " +
"@pENDPOINT_ACTIVE, @pENDPOINT_DESCRIPTION, @pENDPOINT_URI, " +
"@pENDPOINT_AUTH_ACTIVE, @pENDPOINT_AUTH_DESCRIPTION, @pENDPOINT_AUTH_TYPE_ID, @pENDPOINT_AUTH_API_KEY, @pENDPOINT_AUTH_API_VALUE, @pENDPOINT_AUTH_API_KEY_ADD_TO_ID, @pENDPOINT_AUTH_TOKEN, @pENDPOINT_AUTH_USERNAME, @pENDPOINT_AUTH_PASSWORD, @pENDPOINT_AUTH_DOMAIN, @pENDPOINT_AUTH_WORKSTATION, " +
"@pENDPOINT_PARAMS_ACTIVE, @pENDPOINT_PARAMS_DESCRIPTION, @pENDPOINT_PARAMS_GROUP_ID, @pENDPOINT_PARAMS_SEQUENCE, @pENDPOINT_PARAMS_KEY, @pENDPOINT_PARAMS_VALUE, " +
"@pPROFILE_ACTIVE, @pPROFILE_TYPE_ID, @pPROFILE_MANDANTOR, @pPROFILE_NAME, @pPROFILE_DESCRIPTION, @pPROFILE_LOG_LEVEL_ID, @pPROFILE_LANGUAGE_ID, @pPROFILE_FIRST_RUN, @pPROFILE_LAST_RUN, @pPROFILE_LAST_RESULT, " +
"@pRESULT_ACTION_ID, @pRESULT_STATUS_ID, @pRESULT_HEADER, @pRESULT_BODY; " +
"SELECT @RC;",
parameters,
cancel);
var result = await repo.ExecuteQueryRawAsync(sp.BuildSql(), sp.BuildParameters(), cancel);
// The stored procedure returns 0 on success, error codes > 0 on failure
if (result > 0)
{
throw new UpdateObjectFailedException(request, $"UpdateObject stored procedure failed with error code: {result}");

View File

@@ -0,0 +1,22 @@
using FluentValidation;
using ReC.Application.Common.Procedures.DeleteProcedure;
namespace ReC.Application.Common.Validations;
public class DeleteObjectProcedureValidator : AbstractValidator<DeleteObjectProcedure>
{
public DeleteObjectProcedureValidator()
{
RuleFor(x => x.Entity)
.IsInEnum()
.WithMessage("ENTITY must be a valid EntityType value.");
RuleFor(x => x.Start)
.GreaterThan(0)
.WithMessage("Start GUID/ID must be greater than 0.");
RuleFor(x => x.End)
.GreaterThanOrEqualTo(x => x.Start)
.WithMessage("End GUID/ID must be greater than or equal to Start GUID/ID.");
}
}

View File

@@ -7,66 +7,60 @@ public class InsertObjectProcedureValidator : AbstractValidator<InsertObjectProc
{
public InsertObjectProcedureValidator()
{
// ENTITY must be one of the allowed values
RuleFor(x => x.Entity)
.NotEmpty()
.Must(e => e is "ACTION" or "ENDPOINT" or "ENDPOINT_AUTH" or "ENDPOINT_PARAMS" or "PROFILE" or "RESULT")
.WithMessage("ENTITY must be one of: ACTION, ENDPOINT, ENDPOINT_AUTH, ENDPOINT_PARAMS, PROFILE, RESULT.");
.IsInEnum()
.WithMessage("ENTITY must be a valid EntityType value.");
// ACTION validation
When(x => x.Entity == "ACTION", () =>
When(x => x.Action != null, () =>
{
RuleFor(x => x.Action.ProfileId)
RuleFor(x => x.Action!.ProfileId)
.NotNull()
.WithMessage("ACTION requires ActionProfileId (maps to @pACTION_PROFILE_ID).");
RuleFor(x => x.Action.EndpointId)
RuleFor(x => x.Action!.EndpointId)
.NotNull()
.WithMessage("ACTION requires ActionEndpointId (maps to @pACTION_ENDPOINT_ID).");
});
// ENDPOINT validation
When(x => x.Entity == "ENDPOINT", () =>
When(x => x.Endpoint != null, () =>
{
RuleFor(x => x.Endpoint.Uri)
RuleFor(x => x.Endpoint!.Uri)
.NotEmpty()
.WithMessage("ENDPOINT requires EndpointUri (maps to @pENDPOINT_URI).")
.MaximumLength(2000);
});
// PROFILE validation
When(x => x.Entity == "PROFILE", () =>
When(x => x.Profile != null, () =>
{
RuleFor(x => x.Profile.Name)
RuleFor(x => x.Profile!.Name)
.NotEmpty()
.WithMessage("PROFILE requires ProfileName (maps to @pPROFILE_NAME).")
.MaximumLength(50);
RuleFor(x => x.Profile.Mandantor)
RuleFor(x => x.Profile!.Mandantor)
.MaximumLength(50)
.When(x => x.Profile.Mandantor != null);
.When(x => x.Profile!.Mandantor != null);
RuleFor(x => x.Profile.Description)
RuleFor(x => x.Profile!.Description)
.MaximumLength(250)
.When(x => x.Profile.Description != null);
.When(x => x.Profile!.Description != null);
});
// RESULT validation
When(x => x.Entity == "RESULT", () =>
When(x => x.Result != null, () =>
{
RuleFor(x => x.Result.ActionId)
RuleFor(x => x.Result!.ActionId)
.NotNull()
.WithMessage("RESULT requires ResultActionId (maps to @pRESULT_ACTION_ID).");
RuleFor(x => x.Result.StatusId)
.NotNull()
.WithMessage("RESULT requires ResultStatusId (maps to @pRESULT_STATUS_ID).");
});
// ENDPOINT_PARAMS validation
When(x => x.Entity == "ENDPOINT_PARAMS", () =>
When(x => x.EndpointParams != null, () =>
{
RuleFor(x => x.EndpointParams.GroupId)
RuleFor(x => x.EndpointParams!.GroupId)
.NotNull()
.WithMessage("ENDPOINT_PARAMS requires EndpointParamsGroupId (maps to @pENDPOINT_PARAMS_GROUP_ID).");
});
@@ -76,12 +70,12 @@ public class InsertObjectProcedureValidator : AbstractValidator<InsertObjectProc
.MaximumLength(50)
.When(x => x.AddedWho != null);
RuleFor(x => x.Endpoint.Description)
RuleFor(x => x.Endpoint!.Description)
.MaximumLength(250)
.When(x => x.Endpoint.Description != null);
.When(x => x.Endpoint is { Description: not null });
RuleFor(x => x.EndpointAuth.Description)
RuleFor(x => x.EndpointAuth!.Description)
.MaximumLength(250)
.When(x => x.EndpointAuth.Description != null);
.When(x => x.EndpointAuth is { Description: not null });
}
}

View File

@@ -0,0 +1,21 @@
using FluentValidation;
using ReC.Application.Results.Commands;
namespace ReC.Application.Common.Validations;
public class InsertResultCommandValidator : AbstractValidator<InsertResultCommand>
{
public InsertResultCommandValidator()
{
RuleFor(x => x.ActionId)
.NotNull()
.WithMessage("ActionId is required.")
.GreaterThan(0L)
.When(x => x.ActionId.HasValue)
.WithMessage("ActionId must be greater than 0.");
RuleFor(x => x.References.BatchId)
.NotEmpty()
.WithMessage("BatchId is required.");
}
}

View File

@@ -0,0 +1,22 @@
using FluentValidation;
using MediatR;
using ReC.Application.RecActions.Commands;
using ReC.Application.Results.Queries;
namespace ReC.Application.Common.Validations;
public class InvokeBatchRecActionViewsCommandValidator : AbstractValidator<InvokeBatchRecActionViewsCommand>
{
public InvokeBatchRecActionViewsCommandValidator(ISender sender)
{
RuleFor(x => x.References.BatchId)
.NotEmpty()
.WithMessage("BatchId is required.")
.MustAsync(async (batchId, cancel) =>
{
var any = await sender.Send(new AnyResultViewQuery(BatchId: batchId), cancel);
return !any;
})
.WithMessage(x => $"Cannot invoke rec actions for batch '{x.References.BatchId}' because there are already results associated with it.");
}
}

View File

@@ -0,0 +1,15 @@
using FluentValidation;
using ReC.Application.Profile.Queries;
namespace ReC.Application.Common.Validations;
public class ReadProfileViewQueryValidator : AbstractValidator<ReadProfileViewQuery>
{
public ReadProfileViewQueryValidator()
{
RuleFor(x => x.Id)
.GreaterThan(0)
.When(x => x.Id.HasValue)
.WithMessage("Id must be greater than 0.");
}
}

View File

@@ -0,0 +1,15 @@
using FluentValidation;
using ReC.Application.RecActions.Queries;
namespace ReC.Application.Common.Validations;
public class ReadRecActionViewQueryValidator : AbstractValidator<ReadRecActionViewQuery>
{
public ReadRecActionViewQueryValidator()
{
RuleFor(x => x.ProfileId)
.GreaterThan(0)
.When(x => x.ProfileId.HasValue)
.WithMessage("ProfileId must be greater than 0.");
}
}

View File

@@ -0,0 +1,34 @@
using FluentValidation;
using ReC.Application.Results.Queries;
namespace ReC.Application.Common.Validations;
public class ReadResultViewQueryValidator : AbstractValidator<ReadResultViewQuery>
{
public ReadResultViewQueryValidator()
{
RuleFor(x => x)
.Must(x => x.Id.HasValue || x.ActionId.HasValue || x.ProfileId.HasValue || x.BatchId is not null)
.WithMessage("At least one filter (Id, ActionId, ProfileId or BatchId) must be provided.");
RuleFor(x => x.Id)
.GreaterThan(0)
.When(x => x.Id.HasValue)
.WithMessage("Id must be greater than 0.");
RuleFor(x => x.ActionId)
.GreaterThan(0)
.When(x => x.ActionId.HasValue)
.WithMessage("ActionId must be greater than 0.");
RuleFor(x => x.ProfileId)
.GreaterThan(0)
.When(x => x.ProfileId.HasValue)
.WithMessage("ProfileId must be greater than 0.");
RuleFor(x => x.BatchId)
.NotEmpty()
.When(x => x.BatchId is not null)
.WithMessage("BatchId must not be empty when provided.");
}
}

View File

@@ -0,0 +1,52 @@
using FluentValidation;
using ReC.Application.Common.Procedures.UpdateProcedure;
namespace ReC.Application.Common.Validations;
public class UpdateObjectProcedureValidator : AbstractValidator<UpdateObjectProcedure>
{
public UpdateObjectProcedureValidator()
{
RuleFor(x => x.Entity)
.IsInEnum()
.WithMessage("ENTITY must be a valid EntityType value.");
RuleFor(x => x.Id)
.GreaterThan(0)
.WithMessage("Target GUID/ID must be greater than 0.");
RuleFor(x => x.ChangedWho)
.MaximumLength(50)
.When(x => x.ChangedWho != null);
When(x => x.Endpoint is { Description: not null }, () =>
{
RuleFor(x => x.Endpoint.Description)
.MaximumLength(250);
});
When(x => x.EndpointAuth is { Description: not null }, () =>
{
RuleFor(x => x.EndpointAuth.Description)
.MaximumLength(250);
});
When(x => x.Profile is { Name: not null }, () =>
{
RuleFor(x => x.Profile.Name)
.MaximumLength(50);
});
When(x => x.Profile is { Mandantor: not null }, () =>
{
RuleFor(x => x.Profile.Mandantor)
.MaximumLength(50);
});
When(x => x.Profile is { Description: not null }, () =>
{
RuleFor(x => x.Profile.Description)
.MaximumLength(250);
});
}
}

View File

@@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ReC.Application.Common.Behaviors;
using ReC.Application.Common.Behaviors.Action;
using ReC.Application.Common.Behaviors.InvokeAction;
using ReC.Application.Common.Constants;
using ReC.Application.Common.Options;
using ReC.Application.RecActions.Commands;

View File

@@ -1,5 +1,6 @@
using MediatR;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.EndpointAuth.Commands;
@@ -27,7 +28,7 @@ public class DeleteEndpointAuthProcedureHandler(ISender sender) : IRequestHandle
{
return await sender.Send(new DeleteObjectProcedure
{
Entity = "ENDPOINT_AUTH",
Entity = EntityType.EndpointAuth,
Start = request.Start,
End = request.End,
Force = request.Force

View File

@@ -1,5 +1,6 @@
using MediatR;
using MediatR;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.EndpointAuth.Commands;
@@ -24,7 +25,7 @@ public class InsertEndpointAuthProcedureHandler(ISender sender) : IRequestHandle
{
return await sender.Send(new InsertObjectProcedure
{
Entity = "ENDPOINT_AUTH",
Entity = EntityType.EndpointAuth,
EndpointAuth = request
}, cancel);
}

View File

@@ -1,6 +1,7 @@
using MediatR;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Common.Procedures;
namespace ReC.Application.EndpointAuth.Commands;
@@ -17,7 +18,7 @@ public class UpdateEndpointAuthProcedureHandler(ISender sender) : IRequestHandle
{
return await sender.Send(new UpdateObjectProcedure
{
Entity = "ENDPOINT_AUTH",
Entity = EntityType.EndpointAuth,
Id = request.Id,
EndpointAuth = request.Data
}, cancel);

View File

@@ -1,5 +1,6 @@
using MediatR;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.EndpointParams.Commands;
@@ -27,7 +28,7 @@ public class DeleteEndpointParamsProcedureHandler(ISender sender) : IRequestHand
{
return await sender.Send(new DeleteObjectProcedure
{
Entity = "ENDPOINT_PARAMS",
Entity = EntityType.EndpointParams,
Start = request.Start,
End = request.End,
Force = request.Force

View File

@@ -1,5 +1,6 @@
using MediatR;
using MediatR;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.EndpointParams.Commands;
@@ -19,7 +20,7 @@ public class InsertEndpointParamsProcedureHandler(ISender sender) : IRequestHand
{
return await sender.Send(new InsertObjectProcedure
{
Entity = "ENDPOINT_PARAMS",
Entity = EntityType.EndpointParams,
EndpointParams = request
}, cancel);
}

View File

@@ -1,6 +1,7 @@
using MediatR;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Common.Procedures;
namespace ReC.Application.EndpointParams.Commands;
@@ -17,7 +18,7 @@ public class UpdateEndpointParamsProcedureHandler(ISender sender) : IRequestHand
{
return await sender.Send(new UpdateObjectProcedure
{
Entity = "ENDPOINT_PARAMS",
Entity = EntityType.EndpointParams,
Id = request.Id,
EndpointParams = request.Data
}, cancel);

View File

@@ -1,5 +1,6 @@
using MediatR;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Endpoints.Commands;
@@ -27,7 +28,7 @@ public class DeleteEndpointProcedureHandler(ISender sender) : IRequestHandler<De
{
return await sender.Send(new DeleteObjectProcedure
{
Entity = "ENDPOINT",
Entity = EntityType.Endpoint,
Start = request.Start,
End = request.End,
Force = request.Force

View File

@@ -1,5 +1,6 @@
using MediatR;
using MediatR;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Endpoints.Commands;
@@ -16,7 +17,7 @@ public class InsertEndpointProcedureHandler(ISender sender) : IRequestHandler<In
{
return await sender.Send(new InsertObjectProcedure
{
Entity = "ENDPOINT",
Entity = EntityType.Endpoint,
Endpoint = request
}, cancel);
}

View File

@@ -1,6 +1,7 @@
using MediatR;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Endpoints.Commands;
@@ -17,7 +18,7 @@ public class UpdateEndpointProcedureHandler(ISender sender) : IRequestHandler<Up
{
return await sender.Send(new UpdateObjectProcedure
{
Entity = "ENDPOINT",
Entity = EntityType.Endpoint,
Id = request.Id,
Endpoint = request.Data
}, cancel);

View File

@@ -1,5 +1,6 @@
using MediatR;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Profile.Commands;
@@ -27,7 +28,7 @@ public class DeleteProfileProcedureHandler(ISender sender) : IRequestHandler<Del
{
return await sender.Send(new DeleteObjectProcedure
{
Entity = "PROFILE",
Entity = EntityType.Profile,
Start = request.Start,
End = request.End,
Force = request.Force

View File

@@ -1,5 +1,6 @@
using MediatR;
using MediatR;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Profile.Commands;
@@ -20,7 +21,7 @@ public class InsertProfileProcedureHandler(ISender sender) : IRequestHandler<Ins
{
return await sender.Send(new InsertObjectProcedure
{
Entity = "PROFILE",
Entity = EntityType.Profile,
Profile = request
}, cancel);
}

View File

@@ -1,6 +1,7 @@
using MediatR;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Profile.Commands;
@@ -17,7 +18,7 @@ public class UpdateProfileProcedureHandler(ISender sender) : IRequestHandler<Upd
{
return await sender.Send(new UpdateObjectProcedure
{
Entity = "PROFILE",
Entity = EntityType.Profile,
Id = request.Id,
Profile = request.Data
}, cancel);

View File

@@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="15.1.0" />
<PackageReference Include="AutoMapper" Version="16.1.1" />
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.6.0" />
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.1" />

View File

@@ -1,5 +1,6 @@
using MediatR;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.RecActions.Commands;
@@ -27,7 +28,7 @@ public class DeleteActionProcedureHandler(ISender sender) : IRequestHandler<Dele
{
return await sender.Send(new DeleteObjectProcedure
{
Entity = "ACTION",
Entity = EntityType.Action,
Start = request.Start,
End = request.End,
Force = request.Force

View File

@@ -1,6 +1,7 @@
using MediatR;
using MediatR;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Domain.Constants;
using ReC.Application.Common.Procedures;
namespace ReC.Application.RecActions.Commands;
@@ -27,7 +28,7 @@ public class InsertActionProcedureHandler(ISender sender) : IRequestHandler<Inse
{
return await sender.Send(new InsertObjectProcedure
{
Entity = "ACTION",
Entity = EntityType.Action,
Action = request
}, cancel);
}

View File

@@ -1,5 +1,6 @@
using DigitalData.Core.Abstractions.Interfaces;
using MediatR;
using MediatR;
using Microsoft.Extensions.Logging;
using ReC.Application.Common.Exceptions;
using ReC.Application.RecActions.Queries;
using ReC.Domain.Constants;
@@ -8,15 +9,10 @@ namespace ReC.Application.RecActions.Commands;
public record InvokeBatchRecActionViewsCommand : IRequest
{
public long ProfileId { get; init; }
public required InvokeReferences References { get; init; }
}
public static class InvokeBatchRecActionViewsCommandExtensions
{
public static Task InvokeBatchRecActionView(this ISender sender, long profileId, CancellationToken cancel = default)
=> sender.Send(new InvokeBatchRecActionViewsCommand { ProfileId = profileId }, cancel);
}
public class InvokeRecActionViewsCommandHandler(ISender sender) : IRequestHandler<InvokeBatchRecActionViewsCommand>
public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRecActionViewsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionViewsCommand>
{
public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
{
@@ -26,13 +22,30 @@ public class InvokeRecActionViewsCommandHandler(ISender sender) : IRequestHandle
{
try
{
await sender.Send(new InvokeRecActionViewCommand() { Action = action }, cancel);
await sender.Send(new InvokeRecActionViewCommand()
{
Action = action,
References = request.References
}, cancel);
}
catch
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)
{
switch (action.ErrorAction)
{
case ErrorAction.Continue:
logger?.LogError(ex, "Unexpected error during rec action. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
break;
default:
// Rethrow the exception to stop processing further actions

View File

@@ -1,5 +1,6 @@
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using ReC.Application.Common.Constants;
using ReC.Application.Common.Dto;
@@ -7,6 +8,7 @@ using ReC.Application.Common.Exceptions;
using ReC.Application.Common.Options;
using ReC.Application.Results.Commands;
using ReC.Domain.Constants;
using ReC.Domain.Views;
using System.Net;
using System.Net.Http.Headers;
using System.Text;
@@ -17,13 +19,25 @@ namespace ReC.Application.RecActions.Commands;
public record InvokeRecActionViewCommand : IRequest
{
public RecActionViewDto Action { get; set; } = null!;
public required InvokeReferences References { get; set; }
}
public record InvokeReferences
{
public required string BatchId { get; init; }
public string? Reference1 { get; init; }
public string? Reference2 { get; init; }
public string? Reference3 { get; init; }
public string? Reference4 { get; init; }
public string? Reference5 { get; init; }
}
public class InvokeRecActionViewCommandHandler(
IOptions<RecActionOptions> options,
ISender sender,
IHttpClientFactory clientFactory,
IConfiguration? config = null
IConfiguration? config = null,
ILogger<InvokeRecActionViewCommandHandler>? logger = null
) : IRequestHandler<InvokeRecActionViewCommand>
{
private readonly RecActionOptions _options = options.Value;
@@ -45,11 +59,47 @@ public class InvokeRecActionViewCommandHandler(
using var httpReq = CreateHttpRequestMessage(restType, action.EndpointUri);
if (action.Body is not null)
{
httpReq.Content = new StringContent(action.Body);
var contentType = action.Headers?.FirstOrDefault(h => h.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase));
if (contentType is not null && !string.IsNullOrWhiteSpace(contentType.Value.Value))
try { httpReq.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType.Value.Value); }
catch (FormatException ex)
{
logger?.LogWarning(ex, "Content-Type '{Value}' could not be parsed with strict validation, falling back to TryAddWithoutValidation. ActionId: {ActionId}, ProfileId: {ProfileId}", contentType.Value.Value, action.Id, action.ProfileId);
httpReq.Content.Headers.TryAddWithoutValidation("Content-Type", contentType.Value.Value);
}
else if (_options.AutoDetectHeaders)
{
var body = action.Body.TrimStart();
if (body.StartsWith('{') || body.StartsWith('['))
{
httpReq.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json") { CharSet = "utf-8" };
logger?.LogWarning("Content-Type header was not specified. Auto-detected 'application/json; charset=utf-8' based on body content. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
}
else if (body.StartsWith('<'))
{
httpReq.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xml") { CharSet = "utf-8" };
logger?.LogWarning("Content-Type header was not specified. Auto-detected 'application/xml; charset=utf-8' based on body content. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
}
}
}
if (action.Headers is not null)
foreach (var header in action.Headers)
httpReq.Headers.Add(header.Key, header.Value);
foreach (var header in action.Headers.Where(h => !h.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase)))
try { httpReq.Headers.Add(header.Key, header.Value); }
catch (FormatException ex)
{
logger?.LogWarning(ex, "Header '{Key}' could not be added with strict validation, falling back to TryAddWithoutValidation. ActionId: {ActionId}, ProfileId: {ProfileId}", header.Key, action.Id, action.ProfileId);
httpReq.Headers.TryAddWithoutValidation(header.Key, header.Value);
}
if (_options.AutoDetectHeaders && !httpReq.Headers.Contains("Accept"))
{
httpReq.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
logger?.LogWarning("Accept header was not specified. Defaulting to 'application/json'. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
}
switch (action.EndpointAuthType)
{
@@ -62,7 +112,12 @@ public class InvokeRecActionViewCommandHandler(
switch (action.EndpointAuthApiKeyAddTo)
{
case ApiKeyLocation.Header:
httpReq.Headers.Add(apiKey, apiValue);
try { httpReq.Headers.Add(apiKey, apiValue); }
catch (FormatException ex)
{
logger?.LogWarning(ex, "ApiKey header '{Key}' could not be added with strict validation, falling back to TryAddWithoutValidation. ActionId: {ActionId}, ProfileId: {ProfileId}", apiKey, action.Id, action.ProfileId);
httpReq.Headers.TryAddWithoutValidation(apiKey, apiValue);
}
break;
case ApiKeyLocation.Query:
var uriBuilder = new UriBuilder(httpReq.RequestUri!);
@@ -85,14 +140,24 @@ public class InvokeRecActionViewCommandHandler(
case EndpointAuthType.JwtBearer:
case EndpointAuthType.OAuth2:
if (action.EndpointAuthToken is string authToken)
httpReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
try { httpReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authToken); }
catch (FormatException ex)
{
logger?.LogWarning(ex, "Bearer token could not be set with strict validation, falling back to TryAddWithoutValidation. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
httpReq.Headers.TryAddWithoutValidation("Authorization", $"Bearer {authToken}");
}
break;
case EndpointAuthType.BasicAuth:
if (action.EndpointAuthUsername is string authUsername && action.EndpointAuthPassword is string authPassword)
{
var basicAuth = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{authUsername}:{authPassword}"));
httpReq.Headers.Authorization = new AuthenticationHeaderValue("Basic", basicAuth);
try { httpReq.Headers.Authorization = new AuthenticationHeaderValue("Basic", basicAuth); }
catch (FormatException ex)
{
logger?.LogWarning(ex, "Basic auth could not be set with strict validation, falling back to TryAddWithoutValidation. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
httpReq.Headers.TryAddWithoutValidation("Authorization", $"Basic {basicAuth}");
}
}
break;
@@ -142,26 +207,30 @@ public class InvokeRecActionViewCommandHandler(
var resBody = await response.Content.ReadAsStringAsync(cancel);
var resHeaders = response.Headers.ToDictionary();
var statusCode = (short)response.StatusCode;
await sender.Send(new InsertResultCommand()
{
StatusId = statusCode,
Status = response.StatusCode.ToRecStatus(),
ActionId = action.Id,
Header = JsonSerializer.Serialize(resHeaders, options: new() { WriteIndented = false }),
Body = resBody
Body = resBody,
Info = (short)response.StatusCode,
Type = ResultType.Main,
References = request.References
}, cancel);
}
catch(Exception ex)
{
await sender.Send(new InsertResultCommand()
{
Status = RecStatus.Error,
ActionId = action.Id,
Error = ex.ToString()
Error = ex.ToString(),
Type = ResultType.Main,
References = request.References
}, cancel);
if (action.ErrorAction == ErrorAction.Stop)
throw;
throw new RecActionException(action.Id, action.ProfileId, ex);
}
finally
{

View File

@@ -1,6 +1,7 @@
using MediatR;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Common.Procedures;
namespace ReC.Application.RecActions.Commands;
@@ -17,7 +18,7 @@ public class UpdateActionProcedureHandler(ISender sender) : IRequestHandler<Upda
{
return await sender.Send(new UpdateObjectProcedure
{
Entity = "ACTION",
Entity = EntityType.Action,
Id = request.Id,
Action = request.Data
}, cancel);

View File

@@ -1,5 +1,6 @@
using MediatR;
using ReC.Application.Common.Procedures.DeleteProcedure;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Results.Commands;
@@ -27,7 +28,7 @@ public class DeleteResultProcedureHandler(ISender sender) : IRequestHandler<Dele
{
return await sender.Send(new DeleteObjectProcedure
{
Entity = "RESULT",
Entity = EntityType.Result,
Start = request.Start,
End = request.End,
Force = request.Force

View File

@@ -1,16 +1,22 @@
using MediatR;
using MediatR;
using ReC.Application.Common.Procedures.InsertProcedure;
using ReC.Application.RecActions.Commands;
using ReC.Domain.Constants;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Results.Commands;
public record InsertResultCommand : IInsertProcedure
{
public long? ActionId { get; set; }
public short? StatusId { get; set; }
public required RecStatus Status { get; set; }
public string? Header { get; set; }
public string? Body { get; set; }
public string? Info { get; set; }
public short Info { get; set; }
public string? InfoDetail { get; set; }
public string? Error { get; set; }
public required ResultType Type { get; set; }
public required InvokeReferences References { get; set; }
}
public class InsertResultProcedureHandler(ISender sender) : IRequestHandler<InsertResultCommand, long>
@@ -19,7 +25,7 @@ public class InsertResultProcedureHandler(ISender sender) : IRequestHandler<Inse
{
return await sender.Send(new InsertObjectProcedure
{
Entity = "RESULT",
Entity = EntityType.Result,
Result = request
}, cancel);
}

View File

@@ -1,6 +1,7 @@
using MediatR;
using ReC.Application.Common.Procedures.UpdateProcedure;
using ReC.Application.Common.Procedures.UpdateProcedure.Dto;
using ReC.Application.Common.Procedures;
namespace ReC.Application.Results.Commands;
@@ -17,7 +18,7 @@ public class UpdateResultProcedureHandler(ISender sender) : IRequestHandler<Upda
{
return await sender.Send(new UpdateObjectProcedure
{
Entity = "RESULT",
Entity = EntityType.Result,
Id = request.Id,
Result = request.Data
}, cancel);

View File

@@ -0,0 +1,35 @@
using DigitalData.Core.Abstraction.Application.Repository;
using MediatR;
using Microsoft.EntityFrameworkCore;
using ReC.Domain.Views;
namespace ReC.Application.Results.Queries;
public record AnyResultViewQuery(
long? Id = null,
long? ActionId = null,
long? ProfileId = null,
string? BatchId = null
) : IRequest<bool>;
public class AnyResultViewQueryHandler(IRepository<ResultView> repo) : IRequestHandler<AnyResultViewQuery, bool>
{
public Task<bool> Handle(AnyResultViewQuery request, CancellationToken cancel)
{
var q = repo.Query;
if(request.Id is long id)
q = q.Where(rv => rv.Id == id);
if(request.ActionId is long actionId)
q = q.Where(rv => rv.ActionId == actionId);
if(request.ProfileId is long profileId)
q = q.Where(rv => rv.ProfileId == profileId);
if(request.BatchId is string batchId)
q = q.Where(rv => rv.BatchId == batchId);
return q.AnyAsync(cancel);
}
}

View File

@@ -17,11 +17,13 @@ public record ReadResultViewQuery : IRequest<IEnumerable<ResultViewDto>>
public long? ProfileId { get; init; } = null;
public string? BatchId { get; init; } = null;
public bool IncludeAction { get; init; } = true;
public bool IncludeProfile { get; init; } = false;
public bool Last { get; init; } = false;
public bool LastBatch { get; init; } = false;
}
public class ReadResultViewQueryHandler(IRepository<ResultView> repo, IMapper mapper) : IRequestHandler<ReadResultViewQuery, IEnumerable<ResultViewDto>>
@@ -39,13 +41,18 @@ public class ReadResultViewQueryHandler(IRepository<ResultView> repo, IMapper ma
if(request.ProfileId is long profileId)
q = q.Where(rv => rv.ProfileId == profileId);
if(request.IncludeAction)
if(request.BatchId is string batchId)
q = q.Where(rv => rv.BatchId == batchId);
if (request.IncludeAction)
q = q.Include(rv => rv.Action);
if(request.IncludeProfile)
q = q.Include(rv => rv.Profile);
var entities = request.Last ? [await q.OrderBy(rv => rv.AddedWhen).LastOrDefaultAsync(cancel)] : await q.ToListAsync(cancel);
var entities = request.LastBatch
? await GetLastBatchEntitiesAsync(q, cancel)
: await q.ToListAsync(cancel);
if (entities.Count == 0)
throw new NotFoundException($"No result views found for the given criteria. Criteria: {
@@ -58,4 +65,20 @@ public class ReadResultViewQueryHandler(IRepository<ResultView> repo, IMapper ma
return mapper.Map<IEnumerable<ResultViewDto>>(entities);
}
private static async Task<List<ResultView>> GetLastBatchEntitiesAsync(IQueryable<ResultView> q, CancellationToken cancel)
{
var lastBatchId = await q
.Where(rv => rv.BatchId != null)
.OrderByDescending(rv => rv.AddedWhen)
.Select(rv => rv.BatchId)
.FirstOrDefaultAsync(cancel);
if (lastBatchId is null)
return [];
return await q
.Where(rv => rv.BatchId == lastBatchId)
.ToListAsync(cancel);
}
}

View File

@@ -2,6 +2,7 @@ using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client.Api
{
@@ -20,15 +21,37 @@ namespace ReC.Client.Api
/// </summary>
protected readonly string ResourcePath;
/// <summary>
/// An optional logger used to record API call outcomes. May be <see langword="null"/>.
/// </summary>
#if NETFRAMEWORK
protected readonly ILogger Logger;
#else
protected readonly ILogger? Logger;
#endif
/// <summary>
/// The options controlling client behavior. Never <see langword="null"/>.
/// </summary>
protected readonly ReCClientOptions Options;
/// <summary>
/// Initializes a new instance of the <see cref="BaseCrudApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
/// <param name="resourcePath">The base resource path for the API endpoint.</param>
protected BaseCrudApi(HttpClient http, string resourcePath)
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger logger = null, ReCClientOptions options = null)
#else
protected BaseCrudApi(HttpClient http, string resourcePath, ILogger? logger = null, ReCClientOptions? options = null)
#endif
{
Http = http ?? throw new ArgumentNullException(nameof(http));
ResourcePath = resourcePath ?? throw new ArgumentNullException(nameof(resourcePath));
Logger = logger;
Options = options ?? new ReCClientOptions();
}
/// <summary>
@@ -37,9 +60,15 @@ namespace ReC.Client.Api
/// <typeparam name="T">The payload type.</typeparam>
/// <param name="payload">The payload to send.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> CreateAsync<T>(T payload, CancellationToken cancel = default)
=> Http.PostAsync(ResourcePath, ReCClientHelpers.ToJsonContent(payload), cancel);
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
public async Task CreateAsync<T>(T payload, CancellationToken cancel = default)
{
using (var content = ReCClientHelpers.ToJsonContent(payload))
using (var resp = await Http.PostAsync(ResourcePath, content, cancel))
{
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
}
}
/// <summary>
/// Updates a resource by identifier.
@@ -48,24 +77,31 @@ namespace ReC.Client.Api
/// <param name="id">The resource identifier.</param>
/// <param name="payload">The payload to send.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> UpdateAsync<T>(long id, T payload, CancellationToken cancel = default)
=> Http.PutAsync($"{ResourcePath}/{id}", ReCClientHelpers.ToJsonContent(payload), cancel);
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
public async Task UpdateAsync<T>(long id, T payload, CancellationToken cancel = default)
{
using (var content = ReCClientHelpers.ToJsonContent(payload))
using (var resp = await Http.PutAsync($"{ResourcePath}/{id}", content, cancel))
{
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
}
}
/// <summary>
/// Deletes resources with identifiers supplied in the payload.
/// Deletes resources with identifiers supplied in the payload. The payload is serialized into
/// the query string because the API binds delete payloads from the URL query.
/// </summary>
/// <typeparam name="T">The payload type containing identifiers.</typeparam>
/// <param name="payload">The payload to send.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> DeleteAsync<T>(T payload, CancellationToken cancel = default)
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
public async Task DeleteAsync<T>(T payload, CancellationToken cancel = default)
{
var request = new HttpRequestMessage(HttpMethod.Delete, ResourcePath)
var query = ReCClientHelpers.BuildQueryFromObject(payload);
using (var resp = await Http.DeleteAsync($"{ResourcePath}{query}", cancel))
{
Content = ReCClientHelpers.ToJsonContent(payload)
};
return Http.SendAsync(request, cancel);
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
}
}
}
}

View File

@@ -1,11 +1,14 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client.Api
{
/// <summary>
/// Provides access to common object endpoints.
/// Provides access to common object endpoints. The Common API binds update and delete
/// payloads from the body / query string (no id route segment), so the inherited CRUD
/// helpers from <see cref="BaseCrudApi"/> are hidden with overloads that match the API.
/// </summary>
public class CommonApi : BaseCrudApi
{
@@ -13,8 +16,32 @@ namespace ReC.Client.Api
/// Initializes a new instance of the <see cref="CommonApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public CommonApi(HttpClient http) : base(http, "api/Common")
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public CommonApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Common", logger, options)
#else
public CommonApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Common", logger, options)
#endif
{
}
/// <summary>
/// Updates an object via the Common update procedure. The identifier is expected to be
/// part of <paramref name="payload"/> rather than the URL.
/// </summary>
/// <typeparam name="T">The payload type.</typeparam>
/// <param name="payload">The payload to send.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
public async Task UpdateAsync<T>(T payload, CancellationToken cancel = default)
{
using (var content = ReCClientHelpers.ToJsonContent(payload))
using (var resp = await Http.PutAsync(ResourcePath, content, cancel))
{
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
}
}
}
}

View File

@@ -1,6 +1,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client.Api
{
@@ -13,7 +14,13 @@ namespace ReC.Client.Api
/// Initializes a new instance of the <see cref="EndpointAuthApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public EndpointAuthApi(HttpClient http) : base(http, "api/EndpointAuth")
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public EndpointAuthApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/EndpointAuth", logger, options)
#else
public EndpointAuthApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/EndpointAuth", logger, options)
#endif
{
}
}

View File

@@ -1,6 +1,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client.Api
{
@@ -13,7 +14,13 @@ namespace ReC.Client.Api
/// Initializes a new instance of the <see cref="EndpointParamsApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public EndpointParamsApi(HttpClient http) : base(http, "api/EndpointParams")
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public EndpointParamsApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/EndpointParams", logger, options)
#else
public EndpointParamsApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/EndpointParams", logger, options)
#endif
{
}
}

View File

@@ -1,6 +1,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client.Api
{
@@ -13,7 +14,13 @@ namespace ReC.Client.Api
/// Initializes a new instance of the <see cref="EndpointsApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public EndpointsApi(HttpClient http) : base(http, "api/Endpoints")
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public EndpointsApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Endpoints", logger, options)
#else
public EndpointsApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Endpoints", logger, options)
#endif
{
}
}

View File

@@ -0,0 +1,50 @@
namespace ReC.Client.Api
{
/// <summary>
/// Optional reference values that are passed through to all result records when invoking a profile.
/// </summary>
public class InvokeReferences
{
/// <summary>Batch identifier.</summary>
public string
#if NET
?
#endif
BatchId { get; set; }
/// <summary>Reference value 1.</summary>
public string
#if NET
?
#endif
Reference1 { get; set; }
/// <summary>Reference value 2.</summary>
public string
#if NET
?
#endif
Reference2 { get; set; }
/// <summary>Reference value 3.</summary>
public string
#if NET
?
#endif
Reference3 { get; set; }
/// <summary>Reference value 4.</summary>
public string
#if NET
?
#endif
Reference4 { get; set; }
/// <summary>Reference value 5.</summary>
public string
#if NET
?
#endif
Reference5 { get; set; }
}
}

View File

@@ -1,6 +1,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client.Api
{
@@ -13,21 +14,45 @@ namespace ReC.Client.Api
/// Initializes a new instance of the <see cref="ProfileApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public ProfileApi(HttpClient http) : base(http, "api/Profile")
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public ProfileApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Profile", logger, options)
#else
public ProfileApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Profile", logger, options)
#endif
{
}
/// <summary>
/// Retrieves a profile by identifier.
/// Retrieves profiles and deserializes the JSON response into <typeparamref name="T"/>.
/// </summary>
/// <param name="id">The profile identifier.</param>
/// <param name="includeActions">Whether to include related actions.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> GetAsync(long id, bool includeActions = false, CancellationToken cancel = default)
#if NETFRAMEWORK
public async Task<T> GetAsync<T>(long? id = null, bool includeActions = true, CancellationToken cancel = default)
#else
public async Task<T?> GetAsync<T>(long? id = null, bool includeActions = true, CancellationToken cancel = default)
#endif
{
var query = ReCClientHelpers.BuildQuery(("Id", id), ("IncludeActions", includeActions));
return Http.GetAsync($"{ResourcePath}{query}", cancel);
using (var resp = await Http.GetAsync($"{ResourcePath}{query}", cancel).ConfigureAwait(false))
{
var body = await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
return ReCClientHelpers.Deserialize<T>(body);
}
}
/// <summary>
/// Retrieves profiles and returns a dynamically deserialized payload
/// (typically a <see cref="System.Text.Json.JsonElement"/>). This is the non-generic
/// overload of <see cref="GetAsync{T}"/>.
/// </summary>
#if NETFRAMEWORK
public Task<dynamic> GetAsync(long? id = null, bool includeActions = true, CancellationToken cancel = default)
#else
public Task<dynamic?> GetAsync(long? id = null, bool includeActions = true, CancellationToken cancel = default)
#endif
{
return GetAsync<object>(id, includeActions, cancel);
}
}
}

View File

@@ -1,6 +1,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client.Api
{
@@ -13,33 +14,78 @@ namespace ReC.Client.Api
/// Initializes a new instance of the <see cref="RecActionApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public RecActionApi(HttpClient http) : base(http, "api/RecAction")
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public RecActionApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/RecAction", logger, options)
#else
public RecActionApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/RecAction", logger, options)
#endif
{
}
/// <summary>
/// Invokes a ReC action for the specified profile.
/// Invokes a batch of RecActions for the specified profile.
/// </summary>
/// <param name="profileId">The profile identifier.</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>
/// <returns><see langword="true"/> if the request succeeds; otherwise, <see langword="false"/>.</returns>
public async Task<bool> InvokeAsync(int profileId, CancellationToken cancellationToken = default)
/// <exception cref="ReCApiException">Thrown when the API responds with a non-success status code.</exception>
#if NETFRAMEWORK
public async Task InvokeAsync(long profileId, InvokeReferences references = null, CancellationToken cancellationToken = default)
#else
public async Task InvokeAsync(long profileId, InvokeReferences? references = null, CancellationToken cancellationToken = default)
#endif
{
var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content: null, cancellationToken);
return resp.IsSuccessStatusCode;
var content = references != null ? ReCClientHelpers.ToJsonContent(references) : null;
using (content)
using (var resp = await Http.PostAsync($"{ResourcePath}/invoke/{profileId}", content, cancellationToken))
{
await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancellationToken).ConfigureAwait(false);
}
}
/// <summary>
/// Retrieves Rec actions.
/// Invokes a batch of RecActions for the specified profile.
/// </summary>
/// <param name="profileId">Optional profile filter.</param>
/// <param name="invoked">Optional invoked filter.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
/// <param name="profileId">The profile identifier.</param>
/// <param name="batchId">Batch identifier.</param>
/// <param name="cancellationToken">A token to cancel the operation.</param>
/// <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)
{
return InvokeAsync(profileId, new InvokeReferences() { BatchId = batchId }, cancellationToken);
}
/// <summary>
/// Retrieves Rec actions and deserializes the JSON response into <typeparamref name="T"/>.
/// </summary>
#if NETFRAMEWORK
public async Task<T> GetAsync<T>(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
#else
public async Task<T?> GetAsync<T>(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
#endif
{
var query = ReCClientHelpers.BuildQuery(("ProfileId", profileId), ("Invoked", invoked));
return Http.GetAsync($"{ResourcePath}{query}", cancel);
using (var resp = await Http.GetAsync($"{ResourcePath}{query}", cancel).ConfigureAwait(false))
{
var body = await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
return ReCClientHelpers.Deserialize<T>(body);
}
}
/// <summary>
/// Retrieves Rec actions and returns a dynamically deserialized payload
/// (typically a <see cref="System.Text.Json.JsonElement"/>). This is the non-generic
/// overload of <see cref="GetAsync{T}"/>.
/// </summary>
#if NETFRAMEWORK
public Task<dynamic> GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
#else
public Task<dynamic?> GetAsync(long? profileId = null, bool? invoked = null, CancellationToken cancel = default)
#endif
{
return GetAsync<object>(profileId, invoked, cancel);
}
}
}

View File

@@ -1,6 +1,7 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client.Api
{
@@ -13,22 +14,53 @@ namespace ReC.Client.Api
/// Initializes a new instance of the <see cref="ResultApi"/> class.
/// </summary>
/// <param name="http">The HTTP client used for requests.</param>
public ResultApi(HttpClient http) : base(http, "api/Result")
/// <param name="logger">An optional logger used to record API call outcomes.</param>
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
#if NETFRAMEWORK
public ResultApi(HttpClient http, ILogger logger = null, ReCClientOptions options = null) : base(http, "api/Result", logger, options)
#else
public ResultApi(HttpClient http, ILogger? logger = null, ReCClientOptions? options = null) : base(http, "api/Result", logger, options)
#endif
{
}
/// <summary>
/// Retrieves results with optional filters.
/// Retrieves results with optional filters and deserializes the JSON response into <typeparamref name="T"/>.
/// </summary>
/// <param name="id">Optional result identifier.</param>
/// <param name="actionId">Optional action identifier.</param>
/// <param name="profileId">Optional profile identifier.</param>
/// <param name="cancel">A token to cancel the operation.</param>
/// <returns>The HTTP response message.</returns>
public Task<HttpResponseMessage> GetAsync(long? id = null, long? actionId = null, long? profileId = null, CancellationToken cancel = default)
#if NETFRAMEWORK
public async Task<T> GetAsync<T>(long? id = null, long? actionId = null, long? profileId = null, string batchId = null, bool includeAction = true, bool includeProfile = false, bool lastBatch = false, CancellationToken cancel = default)
#else
public async Task<T?> GetAsync<T>(long? id = null, long? actionId = null, long? profileId = null, string? batchId = null, bool includeAction = true, bool includeProfile = false, bool lastBatch = false, CancellationToken cancel = default)
#endif
{
var query = ReCClientHelpers.BuildQuery(("Id", id), ("ActionId", actionId), ("ProfileId", profileId));
return Http.GetAsync($"{ResourcePath}{query}", cancel);
var query = ReCClientHelpers.BuildQuery(
("Id", id),
("ActionId", actionId),
("ProfileId", profileId),
("BatchId", batchId),
("IncludeAction", includeAction),
("IncludeProfile", includeProfile),
("LastBatch", lastBatch));
using (var resp = await Http.GetAsync($"{ResourcePath}{query}", cancel).ConfigureAwait(false))
{
var body = await ReCClientHelpers.HandleResponseAsync(resp, Logger, Options.LogSuccessfulRequests, cancel).ConfigureAwait(false);
return ReCClientHelpers.Deserialize<T>(body);
}
}
/// <summary>
/// Retrieves results with optional filters and returns a dynamically deserialized payload
/// (typically a <see cref="System.Text.Json.JsonElement"/>). This is the non-generic
/// overload of <see cref="GetAsync{T}"/>.
/// </summary>
#if NETFRAMEWORK
public Task<dynamic> GetAsync(long? id = null, long? actionId = null, long? profileId = null, string batchId = null, bool includeAction = true, bool includeProfile = false, bool lastBatch = false, CancellationToken cancel = default)
#else
public Task<dynamic?> GetAsync(long? id = null, long? actionId = null, long? profileId = null, string? batchId = null, bool includeAction = true, bool includeProfile = false, bool lastBatch = false, CancellationToken cancel = default)
#endif
{
return GetAsync<object>(id, actionId, profileId, batchId, includeAction, includeProfile, lastBatch, cancel);
}
}
}

View File

@@ -1,6 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
#if NETFRAMEWORK
using System;
#if NETFRAMEWORK
using System.Net.Http;
#endif
@@ -16,9 +16,15 @@ namespace ReC.Client
/// </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>
/// <param name="configureOptions">An optional action to configure <see cref="ReCClientOptions"/>. When omitted, defaults are used.</param>
/// <returns>An <see cref="IHttpClientBuilder"/> that can be used to configure the client.</returns>
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, string apiUri)
#if NETFRAMEWORK
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, string apiUri, Action<ReCClientOptions> configureOptions = null)
#else
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, string apiUri, Action<ReCClientOptions>? configureOptions = null)
#endif
{
AddRecClientOptions(services, configureOptions);
services.AddScoped<ReCClient>();
return services.AddHttpClient(ReCClient.ClientName, client =>
{
@@ -31,11 +37,29 @@ namespace ReC.Client
/// </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>
/// <param name="configureOptions">An optional action to configure <see cref="ReCClientOptions"/>. When omitted, defaults are used.</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)
#if NETFRAMEWORK
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, Action<HttpClient> configureClient, Action<ReCClientOptions> configureOptions = null)
#else
public static IHttpClientBuilder AddRecClient(this IServiceCollection services, Action<HttpClient> configureClient, Action<ReCClientOptions>? configureOptions = null)
#endif
{
AddRecClientOptions(services, configureOptions);
services.AddScoped<ReCClient>();
return services.AddHttpClient(ReCClient.ClientName, configureClient);
}
#if NETFRAMEWORK
private static void AddRecClientOptions(IServiceCollection services, Action<ReCClientOptions> configureOptions)
#else
private static void AddRecClientOptions(IServiceCollection services, Action<ReCClientOptions>? configureOptions)
#endif
{
// Ensure default options are always registered even when the caller does not configure anything.
var builder = services.AddOptions<ReCClientOptions>();
if (configureOptions != null)
builder.Configure(configureOptions);
}
}
}

View File

@@ -10,10 +10,10 @@
<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>
<PackageTags>digital data rec api client</PackageTags>
<Version>2.0.0-beta</Version>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.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>

View File

@@ -0,0 +1,88 @@
using System;
using System.Net;
using System.Net.Http;
namespace ReC.Client
{
/// <summary>
/// Represents an error returned by the ReC API.
/// </summary>
#if !NETFRAMEWORK
[Serializable]
#endif
public class ReCApiException : Exception
{
/// <summary>
/// The HTTP status code returned by the API.
/// </summary>
public HttpStatusCode StatusCode { get; }
/// <summary>
/// The HTTP reason phrase returned by the API, if any.
/// </summary>
#if NETFRAMEWORK
public string ReasonPhrase { get; }
#else
public string? ReasonPhrase { get; }
#endif
/// <summary>
/// The raw response body returned by the API, if any.
/// </summary>
#if NETFRAMEWORK
public string ResponseBody { get; }
#else
public string? ResponseBody { get; }
#endif
/// <summary>
/// The HTTP method used for the failed request.
/// </summary>
#if NETFRAMEWORK
public string Method { get; }
#else
public string? Method { get; }
#endif
/// <summary>
/// The request URI that was called.
/// </summary>
#if NETFRAMEWORK
public Uri RequestUri { get; }
#else
public Uri? RequestUri { get; }
#endif
/// <summary>
/// Initializes a new instance of the <see cref="ReCApiException"/> class.
/// </summary>
/// <param name="message">A summary message describing the error.</param>
/// <param name="statusCode">The HTTP status code returned by the API.</param>
/// <param name="reasonPhrase">The HTTP reason phrase returned by the API.</param>
/// <param name="responseBody">The raw response body returned by the API.</param>
/// <param name="method">The HTTP method used for the request.</param>
/// <param name="requestUri">The request URI that was called.</param>
public ReCApiException(
string message,
HttpStatusCode statusCode,
#if NETFRAMEWORK
string reasonPhrase,
string responseBody,
string method,
Uri requestUri
#else
string? reasonPhrase,
string? responseBody,
string? method,
Uri? requestUri
#endif
) : base(message)
{
StatusCode = statusCode;
ReasonPhrase = reasonPhrase;
ResponseBody = responseBody;
Method = method;
RequestUri = requestUri;
}
}
}

View File

@@ -0,0 +1,142 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Net.Http;
namespace ReC.Client
{
/// <summary>
/// Static convenience entry-point for building and resolving a <see cref="ReCClient"/> without an
/// externally provided <see cref="IServiceProvider"/>. Intended for legacy scenarios (e.g. .NET Framework
/// codebases without an established DI container). For new code, prefer
/// <see cref="DependencyInjection.AddRecClient(IServiceCollection, string, Action{ReCClientOptions})"/>.
/// </summary>
public partial class ReCClient
{
#if NET8_0_OR_GREATER
private static Action<IServiceCollection>? _staticConfigure = null;
#else
private static Action<IServiceCollection> _staticConfigure = null;
#endif
private static readonly Lazy<IServiceProvider> LazyProvider = new Lazy<IServiceProvider>(() =>
{
var configure = _staticConfigure
?? throw new InvalidOperationException("Static Provider is not built. Call BuildStaticClient first.");
var services = new ServiceCollection();
configure(services);
return services.BuildServiceProvider();
}, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
/// <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. The underlying
/// <see cref="IServiceProvider"/> is created lazily and thread-safely on first access via <see cref="Create"/>.
/// </remarks>
/// <param name="configure">Callback that populates a <see cref="StaticBuildConfiguration"/> instance.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="configure"/> is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when neither <see cref="StaticBuildConfiguration.BaseAddress"/> nor <see cref="StaticBuildConfiguration.ConfigureClient"/> is set, when both are set, or when the static provider has already been built.</exception>
[Obsolete("Use a local service collection instead of the static provider.")]
public static void BuildStaticClient(Action<StaticBuildConfiguration> configure)
{
if (configure == null)
throw new ArgumentNullException(nameof(configure));
var cfg = new StaticBuildConfiguration();
configure(cfg);
var hasBaseAddress = !string.IsNullOrWhiteSpace(cfg.BaseAddress);
var hasConfigureClient = cfg.ConfigureClient != null;
if (!hasBaseAddress && !hasConfigureClient)
throw new InvalidOperationException(
$"Either {nameof(StaticBuildConfiguration.BaseAddress)} or {nameof(StaticBuildConfiguration.ConfigureClient)} must be set on {nameof(StaticBuildConfiguration)}.");
if (hasBaseAddress && hasConfigureClient)
throw new InvalidOperationException(
$"{nameof(StaticBuildConfiguration.BaseAddress)} and {nameof(StaticBuildConfiguration.ConfigureClient)} are mutually exclusive on {nameof(StaticBuildConfiguration)}.");
Action<IServiceCollection> register = services =>
{
if (hasBaseAddress)
services.AddRecClient(cfg.BaseAddress, cfg.ConfigureOptions);
else
services.AddRecClient(cfg.ConfigureClient, cfg.ConfigureOptions);
if (cfg.Logger != null)
services.AddSingleton(cfg.Logger);
cfg.ConfigureServices?.Invoke(services);
};
if (System.Threading.Interlocked.CompareExchange(ref _staticConfigure, register, null) != null)
throw new InvalidOperationException("Static Provider is already built.");
}
/// <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.
/// The underlying <see cref="IServiceProvider"/> is created lazily and thread-safely on first access via <see cref="Create"/>.
/// </remarks>
/// <param name="apiUri">The base URI of the ReC API.</param>
/// <param name="configureOptions">An optional callback to configure <see cref="ReCClientOptions"/>.</param>
/// <param name="logger">An optional <see cref="ILogger"/> instance to be used by the <see cref="ReCClient"/>. When provided, it is registered as a singleton in the internal service collection.</param>
/// <exception cref="InvalidOperationException">Thrown if the static provider has already been built.</exception>
[Obsolete("Use BuildStaticClient(Action<StaticBuildConfiguration>) instead.")]
#if NETFRAMEWORK
public static void BuildStaticClient(string apiUri, Action<ReCClientOptions> configureOptions = null, ILogger logger = null)
#else
public static void BuildStaticClient(string apiUri, Action<ReCClientOptions>? configureOptions = null, ILogger<ReCClient>? logger = null)
#endif
{
BuildStaticClient(cfg =>
{
cfg.BaseAddress = apiUri;
cfg.ConfigureOptions = configureOptions;
cfg.Logger = logger;
});
}
/// <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.
/// The underlying <see cref="IServiceProvider"/> is created lazily and thread-safely on first access via <see cref="Create"/>.
/// </remarks>
/// <param name="configureClient">An action to configure the <see cref="HttpClient"/>.</param>
/// <param name="configureOptions">An optional callback to configure <see cref="ReCClientOptions"/>.</param>
/// <param name="logger">An optional <see cref="ILogger"/> instance to be used by the <see cref="ReCClient"/>. When provided, it is registered as a singleton in the internal service collection.</param>
/// <exception cref="InvalidOperationException">Thrown if the static provider has already been built.</exception>
[Obsolete("Use BuildStaticClient(Action<StaticBuildConfiguration>) instead.")]
#if NETFRAMEWORK
public static void BuildStaticClient(Action<HttpClient> configureClient, Action<ReCClientOptions> configureOptions = null, ILogger logger = null)
#else
public static void BuildStaticClient(Action<HttpClient> configureClient, Action<ReCClientOptions>? configureOptions = null, ILogger<ReCClient>? logger = null)
#endif
{
BuildStaticClient(cfg =>
{
cfg.ConfigureClient = configureClient;
cfg.ConfigureOptions = configureOptions;
cfg.Logger = logger;
});
}
/// <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(Action{StaticBuildConfiguration})"/> has not been called yet.</exception>
[Obsolete("Use a local service collection instead of the static provider.")]
public static ReCClient Create()
{
return LazyProvider.Value.GetRequiredService<ReCClient>();
}
}
}

View File

@@ -1,4 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Net.Http;
using ReC.Client.Api;
@@ -8,7 +10,7 @@ namespace ReC.Client
/// <summary>
/// A client for interacting with the ReC API.
/// </summary>
public class ReCClient
public partial class ReCClient
{
private readonly HttpClient _http;
@@ -56,77 +58,31 @@ namespace ReC.Client
/// Initializes a new instance of the <see cref="ReCClient"/> class.
/// </summary>
/// <param name="httpClientFactory">The factory to create HttpClients.</param>
public ReCClient(IHttpClientFactory httpClientFactory)
/// <param name="options">An optional set of client options. Defaults are used when omitted.</param>
/// <param name="logger">An optional logger used to record API call outcomes.</param>
#if NETFRAMEWORK
public ReCClient(IHttpClientFactory httpClientFactory, IOptions<ReCClientOptions> options = null, ILogger logger = null)
#else
public ReCClient(IHttpClientFactory httpClientFactory, IOptions<ReCClientOptions>? options = null, ILogger<ReCClient>? logger = null)
#endif
{
_http = httpClientFactory.CreateClient(ClientName);
RecActions = new RecActionApi(_http);
Results = new ResultApi(_http);
Profiles = new ProfileApi(_http);
EndpointAuth = new EndpointAuthApi(_http);
EndpointParams = new EndpointParamsApi(_http);
Endpoints = new EndpointsApi(_http);
Common = new CommonApi(_http);
var opts = options?.Value ?? new ReCClientOptions();
if (opts.LogSuccessfulRequests && logger == null)
throw new InvalidOperationException(
$"{nameof(ReCClientOptions.LogSuccessfulRequests)} is enabled, but no {nameof(ILogger)} was injected into {nameof(ReCClient)}. " +
$"Register a logging provider (e.g. services.AddLogging()) so that an {nameof(ILogger)} can be resolved, " +
$"or set {nameof(ReCClientOptions.LogSuccessfulRequests)} to false.");
RecActions = new RecActionApi(_http, logger, opts);
Results = new ResultApi(_http, logger, opts);
Profiles = new ProfileApi(_http, logger, opts);
EndpointAuth = new EndpointAuthApi(_http, logger, opts);
EndpointParams = new EndpointParamsApi(_http, logger, opts);
Endpoints = new EndpointsApi(_http, logger, opts);
Common = new CommonApi(_http, logger, opts);
}
#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
}
/// <summary>

View File

@@ -1,11 +1,14 @@
using System;
using System.Collections;
using System.Globalization;
using System.Linq;
using System.Net.Http.Json;
#if NETFRAMEWORK
using System.Net.Http;
#endif
using System.Net.Http.Json;
using System.Reflection;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace ReC.Client
{
@@ -45,5 +48,110 @@ namespace ReC.Client
/// <param name="payload">The payload to serialize.</param>
/// <returns>A <see cref="JsonContent"/> instance ready for HTTP requests.</returns>
public static JsonContent ToJsonContent<T>(T payload) => JsonContent.Create(payload);
/// <summary>
/// Builds a query string from the public readable properties of <paramref name="payload"/>,
/// skipping properties whose values are <see langword="null"/>.
/// </summary>
/// <typeparam name="T">The payload type.</typeparam>
/// <param name="payload">The payload to serialize into a query string.</param>
/// <returns>A query string beginning with '?', or an empty string if no values are provided.</returns>
public static string BuildQueryFromObject<T>(T payload)
{
if (payload == null)
return string.Empty;
var props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.CanRead && p.GetIndexParameters().Length == 0);
var parts = props
.Select(p => new { p.Name, Value = p.GetValue(payload) })
.Where(p => p.Value != null)
.Select(p => $"{Uri.EscapeDataString(p.Name)}={Uri.EscapeDataString(Convert.ToString(p.Value, CultureInfo.InvariantCulture) ?? string.Empty)}");
var query = string.Join("&", parts);
return string.IsNullOrWhiteSpace(query) ? string.Empty : $"?{query}";
}
/// <summary>
/// JSON serializer options used when deserializing API responses.
/// </summary>
public static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true,
};
/// <summary>
/// Reads the response body and logs the outcome. Throws a <see cref="ReCApiException"/> when
/// the response indicates a non-success status code.
/// </summary>
#if NETFRAMEWORK
public static async Task<string> HandleResponseAsync(HttpResponseMessage response, ILogger logger = null, bool logSuccess = true, CancellationToken cancel = default)
#else
public static async Task<string?> HandleResponseAsync(HttpResponseMessage response, ILogger? logger = null, bool logSuccess = true, CancellationToken cancel = default)
#endif
{
var request = response.RequestMessage;
var method = request?.Method?.Method;
var uri = request?.RequestUri;
var statusCode = (int)response.StatusCode;
#if NETFRAMEWORK
string body = null;
#else
string? body = null;
#endif
if (response.Content != null)
{
try
{
#if NETFRAMEWORK
body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
#else
body = await response.Content.ReadAsStringAsync(cancel).ConfigureAwait(false);
#endif
}
catch
{
}
}
if (response.IsSuccessStatusCode)
{
if (logSuccess)
{
logger?.LogInformation(
"ReC API request succeeded. {Method} {Uri} -> {StatusCode} ({ReasonPhrase})",
method,
uri,
statusCode,
response.ReasonPhrase);
}
return body;
}
var message = $"ReC API request failed with status {statusCode} ({response.ReasonPhrase}). "
+ $"{method} {uri}"
+ (string.IsNullOrWhiteSpace(body) ? string.Empty : $": {body}");
throw new ReCApiException(message, response.StatusCode, response.ReasonPhrase, body, method, uri);
}
/// <summary>
/// Deserializes a JSON body string into <typeparamref name="T"/>.
/// </summary>
#if NETFRAMEWORK
public static T Deserialize<T>(string body)
#else
public static T? Deserialize<T>(string? body)
#endif
{
if (string.IsNullOrWhiteSpace(body))
return default;
return JsonSerializer.Deserialize<T>(body, JsonOptions);
}
}
}

View File

@@ -0,0 +1,16 @@
namespace ReC.Client
{
/// <summary>
/// Options that control the behavior of the <see cref="ReCClient"/>.
/// </summary>
public class ReCClientOptions
{
/// <summary>
/// Gets or sets a value indicating whether successful API requests should be
/// logged through the injected <see cref="Microsoft.Extensions.Logging.ILogger"/>.
/// Failed requests always throw <see cref="ReCApiException"/> regardless of this setting.
/// Defaults to <see langword="true"/>.
/// </summary>
public bool LogSuccessfulRequests { get; set; } = true;
}
}

View File

@@ -0,0 +1,63 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Net.Http;
namespace ReC.Client
{
/// <summary>
/// Configuration object for <see cref="ReCClient.BuildStaticClient(Action{StaticBuildConfiguration})"/>.
/// Groups all optional settings for the static <see cref="ReCClient"/> bootstrap path.
/// </summary>
/// <remarks>
/// Either <see cref="BaseAddress"/> or <see cref="ConfigureClient"/> must be set; setting both at the same time is not allowed.
/// </remarks>
public class StaticBuildConfiguration
{
/// <summary>
/// Base URI of the ReC API. Mutually exclusive with <see cref="ConfigureClient"/>.
/// </summary>
#if NETFRAMEWORK
public string BaseAddress { get; set; }
#else
public string? BaseAddress { get; set; }
#endif
/// <summary>
/// Callback that configures the underlying <see cref="HttpClient"/>. Mutually exclusive with <see cref="BaseAddress"/>.
/// </summary>
#if NETFRAMEWORK
public Action<HttpClient> ConfigureClient { get; set; }
#else
public Action<HttpClient>? ConfigureClient { get; set; }
#endif
/// <summary>
/// Optional callback to configure <see cref="ReCClientOptions"/>.
/// </summary>
#if NETFRAMEWORK
public Action<ReCClientOptions> ConfigureOptions { get; set; }
#else
public Action<ReCClientOptions>? ConfigureOptions { get; set; }
#endif
/// <summary>
/// Optional logger instance to be registered as a singleton in the internal service collection.
/// </summary>
#if NETFRAMEWORK
public ILogger Logger { get; set; }
#else
public ILogger<ReCClient>? Logger { get; set; }
#endif
/// <summary>
/// Optional callback for additional service registrations on the internal <see cref="IServiceCollection"/>
/// (e.g. <c>services.AddLogging(...)</c> or custom dependencies).
/// </summary>
#if NETFRAMEWORK
public Action<IServiceCollection> ConfigureServices { get; set; }
#else
public Action<IServiceCollection>? ConfigureServices { get; set; }
#endif
}
}

View File

@@ -7,12 +7,14 @@ namespace ReC.Client
/// <summary>
/// Provides synchronous wrappers for Task-based operations.
/// </summary>
[System.Obsolete("Synchronous blocking helpers (Task.Sync) are no longer recommended. These methods can cause deadlocks or unexpected behavior. Rewrite calling code to use async/await (e.g. async Task tests). This helper class will be removed in a future release.", false)]
public static class TaskSyncExtensions
{
/// <summary>
/// Blocks until the task completes and propagates any exception.
/// </summary>
/// <param name="task">The task to wait for.</param>
[System.Obsolete("Use async/await instead of synchronous blocking. This method can cause deadlocks.", false)]
public static void Sync(this Task task) => task.ConfigureAwait(false).GetAwaiter().GetResult();
/// <summary>
@@ -21,6 +23,7 @@ namespace ReC.Client
/// <typeparam name="TResult">The type of the task result.</typeparam>
/// <param name="task">The task to wait for.</param>
/// <returns>The result of the completed task.</returns>
[System.Obsolete("Use async/await instead of synchronous blocking. This method can cause deadlocks.", false)]
public static TResult Sync<TResult>(this Task<TResult> task) => task.ConfigureAwait(false).GetAwaiter().GetResult();
}
}

View File

@@ -0,0 +1,23 @@
namespace ReC.Domain.Constants;
/// <summary>
/// Represents the general outcome of an operation, independent of any specific technology or protocol.
/// <para>
/// Technology-specific details (e.g., HTTP status codes) are stored separately
/// in the <c>RESULT_INFO</c> and <c>RESULT_INFO_DETAIL</c> fields.
/// </para>
/// </summary>
/// <seealso cref="RecStatusExtensions"/>
public enum RecStatus : byte
{
/// <summary>
/// Indicates that the operation completed successfully (value 0).
/// </summary>
OK = 0,
/// <summary>
/// Indicates that the operation failed (value 1).
/// When set, the <c>RESULT_ERROR</c> field should contain the error details.
/// </summary>
Error = 1
}

View File

@@ -0,0 +1,16 @@
using System.Net;
namespace ReC.Domain.Constants;
public static class RecStatusExtensions
{
/// <summary>
/// Converts an <see cref="HttpStatusCode"/> to a general <see cref="RecStatus"/>
/// based on whether the HTTP status represents a success (2xx) or an error.
/// </summary>
public static RecStatus ToRecStatus(this HttpStatusCode code)
{
int value = (int)code;
return value >= 200 && value <= 299 ? RecStatus.OK : RecStatus.Error;
}
}

View File

@@ -0,0 +1,8 @@
namespace ReC.Domain.Constants;
public enum ResultType : byte
{
Pre = 1,
Main,
Post
}

View File

@@ -1,6 +1,9 @@
namespace ReC.Domain.QueryOutput;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.QueryOutput;
public class BodyQueryResult
{
[Column("REQUEST_BODY")]
public string? RawBody { get; init; }
}

View File

@@ -1,6 +1,9 @@
namespace ReC.Domain.QueryOutput;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.QueryOutput;
public class HeaderQueryResult
{
[Column("REQUEST_HEADER")]
public string? RawHeader { get; init; }
}

View File

@@ -4,5 +4,6 @@ namespace ReC.Domain.QueryOutput;
public class InsertObjectResult
{
[Column("oGUID")]
public required long NewObjectId { get; set; }
}

View File

@@ -1,4 +1,5 @@
using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Views;
@@ -8,39 +9,58 @@ public record ProfileView
{
public virtual IEnumerable<RecActionView>? Actions { get; init; }
[Key]
[Column("PROFILE_GUID")]
public long Id { get; init; }
[Column("ACTIVE")]
public bool Active { get; init; }
[Column("TYPE_ID")]
public ProfileType TypeId { get; init; }
[Column("TYPE")]
public string? Type { get; init; }
[Column("MANDANTOR")]
public string? Mandantor { get; init; }
[Column("PROFILE_NAME")]
public string? ProfileName { get; init; }
[Column("DESCRIPTION")]
public string? Description { get; init; }
[Column("LOG_LEVEL_ID")]
public byte LogLevelId { get; init; }
[Column("LOG_LEVEL")]
public string? LogLevel { get; init; }
[Column("LANGUAGE_ID")]
public short LanguageId { get; init; }
[Column("LANGUAGE")]
public string? Language { get; init; }
[Column("ADDED_WHO")]
public string? AddedWho { get; init; }
[Column("ADDED_WHEN")]
public DateTime AddedWhen { get; init; }
[Column("CHANGED_WHO")]
public string? ChangedWho { get; init; }
[Column("CHANGED_WHEN")]
public DateTime? ChangedWhen { get; init; }
[Column("FIRST_RUN")]
public DateTime? FirstRun { get; init; }
[Column("LAST_RUN")]
public DateTime? LastRun { get; init; }
[Column("LAST_RESULT")]
public string? LastResult { get; init; }
}

View File

@@ -1,4 +1,5 @@
using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Views;
@@ -16,72 +17,109 @@ public class RecActionView
{
public virtual IEnumerable<ResultView>? Results { get; set; }
[Key]
[Column("ACTION_GUID")]
public required long Id { get; set; }
[Column("PROFILE_ID")]
public long? ProfileId { get; set; }
[ForeignKey("ProfileId")]
public ProfileView? Profile { get; set; }
[Column("PROFILE_NAME")]
public string? ProfileName { get; set; }
[Column("PROFILE_TYPE_ID")]
public ProfileType? ProfileType { get; set; }
[Column("PROFILE_TYPE")]
public string? ProfileTypeName { get; set; }
[Column("SEQUENCE")]
public byte? Sequence { get; set; }
[Column("ENDPOINT_ID")]
public long? EndpointId { get; set; }
[Column("ENDPOINT_URI")]
public string? EndpointUri { get; set; }
[Column("ENDPOINT_AUTH_ID")]
public long? EndpointAuthId { get; set; }
[Column("ENDPOINT_AUTH_TYPE_ID")]
public EndpointAuthType? EndpointAuthType { get; set; }
[Column("ENDPOINT_AUTH_TYPE")]
public string? EndpointAuthTypeName { get; set; }
[Column("ENDPOINT_AUTH_API_KEY")]
public string? EndpointAuthApiKey { get; set; }
[Column("ENDPOINT_AUTH_API_VALUE")]
public string? EndpointAuthApiValue { get; set; }
[Column("ENDPOINT_AUTH_API_KEY_ADD_TO_ID")]
public ApiKeyLocation? EndpointAuthApiKeyAddTo { get; set; }
[Column("ENDPOINT_AUTH_API_KEY_ADD_TO")]
public string? EndpointAuthApiKeyAddToName { get; set; }
[Column("ENDPOINT_AUTH_TOKEN")]
public string? EndpointAuthToken { get; set; }
[Column("ENDPOINT_AUTH_USERNAME")]
public string? EndpointAuthUsername { get; set; }
[Column("ENDPOINT_AUTH_PASSWORD")]
public string? EndpointAuthPassword { get; set; }
[Column("ENDPOINT_AUTH_DOMAIN")]
public string? EndpointAuthDomain { get; set; }
[Column("ENDPOINT_AUTH_WORKSTATION")]
public string? EndpointAuthWorkstation { get; set; }
[Column("ENDPOINT_PARAMS_ID")]
public short? EndpointParamsId { get; set; }
[Column("SQL_CONNECTION_ID")]
public short? SqlConnectionId { get; set; }
[Column("SQL_CONNECTION_SERVER")]
public string? SqlConnectionServer { get; set; }
[Column("SQL_CONNECTION_DB")]
public string? SqlConnectionDb { get; set; }
[Column("SQL_CONNECTION_USERNAME")]
public string? SqlConnectionUsername { get; set; }
[Column("SQL_CONNECTION_PASSWORD")]
public string? SqlConnectionPassword { get; set; }
[Column("REST_TYPE_ID")]
public RestType? RestType { get; set; }
[Column("REST_TYPE")]
public string? RestTypeName { get; set; }
[Column("PREPROCESSING_QUERY")]
public string? PreprocessingQuery { get; set; }
[Column("HEADER_QUERY")]
public string? HeaderQuery { get; set; }
[Column("BODY_QUERY")]
public string? BodyQuery { get; set; }
[Column("POSTPROCESSING_QUERY")]
public string? PostprocessingQuery { get; set; }
[Column("ERROR_ACTION_ID")]
public ErrorAction? ErrorAction { get; set; }
[Column("ERROR_ACTION")]
public string? ErrorActionName { get; set; }
}

View File

@@ -1,39 +1,86 @@
using System.ComponentModel.DataAnnotations.Schema;
using ReC.Domain.Constants;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace ReC.Domain.Views;
[Table("VWREC_RESULT", Schema = "dbo")]
public class ResultView
{
[Key]
[Column("RESULT_GUID")]
public long Id { get; set; }
[Column("ACTION_ID")]
public long? ActionId { get; set; }
public RecActionView? Action { get; set; }
[Column("PROFILE_ID")]
public long? ProfileId { get; set; }
public ProfileView? Profile { get; set; }
[Column("PROFILE_NAME")]
public string? ProfileName { get; set; }
public short? StatusCode { get; set; }
[Column("STATUS_ID")]
public RecStatus Status { get; set; }
[Column("STATUS")]
public string? StatusName { get; set; }
[Column("RESULT_TYPE_ID")]
public ResultType? Type { get; set; }
[Column("RESULT_TYPE")]
public string? TypeName { get; set; }
[Column("RESULT_HEADER")]
public string? Header { get; set; }
[Column("RESULT_BODY")]
public string? Body { get; set; }
[Column("RESULT_INFO_ID")]
public short? InfoId { get; set; }
[Column("RESULT_INFO")]
public string? Info { get; set; }
[Column("RESULT_INFO_DETAIL")]
public string? InfoDetail { get; set; }
[Column("RESULT_ERROR")]
public string? Error { get; set; }
[Column("BATCH_ID")]
public string? BatchId { get; set; }
[Column("REFERENCE1")]
public string? Reference1 { get; set; }
[Column("REFERENCE2")]
public string? Reference2 { get; set; }
[Column("REFERENCE3")]
public string? Reference3 { get; set; }
[Column("REFERENCE4")]
public string? Reference4 { get; set; }
[Column("REFERENCE5")]
public string? Reference5 { get; set; }
[Column("ADDED_WHO")]
public string? AddedWho { get; set; }
[Column("ADDED_WHEN")]
public DateTime? AddedWhen { get; set; }
[Column("CHANGED_WHO")]
public string? ChangedWho { get; set; }
[Column("CHANGED_WHEN")]
public DateTime? ChangedWhen { get; set; }
}

View File

@@ -29,7 +29,7 @@ public static class DependencyInjection
opt.RegisterDefaultRepository<TRecDbContext>();
});
services.AddValidatorsFromAssembly(typeof(AuthScopedValidator).Assembly);
services.AddValidatorsFromAssembly(typeof(InsertObjectProcedureValidator).Assembly);
return services;
}

View File

@@ -1,12 +0,0 @@
namespace ReC.Infrastructure.Exceptions;
public class DbModelConfigurationException : Exception
{
public DbModelConfigurationException(string message) : base(message)
{
}
public DbModelConfigurationException()
{
}
}

View File

@@ -1,23 +0,0 @@
using ReC.Infrastructure.Exceptions;
using ReC.Infrastructure.Options.Shared;
namespace ReC.Infrastructure.Options;
public record DbModelOptions
{
public Dictionary<string, EntityOptions> Entities { get; init; } = [];
public Dictionary<string, VirtualEntityOptions> VirtualEntities { get; init; } = [];
public void EnsureEntity<T>(bool isVirtual)
{
var entities = isVirtual
? VirtualEntities.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as EntityBaseOptions)
: Entities.ToDictionary(kvp => kvp.Key, kvp => kvp.Value as EntityBaseOptions);
if(entities.TryGetValue(nameof(T), out var entityOptions))
entityOptions.EnsureProperties<T>();
else
throw new DbModelConfigurationException($"Entity options for type '{typeof(T).FullName}' not found.");
}
}

View File

@@ -1,33 +0,0 @@
using ReC.Domain.Attributes;
using ReC.Infrastructure.Exceptions;
namespace ReC.Infrastructure.Options.Shared;
public record EntityBaseOptions()
{
public Dictionary<string, string> ColumnMappings { get; init; } = [];
public IEnumerable<string> PropertyNames => ColumnMappings.Select(col => col.Key);
public IEnumerable<string> ColumnNames => ColumnMappings.Select(col => col.Value);
public void EnsureProperties(IEnumerable<string> propertyNames)
{
var missingProperties = propertyNames.Except(PropertyNames).ToList();
if (missingProperties.Count != 0)
throw new DbModelConfigurationException($"The following properties are not configured: {string.Join(", ", missingProperties)}");
}
public void EnsureProperties(params string[] propertyNames)
=> EnsureProperties(propertyNames.AsEnumerable());
public void EnsureProperties<T>()
{
var propertyNames = typeof(T)
.GetProperties()
.Where(prop => Attribute.IsDefined(prop, typeof(MustConfiguredAttribute)))
.Select(prop => prop.Name);
EnsureProperties(propertyNames);
}
}

View File

@@ -1,3 +0,0 @@
namespace ReC.Infrastructure.Options.Shared;
public record EntityOptions(TableOptions Table) : EntityBaseOptions;

Some files were not shown because too many files have changed in this diff Show More