Switched to standard MonIn library
This commit is contained in:
@ -1,18 +1,20 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
using Infineon.Monitoring.MonA;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public class WindowsService : BackgroundService {
|
||||
private readonly ILogger<WindowsService> _logger;
|
||||
private readonly IMonInWorkerClient _monInClient;
|
||||
private readonly IMonInClient _monInClient;
|
||||
|
||||
public WindowsService(ILogger<WindowsService> logger,
|
||||
IServiceProvider serviceProvider) {
|
||||
_logger = logger ??
|
||||
throw new ArgumentNullException("ILogger not injected");
|
||||
using (IServiceScope scope = serviceProvider.CreateScope()) {
|
||||
_monInClient = scope.ServiceProvider.GetService<IMonInWorkerClient>() ??
|
||||
throw new ArgumentNullException("IMonInWorkerClient not injected");
|
||||
_monInClient = scope.ServiceProvider.GetService<IMonInClient>() ??
|
||||
throw new ArgumentNullException("IMonInClient not injected");
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,18 +23,18 @@ public class WindowsService : BackgroundService {
|
||||
|
||||
try {
|
||||
while (!stoppingToken.IsCancellationRequested) {
|
||||
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
|
||||
_monInClient.PostStatus("WindowsService", State.Ok);
|
||||
|
||||
_monInClient.PostStatus("WindowsService", StatusValue.Ok);
|
||||
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
|
||||
}
|
||||
} catch (OperationCanceledException) {
|
||||
_logger.LogError("The Windows service has been stopped");
|
||||
|
||||
_monInClient.PostStatus("WindowsService", StatusValue.Critical);
|
||||
_monInClient.PostStatus("WindowsService", State.Critical);
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"An exception occurred when running Windows Service. Exception: {ex.Message}");
|
||||
|
||||
_monInClient.PostStatus("WindowsService", StatusValue.Critical);
|
||||
_monInClient.PostStatus("WindowsService", State.Critical);
|
||||
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user