Skip to content

TickerResult<TEntity>

Result type for all manager operations. Provides success status, result data, and exception information.

Type Definition

csharp
public class TickerResult<TEntity> where TEntity : class
{
    public bool IsSucceeded { get; }
    public TEntity Result { get; }
    public int AffectedRows { get; }
    public Exception Exception { get; }
}

Properties

PropertyTypeDescription
IsSucceededbooltrue if operation succeeded, false otherwise
ResultTEntityThe entity returned (created/updated entity)
AffectedRowsintNumber of database rows affected (for update/delete operations)
ExceptionExceptionException thrown if operation failed

Usage

csharp
var result = await _timeTickerManager.AddAsync(ticker);

if (result.IsSucceeded)
{
    var jobId = result.Result.Id;
    Console.WriteLine($"Job created: {jobId}");
}
else
{
    Console.WriteLine($"Error: {result.Exception?.Message}");
    // result.Exception contains the actual exception (TickerValidatorException, etc.)
}

Common Exception Types

  • TickerValidatorException: Validation errors (invalid function name, cron expression, etc.)
  • ArgumentNullException: Null entity provided
  • ArgumentException: Invalid arguments (e.g., null ExecutionTime)
  • Database exceptions: When using EF Core persistence

Error Handling Patterns

Basic Error Check

csharp
var result = await _manager.AddAsync(entity);

if (!result.IsSucceeded)
{
    _logger.LogError(result.Exception, "Operation failed");
    return; // Handle error appropriately
}

Specific Exception Handling

csharp
var result = await _manager.AddAsync(entity);

if (!result.IsSucceeded)
{
    switch (result.Exception)
    {
        case TickerValidatorException ex:
            _logger.LogWarning("Validation error: {Message}", ex.Message);
            break;
        case ArgumentNullException:
            _logger.LogError("Null entity provided");
            break;
        default:
            _logger.LogError(result.Exception, "Unexpected error");
            break;
    }
}

Using Affected Rows

For update and delete operations:

csharp
var result = await _manager.UpdateAsync(entity);

if (result.IsSucceeded)
{
    Console.WriteLine($"Updated {result.AffectedRows} row(s)");
}

See Also

Built by Albert Kunushevci