refactoring, documentation pending

This commit is contained in:
Volodymyr Smirnov
2020-10-26 17:06:29 +02:00
parent 29156b7f10
commit 14c9c26979
39 changed files with 121 additions and 457 deletions

View File

@@ -1,13 +1,7 @@
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using MalwareMultiScan.Api.Data.Configuration;
using MalwareMultiScan.Api.Data.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.GridFS;
@@ -17,16 +11,16 @@ namespace MalwareMultiScan.Api.Services
public class ScanResultService
{
private const string CollectionName = "ScanResults";
private readonly IMongoCollection<ScanResult> _collection;
private readonly GridFSBucket _bucket;
private readonly IMongoCollection<ScanResult> _collection;
private readonly ScanBackendService _scanBackendService;
public ScanResultService(IMongoDatabase db, ScanBackendService scanBackendService)
{
_scanBackendService = scanBackendService;
_collection = db.GetCollection<ScanResult>(CollectionName);
_bucket = new GridFSBucket(db);
}
@@ -40,7 +34,7 @@ namespace MalwareMultiScan.Api.Services
};
await _collection.InsertOneAsync(scanResult);
return scanResult;
}
@@ -51,12 +45,12 @@ namespace MalwareMultiScan.Api.Services
return await result.FirstOrDefaultAsync();
}
public async Task UpdateScanResultForBackend(string resultId, string backendId,
public async Task UpdateScanResultForBackend(string resultId, string backendId,
bool completed = false, bool succeeded = false, string[] threats = null)
{
var filterScanResult = Builders<ScanResult>.Filter.Where(r => r.Id == resultId);
var updateScanResult = Builders<ScanResult>.Update.Set(r => r.Results[backendId], new ScanResultEntry
{
Completed = completed,
@@ -85,7 +79,7 @@ namespace MalwareMultiScan.Api.Services
{
if (!ObjectId.TryParse(id, out var objectId))
return null;
return await _bucket.OpenDownloadStreamAsync(objectId, new GridFSDownloadOptions
{
Seekable = true