mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-24 05:22:22 +00:00
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using EasyNetQ;
|
|
using MalwareMultiScan.Shared.Data.Messages;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace MalwareMultiScan.Api.Services
|
|
{
|
|
public class ReceiverHostedService : IHostedService
|
|
{
|
|
private readonly IBus _bus;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ScanResultService _scanResultService;
|
|
|
|
public ReceiverHostedService(IBus bus, IConfiguration configuration, ScanResultService scanResultService)
|
|
{
|
|
_bus = bus;
|
|
_configuration = configuration;
|
|
_scanResultService = scanResultService;
|
|
}
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
_bus.Receive<ScanResultMessage>(_configuration.GetValue<string>("ResultsSubscriptionId"), async message =>
|
|
{
|
|
await _scanResultService.UpdateScanResultForBackend(
|
|
message.Id, message.Backend, true, true, message.Threats);
|
|
});
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
_bus.Dispose();
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
} |