-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAPIService.cs
47 lines (44 loc) · 1.54 KB
/
APIService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Net.NetworkInformation;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using NITGEN.SDK.NBioBSP;
namespace BiometricService
{
public sealed class APIService : BackgroundService
{
private readonly ILogger<APIService> _logger;
public NBioAPI _NBioAPI;
public NBioAPI.IndexSearch _IndexSearch;
public APIService(ILogger<APIService> logger)
{
_logger = logger;
_NBioAPI = new NBioAPI();
_IndexSearch = new NBioAPI.IndexSearch(_NBioAPI);
_IndexSearch.InitEngine();
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Biometric API Service is starting.");
try
{
_logger.LogInformation("Biometric API Service is running.");
while (!stoppingToken.IsCancellationRequested)
{
await Task.Delay(5000, stoppingToken);
}
}
catch (OperationCanceledException) // Has been canceled manually
{
_NBioAPI.Dispose();
_IndexSearch.TerminateEngine();
_logger.LogInformation("Biometric API Service has been stopped.");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in Biometric API Service: {Message}", ex.Message);
Environment.Exit(1);
}
}
}
}