Interface IFailureRegistration
Represents a results handler that can register a failure.
Namespace: OpenText.Fusion.AdapterSdk.Api
Assembly: OpenText.Fusion.AdapterSdk.Api.dll
Syntax
public interface IFailureRegistration
Methods
RegisterFailureAsync(IFailureDetails, CancellationToken)
Registers the failure not related to a specific file or location.
Declaration
ValueTask RegisterFailureAsync(IFailureDetails failureDetails, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
IFailureDetails | failureDetails | The failure details. |
CancellationToken | cancellationToken | The task cancellation token. |
Returns
Type | Description |
---|---|
ValueTask |
|
Examples
The example below demonstrates how to register a failure that is not specific to any location. In this case, the operation has failed before any processing occurred.
public async Task RetrieveFilesDataAsync(RetrieveFilesDataRequest request, IFileDataResultsHandler handler, CancellationToken cancellationToken)
{
var userName = request.RepositoryProperties.RepositoryOptions["UserName"].ToString();
var password = request.RepositoryProperties.RepositoryOptions["Password"].ToString();
try
{
// Log into the repository service and obtain an authentication token...
// This operation can fail with an exception
var serviceToken = LogIn(userName, password);
// Do further processing of the request....
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to log into the repository");
// Register a failure that is not specific to a file or a location - we were not able to process any file yet.
// Exceptions message is automatically added to the reported failure.
handler.RegisterFailure(new FailureDetails($"Failed to log in {userName} to the repository", ex), cancellationToken);
}
}
Exceptions
Type | Condition |
---|---|
AbortRequestedException | Processing of the current operation should be aborted. |
RegisterFailureAsync(Nullable<String>, IFailureDetails, CancellationToken)
Registers a failure.
Declaration
ValueTask RegisterFailureAsync(string? fileLocation, IFailureDetails failureDetails, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.String> | fileLocation | A full location or identifier of a file in the repository. |
IFailureDetails | failureDetails | Failure details. |
CancellationToken | cancellationToken | The task cancellation token. |
Returns
Type | Description |
---|---|
ValueTask |
|
Remarks
Registers a failure for a specific file or a repository location.
Examples
In the example of the RegisterFailure
method usage below, the construction of FileInfo
and opening of the file stream (OpenRead
) can cause an exception to be thrown.
Those failures should be handled by the adapter and reported back to Fusion using RegisterFailure
method.
public async Task RetrieveFilesDataAsync(RetrieveFilesDataRequest request, IFileDataResultsHandler handler, CancellationToken cancellationToken)
{
foreach (var repositoryFile in request.Files)
{
try
{
// Both of those operations can fail
var file = new FileInfo(repositoryFile.Metadata.FileLocation);
var fileStream = file.OpenRead();
// processing and queueing contents...
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to obtain file contents for {FileLocation}", repositoryFile.Metadata.FileLocation);
// Register a failure for the current file. Exceptions message is automatically added to the reported failure.
handler.RegisterFailure(repositoryFile.Metadata.FileLocation,
new FailureDetails($"Failed to obtain file contents", ex),
cancellationToken);
}
}
}
Exceptions
Type | Condition |
---|---|
AbortRequestedException | Processing of the current operation should be aborted. |