Syncer АИХ ИТ
This commit is contained in:
18
PARR.AIHIT/AIHIT/PARR.AIHIT.csproj
Normal file
18
PARR.AIHIT/AIHIT/PARR.AIHIT.csproj
Normal 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>
|
||||
10
PARR.AIHIT/AIHIT/Settings/SyncherSettings.cs
Normal file
10
PARR.AIHIT/AIHIT/Settings/SyncherSettings.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
38
PARR.AIHIT/AIHIT/Syncher.cs
Normal file
38
PARR.AIHIT/AIHIT/Syncher.cs
Normal 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
PARR.AIHIT/AIHIT/SyncherInstaller.cs
Normal file
23
PARR.AIHIT/AIHIT/SyncherInstaller.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user