mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-10-10 20:26:16 +00:00
finished unit tests and docstrings
This commit is contained in:
@@ -2,11 +2,15 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Company>Volodymyr Smirnov</Company>
|
||||
<Product>MalwareMultiScan Scanner</Product>
|
||||
<AssemblyVersion>1.0.0</AssemblyVersion>
|
||||
<FileVersion>1.0.0</FileVersion>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EasyNetQ" Version="5.6.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -1,14 +1,15 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Backends.Enums;
|
||||
using MalwareMultiScan.Backends.Extensions;
|
||||
using MalwareMultiScan.Scanner.Services;
|
||||
using MalwareMultiScan.Scanner.Services.Implementations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace MalwareMultiScan.Scanner
|
||||
{
|
||||
public static class Program
|
||||
[ExcludeFromCodeCoverage]
|
||||
internal static class Program
|
||||
{
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
@@ -22,8 +23,8 @@ namespace MalwareMultiScan.Scanner
|
||||
{
|
||||
services.AddLogging();
|
||||
|
||||
services.AddScanningBackend(
|
||||
context.Configuration.GetValue<BackendType>("BackendType"));
|
||||
services.AddRabbitMq(context.Configuration);
|
||||
services.AddScanningBackend(context.Configuration);
|
||||
|
||||
services.AddHostedService<ScanHostedService>();
|
||||
}).RunConsoleAsync();
|
||||
|
@@ -5,32 +5,41 @@ using System.Threading.Tasks;
|
||||
using EasyNetQ;
|
||||
using MalwareMultiScan.Backends.Interfaces;
|
||||
using MalwareMultiScan.Backends.Messages;
|
||||
using MalwareMultiScan.Scanner.Services.Interfaces;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MalwareMultiScan.Scanner.Services
|
||||
namespace MalwareMultiScan.Scanner.Services.Implementations
|
||||
{
|
||||
internal class ScanHostedService : IHostedService
|
||||
/// <inheritdoc />
|
||||
public class ScanHostedService : IScanHostedService
|
||||
{
|
||||
private readonly IScanBackend _backend;
|
||||
private readonly IBus _bus;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger<ScanHostedService> _logger;
|
||||
|
||||
private IBus _bus;
|
||||
|
||||
public ScanHostedService(ILogger<ScanHostedService> logger, IConfiguration configuration, IScanBackend backend)
|
||||
/// <summary>
|
||||
/// Initialise scan hosted service.
|
||||
/// </summary>
|
||||
/// <param name="logger">Logger.</param>
|
||||
/// <param name="backend">Scan backend.</param>
|
||||
/// <param name="bus">EasyNetQ bus.</param>
|
||||
/// <param name="configuration">Configuration.</param>
|
||||
public ScanHostedService(
|
||||
ILogger<ScanHostedService> logger,
|
||||
IScanBackend backend, IBus bus,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_logger = logger;
|
||||
_bus = bus;
|
||||
_configuration = configuration;
|
||||
_backend = backend;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_bus = RabbitHutch.CreateBus(
|
||||
_configuration.GetConnectionString("RabbitMQ"));
|
||||
|
||||
_bus.Receive<ScanRequestMessage>(_backend.Id, Scan);
|
||||
|
||||
_logger.LogInformation(
|
||||
@@ -39,6 +48,7 @@ namespace MalwareMultiScan.Scanner.Services
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_bus.Dispose();
|
||||
@@ -62,9 +72,9 @@ namespace MalwareMultiScan.Scanner.Services
|
||||
Id = message.Id,
|
||||
Backend = _backend.Id
|
||||
};
|
||||
|
||||
|
||||
var stopwatch = new Stopwatch();
|
||||
|
||||
|
||||
stopwatch.Start();
|
||||
|
||||
try
|
||||
@@ -91,10 +101,10 @@ namespace MalwareMultiScan.Scanner.Services
|
||||
}
|
||||
|
||||
result.Duration = stopwatch.ElapsedMilliseconds / 1000;
|
||||
|
||||
|
||||
_logger.LogInformation(
|
||||
$"Sending scan results with status {result.Succeeded}");
|
||||
|
||||
|
||||
await _bus.SendAsync(
|
||||
_configuration.GetValue<string>("ResultsSubscriptionId"), result);
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace MalwareMultiScan.Scanner.Services.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Scan hosted service.
|
||||
/// </summary>
|
||||
public interface IScanHostedService : IHostedService
|
||||
{
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user