Syncer АИХ ИТ

This commit is contained in:
Mikhail Kuznetsov
2023-06-01 12:30:38 +10:00
parent e34037267c
commit 118cd280df
27 changed files with 953 additions and 8 deletions

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\PARR.DAL\PARR.DAL.csproj" />
<ProjectReference Include="..\..\PARR.Mail\PARR.Mail\PARR.Mail.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,10 @@
namespace PARR.AIHIT.Settings
{
internal class SyncherSettings
{
public int OccursEvery { get; set; }
public string? IncludeAddresses { get; set; }
public List<string> IncludeAddressesArray => IncludeAddresses == null ? new List<string>() : IncludeAddresses.Split(",").ToList();
}
}

View File

@@ -0,0 +1,38 @@
using MailKit.Search;
using Microsoft.Extensions.Logging;
using PARR.AIHIT.Settings;
using PARR.Mail.Services;
namespace PARR.AIHIT
{
internal class Syncher
{
private readonly ILogger<Syncher> logger;
private readonly IMailService mailService;
private readonly SyncherSettings syncherSettings;
public Syncher(ILogger<Syncher> logger, IMailService mailService, SyncherSettings syncherSettings)
{
this.logger = logger;
this.mailService = mailService;
this.syncherSettings = syncherSettings;
}
public async Task InvokeAsync()
{
var messages = await mailService.CheckMailAsync(SearchQuery.NotSeen);
if (!messages.Any())
{
return;
}
//var includeAddresses = aIHITSyncherSettings.IncludeAddresses.Any() ? aIHITSyncherSettings.IncludeAddresses.Split(",") : null;
// 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)
{
}
}
}
}

View File

@@ -0,0 +1,23 @@
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 void InstallerServices(IServiceCollection services, IConfiguration configuration)
{
var syncherSettings = new SyncherSettings();
configuration.GetSection(nameof(SyncherSettings)).Bind(syncherSettings);
services.AddSingleton(syncherSettings);
services.AddTransient<Syncher>();
}
}
}