Services+Worker
This commit is contained in:
7
PARR.AIHIT/AIHIT/ISyncher.cs
Normal file
7
PARR.AIHIT/AIHIT/ISyncher.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace PARR.AIHIT
|
||||
{
|
||||
public interface ISyncher
|
||||
{
|
||||
Task InvokeAsync();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,22 @@
|
||||
using MailKit.Search;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.AIHIT.Settings;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.Mail.Services;
|
||||
|
||||
namespace PARR.AIHIT
|
||||
{
|
||||
internal class Syncher
|
||||
internal class Syncher : ISyncher
|
||||
{
|
||||
private readonly ILogger<Syncher> logger;
|
||||
private readonly IMailService mailService;
|
||||
private readonly SyncherSettings syncherSettings;
|
||||
private readonly IHostService hostService;
|
||||
|
||||
public Syncher(ILogger<Syncher> logger, IMailService mailService, SyncherSettings syncherSettings)
|
||||
public Syncher(ILogger<Syncher> logger, IMailService mailService, SyncherSettings syncherSettings, IHostService hostService)
|
||||
{
|
||||
this.hostService = hostService;
|
||||
this.logger = logger;
|
||||
this.mailService = mailService;
|
||||
this.syncherSettings = syncherSettings;
|
||||
@@ -20,6 +24,7 @@ namespace PARR.AIHIT
|
||||
|
||||
public async Task InvokeAsync()
|
||||
{
|
||||
var hosts = await hostService.Get().ToListAsync();
|
||||
var messages = await mailService.CheckMailAsync(SearchQuery.NotSeen);
|
||||
if (!messages.Any())
|
||||
{
|
||||
@@ -29,9 +34,9 @@ namespace PARR.AIHIT
|
||||
// var filtered = messages.Where(m => includeAddresses.Any(i => m.Envelope.From.Mailboxes.First().Address == i)).ToList();
|
||||
|
||||
var filtered = messages.Where(m => syncherSettings.IncludeAddressesArray.Any(i => m.Envelope.From.Mailboxes.First().Address == i)).ToList();
|
||||
foreach ( var message in filtered)
|
||||
foreach (var message in filtered)
|
||||
{
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,18 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using PARR.AIHIT.Settings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PARR.AIHIT
|
||||
{
|
||||
public class SyncherInstaller
|
||||
public static class SyncherInstaller
|
||||
{
|
||||
public void InstallerServices(IServiceCollection services, IConfiguration configuration)
|
||||
public static void InstallerSyncerServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var syncherSettings = new SyncherSettings();
|
||||
configuration.GetSection(nameof(SyncherSettings)).Bind(syncherSettings);
|
||||
services.AddSingleton(syncherSettings);
|
||||
|
||||
services.AddTransient<Syncher>();
|
||||
services.AddTransient<ISyncher, Syncher>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user