Class AASImportServiceClient
Concrete class that implement HTTP calls on Import Microservice.
Implements
Inherited Members
Namespace: StoneCo.TransRep.AASImport.Host.Client
Assembly: cs.temp.dll.dll
Syntax
public class AASImportServiceClient : AASImportServiceClientBase, IAASImportServiceClient
Constructors
AASImportServiceClient(IOptionsSnapshot<AASImportServiceClientOptions>, IHttpRestServiceClient, IConfiguration)
Default constructor to set options and HttpRestServiceClient.
Declaration
public AASImportServiceClient(IOptionsSnapshot<AASImportServiceClientOptions> options, IHttpRestServiceClient httpRestServiceClient, IConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
IOptionsSnapshot<AASImportServiceClientOptions> | options | The options design pattern used in AASImportServiceClient. |
IHttpRestServiceClient | httpRestServiceClient | Interface with the default methods and properties to be used for all HTTP Rest calls. |
IConfiguration | configuration | Represents a set of key/value application configuration properties. |
Examples
Create a options configuration on class with name AppSettingsOptionsConfigurations on folder Configurations.
public static class AppSettingsOptionsConfigurations
{
private static string AppSettingsAASImportServiceClient => "Clients:AASImportServiceClient";
public static void ConfigureAppSettingsOptions(this IServiceCollection services, IConfiguration configuration)
{
services.AddOptions();
services.Configure<AASImportServiceClientOptions>(options =>
configuration.GetSection(AppSettingsAASImportServiceClient).Bind(options));
}
}
Representation on appsettings.json file.
{
"Clients": {
"AASImportServiceClient": {
"Name": "AASImportServiceClient",
"AuthorizationToken": "a07f5aa4d2654c0e91412ee7025de133",
"BaseAddress": "https://domain-of-api.com/"
}
}
}
Dependency injection on application.
public class DIFactory
{
public static void ConfigureDI(IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<IAASImportServiceClient, AASImportServiceClient>(configuration.GetValue<string>("Clients:AASImportServiceClient:Name"), configuration.GetValue<string>("Clients:AASImportServiceClient:BaseAddress"));
}
}
Finally, follow the example of how to use the client.
public class Bar
{
private IAASImportServiceClient AASImportServiceClient { get; }
public Bar(IAASImportServiceClient aasImportServiceClient) => AASImportServiceClient = aasImportServiceClient;
public async Task SetAsImported(string acquirerTransactionKey, string acquirerOperationKey)
{
var traceKey = Guid.NewGuid().ToString("N");
var request = new AASImportRequestMessage
{
AASImportKeyMessages = new List<AASImportKeyMessage>()
{
new AASImportKeyMessage
{
AcquirerTransactionKey = acquirerTransactionKey,
AcquirerOperationKey = acquirerOperationKey
}
}
};
request.AddHeader(Headers.TraceKey, traceKey);
var result = await AASImportServiceClient.SetAsImportedAsync(request);
}
public async Task GetTransactionsToImport(string acquirerTransactionKey, string acquirerOperationKey)
{
var traceKey = Guid.NewGuid().ToString("N");
var request = new AASTransactionKeyRequestMessage
{
AASTransactionKeyMessages = new List<AASTransactionKeyMessage>()
{
new AASTransactionKeyMessage
{
AcquirerTransactionKey = acquirerTransactionKey,
AcquirerOperationKey = acquirerOperationKey
}
}
};
request.AddHeader(Headers.TraceKey, traceKey);
var result = await AASImportServiceClient.GetTransactionsToImportAsync(request);
}
}
Methods
GetTransactionsToImportAsync(AASTransactionKeyRequestMessage)
Asynchronous call to get ID_TRANSACTION and ID_ORIGINAL_TRX on AAS database to include on transaction to import.
Declaration
public Task<ResultResponseMessage<AASTransactionToImportResponseMessage>> GetTransactionsToImportAsync(AASTransactionKeyRequestMessage request)
Parameters
Type | Name | Description |
---|---|---|
AASTransactionKeyRequestMessage | request | Request whit values to set. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<ResultResponseMessage<AASTransactionToImportResponseMessage>> | Result of operations. |
SetAsImportedAsync(AASImportRequestMessage)
Asynchronous call to set as imported authorization on AAS database.
Declaration
public Task<ResultResponseMessage<AASImportResponseMessage>> SetAsImportedAsync(AASImportRequestMessage request)
Parameters
Type | Name | Description |
---|---|---|
AASImportRequestMessage | request | Request whit values to set. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<ResultResponseMessage<AASImportResponseMessage>> | Result of operations with result set on the response header. |