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>();
}
}
}

View File

@@ -0,0 +1,336 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using PARR.DAL.Context;
#nullable disable
namespace PARR.DAL.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20230601014714_UpdTblHosts")]
partial class UpdTblHosts
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("APP")
.HasColumnType("text");
b.Property<string>("DB")
.HasColumnType("text");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("HostName")
.IsRequired()
.HasColumnType("text");
b.Property<string>("IP")
.IsRequired()
.HasColumnType("text");
b.Property<string>("LinkEK")
.HasColumnType("text");
b.Property<string>("OS")
.HasColumnType("text");
b.Property<string>("RegionalEK")
.HasColumnType("text");
b.Property<string>("Responsible")
.HasColumnType("text");
b.Property<string>("Status")
.HasColumnType("text");
b.Property<string>("WorkGroup")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Hosts");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<Guid>("JobCategoryId")
.HasColumnType("uuid");
b.Property<Guid>("JobModeId")
.HasColumnType("uuid");
b.Property<Guid>("JobTypeId")
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("JobCategoryId");
b.HasIndex("JobModeId");
b.HasIndex("JobTypeId");
b.ToTable("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.JobCategory", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("JobCategories");
});
modelBuilder.Entity("PARR.DAL.Models.JobJournal", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("DateOper")
.HasColumnType("text");
b.Property<Guid>("HostId")
.HasColumnType("uuid");
b.Property<string>("Info")
.HasColumnType("text");
b.Property<Guid>("JobId")
.HasColumnType("uuid");
b.Property<Guid>("JobStatusId")
.HasColumnType("uuid");
b.Property<string>("Other")
.HasColumnType("text");
b.Property<int?>("TimeOut")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("HostId");
b.HasIndex("JobId");
b.HasIndex("JobStatusId");
b.ToTable("JobJournals");
});
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("JobModes");
});
modelBuilder.Entity("PARR.DAL.Models.JobStatus", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("JobStatuses");
});
modelBuilder.Entity("PARR.DAL.Models.JobType", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("JobTypes");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
{
b.HasOne("PARR.DAL.Models.JobCategory", "JobCategorye")
.WithMany("Jobs")
.HasForeignKey("JobCategoryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobMode", "JobMode")
.WithMany("Jobs")
.HasForeignKey("JobModeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobType", "JobType")
.WithMany("Jobs")
.HasForeignKey("JobTypeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("JobCategorye");
b.Navigation("JobMode");
b.Navigation("JobType");
});
modelBuilder.Entity("PARR.DAL.Models.JobJournal", b =>
{
b.HasOne("PARR.DAL.Models.Host", "Host")
.WithMany("JobJournals")
.HasForeignKey("HostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.Job", "Job")
.WithMany("Journals")
.HasForeignKey("JobId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("PARR.DAL.Models.JobStatus", "Status")
.WithMany("Journals")
.HasForeignKey("JobStatusId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Host");
b.Navigation("Job");
b.Navigation("Status");
});
modelBuilder.Entity("PARR.DAL.Models.Host", b =>
{
b.Navigation("JobJournals");
});
modelBuilder.Entity("PARR.DAL.Models.Job", b =>
{
b.Navigation("Journals");
});
modelBuilder.Entity("PARR.DAL.Models.JobCategory", b =>
{
b.Navigation("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
{
b.Navigation("Jobs");
});
modelBuilder.Entity("PARR.DAL.Models.JobStatus", b =>
{
b.Navigation("Journals");
});
modelBuilder.Entity("PARR.DAL.Models.JobType", b =>
{
b.Navigation("Jobs");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,98 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PARR.DAL.Migrations
{
/// <inheritdoc />
public partial class UpdTblHosts : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "EK",
table: "Hosts",
newName: "WorkGroup");
migrationBuilder.AddColumn<string>(
name: "APP",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "DB",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "LinkEK",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "OS",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "RegionalEK",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Responsible",
table: "Hosts",
type: "text",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "Status",
table: "Hosts",
type: "text",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "APP",
table: "Hosts");
migrationBuilder.DropColumn(
name: "DB",
table: "Hosts");
migrationBuilder.DropColumn(
name: "LinkEK",
table: "Hosts");
migrationBuilder.DropColumn(
name: "OS",
table: "Hosts");
migrationBuilder.DropColumn(
name: "RegionalEK",
table: "Hosts");
migrationBuilder.DropColumn(
name: "Responsible",
table: "Hosts");
migrationBuilder.DropColumn(
name: "Status",
table: "Hosts");
migrationBuilder.RenameColumn(
name: "WorkGroup",
table: "Hosts",
newName: "EK");
}
}
}

View File

@@ -28,15 +28,18 @@ namespace PARR.DAL.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("APP")
.HasColumnType("text");
b.Property<string>("DB")
.HasColumnType("text");
b.Property<DateTimeOffset>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("DateModified")
.HasColumnType("timestamp with time zone");
b.Property<string>("EK")
.HasColumnType("text");
b.Property<string>("HostName")
.IsRequired()
.HasColumnType("text");
@@ -45,6 +48,24 @@ namespace PARR.DAL.Migrations
.IsRequired()
.HasColumnType("text");
b.Property<string>("LinkEK")
.HasColumnType("text");
b.Property<string>("OS")
.HasColumnType("text");
b.Property<string>("RegionalEK")
.HasColumnType("text");
b.Property<string>("Responsible")
.HasColumnType("text");
b.Property<string>("Status")
.HasColumnType("text");
b.Property<string>("WorkGroup")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Hosts");

View File

@@ -13,7 +13,14 @@ namespace PARR.DAL.Models
public DateTimeOffset? DateModified { get; set; }
public required string HostName { get; set; }
public required string IP { get; set; }
public string? EK { get; set; }
public string? RegionalEK { get; set; }
public string? LinkEK { get; set; }
public string? Status { get; set; }
public string? WorkGroup { get; set; }
public string? Responsible { get; set; }
public string? OS { get; set; }
public string? DB { get; set; }
public string? APP { get; set; }

View File

@@ -18,7 +18,6 @@
<ItemGroup>
<Folder Include="Contracts\" />
<Folder Include="Services\Implementations\" />
</ItemGroup>
</Project>

View File

@@ -2,6 +2,8 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.DAL.Context;
using PARR.DAL.Services.Implementations;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL
{
@@ -13,7 +15,7 @@ namespace PARR.DAL
opt.UseNpgsql(configuration.GetConnectionString("DefaultConnection"))
);
//services.AddTransient<ILayerService, LayerService>();
services.AddTransient<IHostService, HostService>();
//services.AddTransient<IUsersInLayersService, UsersInLayersService>();
//services.AddTransient<IAreaService, AreaService>();
//services.AddTransient<IAreasInLayerService, AreasInLayerService>();

View File

@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class HostService : BaseService<Host>, IHostService
{
private readonly DataContext dataContext;
private readonly ILogger<HostService> logger;
protected override DbSet<Host> EntitySet => dataContext.Hosts;
protected override DataContext EntitiContext => dataContext;
public HostService(DataContext dataContext, ILogger<HostService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
}
}

View File

@@ -0,0 +1,9 @@
using PARR.DAL.Models;
using PARR.DAL.Services.Interfaces.Base;
namespace PARR.DAL.Services.Interfaces
{
public interface IHostService : IBaseService<Host>
{
}
}

View File

@@ -0,0 +1,19 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.Mail.Services;
using PARR.Mail.Settings;
namespace PARR.Mail
{
public static class MailInstaller
{
public static void InstallMailServices(this IServiceCollection services, IConfiguration configuration)
{
var mailSettings = new MailSettings();
configuration.GetSection(nameof(MailSettings)).Bind(mailSettings);
services.AddSingleton(mailSettings);
services.AddTransient<IMailService, MailService>();
}
}
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="4.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,15 @@
using MailKit;
using MailKit.Search;
using MimeKit;
namespace PARR.Mail.Services
{
public interface IMailService
{
Task<IList<IMessageSummary>> CheckMailAsync(SearchQuery query);
Task<MimeEntity> GetBodyPartAsync(IMessageSummary messageSummary);
Task<List<MimeEntity>> GetAttachmentsAsync(IMessageSummary messageSummary);
Task<string> GetBodyTextAsync(IMessageSummary messageSummary);
Task SetAsSeenAsync(IMessageSummary messageSummary);
}
}

View File

@@ -0,0 +1,85 @@
using MailKit;
using MailKit.Net.Imap;
using MailKit.Search;
using MailKit.Security;
using Microsoft.Extensions.Logging;
using MimeKit;
using PARR.Mail.Settings;
namespace PARR.Mail.Services
{
internal class MailService : IMailService
{
private readonly ILogger<MailService> logger;
private readonly MailSettings mailSettings;
public MailService(ILogger<MailService> logger, MailSettings mailSettings)
{
this.logger = logger;
this.mailSettings = mailSettings;
}
public async Task<IList<IMessageSummary>> CheckMailAsync(SearchQuery query)
{
using var client = await GetClient();
IList<IMessageSummary> items = new List<IMessageSummary>();
try
{
var uids = await client.Inbox.SearchAsync(query);
items = await client.Inbox.FetchAsync(uids, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure | MessageSummaryItems.Envelope);
}
catch (Exception e)
{
logger.LogError(e, "Ошибка получения списка писем");
}
return items;
}
public async Task<MimeEntity> GetBodyPartAsync(IMessageSummary messageSummary)
{
using var client = await GetClient();
return await client.Inbox.GetBodyPartAsync(messageSummary.UniqueId, messageSummary.TextBody);
}
public async Task<List<MimeEntity>> GetAttachmentsAsync(IMessageSummary messageSummary)
{
using var client = await GetClient();
List<MimeEntity> result = new List<MimeEntity>();
foreach (var attachment in messageSummary.Attachments)
{
result.Add(await client.Inbox.GetBodyPartAsync(messageSummary.UniqueId, attachment));
}
return result;
}
public async Task<string> GetBodyTextAsync(IMessageSummary messageSummary)
{
using var client = await GetClient();
return ((TextPart)await client.Inbox.GetBodyPartAsync(messageSummary.UniqueId, messageSummary.TextBody)).Text;
}
public async Task SetAsSeenAsync(IMessageSummary messageSummary)
{
using var client = await GetClient();
await client.Inbox.AddFlagsAsync(messageSummary.UniqueId, MessageFlags.Seen, false);
}
private async Task<ImapClient> GetClient()
{
var client = new ImapClient();
await client.ConnectAsync(mailSettings.Host, mailSettings.Port, SecureSocketOptions.None);
await client.AuthenticateAsync(mailSettings.UserName, mailSettings.Password);
await client.Inbox.OpenAsync(FolderAccess.ReadWrite);
// игнорить сертификат
client.CheckCertificateRevocation = false;
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
return client;
}
}
}

View File

@@ -0,0 +1,11 @@
namespace PARR.Mail.Settings
{
internal class MailSettings
{
public string Host { get; set; }
public int Port { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public bool SSL { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-PARR.Worker-87bfa085-3c62-4b97-b25f-bdece8fc03df</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.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,22 @@
using PARR.DAL;
using PARR.Mail;
using PARR.Worker;
using Serilog;
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
{
services.InstallMailServices(hostContext.Configuration);
services.InstallDalServices(hostContext.Configuration);
services.AddHostedService<Worker>();
})
.UseSerilog((hostContext, services, config) =>
{
config
.WriteTo.Console()
.ReadFrom.Configuration(hostContext.Configuration);
})
.Build();
host.Run();

View File

@@ -0,0 +1,11 @@
{
"profiles": {
"PARR.Worker": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,10 @@
namespace PARR.Worker.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 PARR.Mail.Services;
using PARR.Worker.Settings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PARR.Worker
{
internal class Syncher
{
private readonly ILogger<Worker> logger;
private readonly IMailService mailService;
private readonly SyncherSettings aIHITSyncherSettings;
public Syncher(ILogger<Worker> logger, IMailService mailService, SyncherSettings aIHITSyncherSettings)
{
this.logger = logger;
this.mailService = mailService;
this.aIHITSyncherSettings = aIHITSyncherSettings;
}
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 => aIHITSyncherSettings.IncludeAddressesArray.Any(i => m.Envelope.From.Mailboxes.First().Address == i)).ToList();
}
}
}

View File

@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Services.Interfaces;
namespace PARR.Worker
{
public class Worker : BackgroundService
{
private readonly ILogger<Worker> logger;
private readonly IHostService hostService;
public Worker(ILogger<Worker> logger, IHostService hostService)
{
this.logger = logger;
this.hostService = hostService;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
logger.LogInformation("--- Сервис запущен! ---");
while (!stoppingToken.IsCancellationRequested)
{
var hosts = await hostService.Get().ToListAsync();
foreach ( var host in hosts ) { logger.LogInformation($"{host.HostName}"); }
// syncher.InvokeAsync();
//await attachmentUploader.UploadAsync();
//logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
await Task.Delay(60000, stoppingToken);
}
}
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

View File

@@ -0,0 +1,38 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Debug"
}
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "log/log-.txt",
"rollingInterval": "Day"
}
}
]
},
"MailSettings": {
"Host": "uc.dvgd.rzd",
"Password": "Robin123",
"Port": 143,
"SSL": false,
"UserName": "IVC_Robot"
},
"AIHITSyncherSettings": {
"OccursEvery": 60000,
"IncludeAddresses": "aihit@gvc.rzd"
}
}

View File

@@ -9,6 +9,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.DAL", "PARR.DAL\PARR.D
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{AF6BD539-34B2-4D57-AEB3-F6FDE26B98ED}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.Mail", "PARR.Mail\PARR.Mail\PARR.Mail.csproj", "{228C8124-69E4-4AE0-8C33-0438E54FF1BA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PARR.Worker", "PARR.Worker\PARR.Worker\PARR.Worker.csproj", "{D15F308C-9F63-4D69-B06E-DDA26FEE9BAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PARR.AIHIT", "PARR.AIHIT\AIHIT\PARR.AIHIT.csproj", "{3ED4E1CE-2AF5-4EB3-B7DF-B77CCC242B9E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -26,6 +32,18 @@ Global
{AF6BD539-34B2-4D57-AEB3-F6FDE26B98ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF6BD539-34B2-4D57-AEB3-F6FDE26B98ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF6BD539-34B2-4D57-AEB3-F6FDE26B98ED}.Release|Any CPU.Build.0 = Release|Any CPU
{228C8124-69E4-4AE0-8C33-0438E54FF1BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{228C8124-69E4-4AE0-8C33-0438E54FF1BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{228C8124-69E4-4AE0-8C33-0438E54FF1BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{228C8124-69E4-4AE0-8C33-0438E54FF1BA}.Release|Any CPU.Build.0 = Release|Any CPU
{D15F308C-9F63-4D69-B06E-DDA26FEE9BAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D15F308C-9F63-4D69-B06E-DDA26FEE9BAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D15F308C-9F63-4D69-B06E-DDA26FEE9BAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D15F308C-9F63-4D69-B06E-DDA26FEE9BAB}.Release|Any CPU.Build.0 = Release|Any CPU
{3ED4E1CE-2AF5-4EB3-B7DF-B77CCC242B9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3ED4E1CE-2AF5-4EB3-B7DF-B77CCC242B9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3ED4E1CE-2AF5-4EB3-B7DF-B77CCC242B9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3ED4E1CE-2AF5-4EB3-B7DF-B77CCC242B9E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -1,12 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
public class HomeController : Controller
{
public IActionResult Index()
private readonly IHostService hostService;
public HomeController(IHostService hostService)
{
return View();
this.hostService = hostService;
}
[HttpGet("test")]
public async Task<IActionResult> Index()
{
var hosts = await hostService.Get().ToListAsync();
//foreach (var host in hosts) { logger.LogInformation($"{host.HostName}"); }
//return View();
return Ok(hosts.Select(t => new { t.HostName, t.IP, t.Id }));
}
}
}