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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace PARR.DAL.Migrations
|
||||
b.ToTable("JobJournals");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -234,7 +234,7 @@ namespace PARR.DAL.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PARR.DAL.Models.JobMode", "JobMode")
|
||||
b.HasOne("PARR.DAL.Models.JobModeService", "JobModeService")
|
||||
.WithMany("Jobs")
|
||||
.HasForeignKey("JobModeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@@ -248,7 +248,7 @@ namespace PARR.DAL.Migrations
|
||||
|
||||
b.Navigation("JobCategorye");
|
||||
|
||||
b.Navigation("JobMode");
|
||||
b.Navigation("JobModeService");
|
||||
|
||||
b.Navigation("JobType");
|
||||
});
|
||||
@@ -295,7 +295,7 @@ namespace PARR.DAL.Migrations
|
||||
b.Navigation("Jobs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
|
||||
{
|
||||
b.Navigation("Jobs");
|
||||
});
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace PARR.DAL.Migrations
|
||||
b.ToTable("JobJournals");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -255,7 +255,7 @@ namespace PARR.DAL.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PARR.DAL.Models.JobMode", "JobMode")
|
||||
b.HasOne("PARR.DAL.Models.JobModeService", "JobModeService")
|
||||
.WithMany("Jobs")
|
||||
.HasForeignKey("JobModeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@@ -269,7 +269,7 @@ namespace PARR.DAL.Migrations
|
||||
|
||||
b.Navigation("JobCategorye");
|
||||
|
||||
b.Navigation("JobMode");
|
||||
b.Navigation("JobModeService");
|
||||
|
||||
b.Navigation("JobType");
|
||||
});
|
||||
@@ -316,7 +316,7 @@ namespace PARR.DAL.Migrations
|
||||
b.Navigation("Jobs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
|
||||
{
|
||||
b.Navigation("Jobs");
|
||||
});
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace PARR.DAL.Migrations
|
||||
b.ToTable("JobJournals");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@@ -252,7 +252,7 @@ namespace PARR.DAL.Migrations
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PARR.DAL.Models.JobMode", "JobMode")
|
||||
b.HasOne("PARR.DAL.Models.JobModeService", "JobModeService")
|
||||
.WithMany("Jobs")
|
||||
.HasForeignKey("JobModeId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
@@ -266,7 +266,7 @@ namespace PARR.DAL.Migrations
|
||||
|
||||
b.Navigation("JobCategorye");
|
||||
|
||||
b.Navigation("JobMode");
|
||||
b.Navigation("JobModeService");
|
||||
|
||||
b.Navigation("JobType");
|
||||
});
|
||||
@@ -313,7 +313,7 @@ namespace PARR.DAL.Migrations
|
||||
b.Navigation("Jobs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobMode", b =>
|
||||
modelBuilder.Entity("PARR.DAL.Models.JobModeService", b =>
|
||||
{
|
||||
b.Navigation("Jobs");
|
||||
});
|
||||
|
||||
24
PARR.DAL/Services/Implementations/JobCategoryService.cs
Normal file
24
PARR.DAL/Services/Implementations/JobCategoryService.cs
Normal 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 JobCategoryService : BaseService<JobCategory>, IJobCategoryService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
private readonly ILogger<JobCategoryService> logger;
|
||||
|
||||
public JobCategoryService(DataContext dataContext, ILogger<JobCategoryService> logger) : base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
this.logger = logger;
|
||||
}
|
||||
protected override DbSet<JobCategory> EntitySet => dataContext.JobCategories;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
}
|
||||
}
|
||||
24
PARR.DAL/Services/Implementations/JobJournalService.cs
Normal file
24
PARR.DAL/Services/Implementations/JobJournalService.cs
Normal 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 JobJournalService : BaseService<JobJournal>, IJobJournalService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
private readonly ILogger<JobJournalService> logger;
|
||||
|
||||
public JobJournalService(DataContext dataContext, ILogger<JobJournalService> logger) : base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
this.logger = logger;
|
||||
}
|
||||
protected override DbSet<JobJournal> EntitySet => dataContext.JobJournals;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
}
|
||||
}
|
||||
24
PARR.DAL/Services/Implementations/JobModeService.cs
Normal file
24
PARR.DAL/Services/Implementations/JobModeService.cs
Normal 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 JobModeService : BaseService<JobMode>, IJobModeService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
private readonly ILogger<JobModeService> logger;
|
||||
|
||||
public JobModeService(DataContext dataContext, ILogger<JobModeService> logger) : base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
this.logger = logger;
|
||||
}
|
||||
protected override DbSet<JobMode> EntitySet => dataContext.JobModes;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
}
|
||||
}
|
||||
30
PARR.DAL/Services/Implementations/JobService.cs
Normal file
30
PARR.DAL/Services/Implementations/JobService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PARR.DAL.Services.Implementations
|
||||
{
|
||||
internal class JobService : BaseService<Job>, IJobService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
private readonly ILogger<JobService> logger;
|
||||
|
||||
public JobService(DataContext dataContext,ILogger<JobService> logger):base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
this.logger = logger;
|
||||
}
|
||||
protected override DbSet<Job> EntitySet => dataContext.Jobs;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
|
||||
}
|
||||
}
|
||||
24
PARR.DAL/Services/Implementations/JobStatusService.cs
Normal file
24
PARR.DAL/Services/Implementations/JobStatusService.cs
Normal 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 JobStatusService : BaseService<JobStatus>, IJobStatusService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
private readonly ILogger<JobStatusService> logger;
|
||||
|
||||
public JobStatusService(DataContext dataContext, ILogger<JobStatusService> logger) : base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
this.logger = logger;
|
||||
}
|
||||
protected override DbSet<JobStatus> EntitySet => dataContext.JobStatuses;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
}
|
||||
}
|
||||
9
PARR.DAL/Services/Interfaces/IJobCategoryService.cs
Normal file
9
PARR.DAL/Services/Interfaces/IJobCategoryService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces
|
||||
{
|
||||
internal interface IJobCategoryService : IBaseService<JobCategory>
|
||||
{
|
||||
}
|
||||
}
|
||||
12
PARR.DAL/Services/Interfaces/IJobJournalService.cs
Normal file
12
PARR.DAL/Services/Interfaces/IJobJournalService.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces
|
||||
{
|
||||
internal interface IJobJournalService
|
||||
{
|
||||
}
|
||||
}
|
||||
9
PARR.DAL/Services/Interfaces/IJobModeService.cs
Normal file
9
PARR.DAL/Services/Interfaces/IJobModeService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces
|
||||
{
|
||||
internal interface IJobModeService : IBaseService<JobMode>
|
||||
{
|
||||
}
|
||||
}
|
||||
9
PARR.DAL/Services/Interfaces/IJobService.cs
Normal file
9
PARR.DAL/Services/Interfaces/IJobService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces
|
||||
{
|
||||
public interface IJobService : IBaseService<Job>
|
||||
{
|
||||
}
|
||||
}
|
||||
9
PARR.DAL/Services/Interfaces/IJobStatusService.cs
Normal file
9
PARR.DAL/Services/Interfaces/IJobStatusService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces
|
||||
{
|
||||
internal interface IJobStatusService : IBaseService<JobStatus>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\PARR.AIHIT\AIHIT\PARR.AIHIT.csproj" />
|
||||
<ProjectReference Include="..\..\PARR.DAL\PARR.DAL.csproj" />
|
||||
<ProjectReference Include="..\..\PARR.Mail\PARR.Mail\PARR.Mail.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using PARR.AIHIT;
|
||||
using PARR.DAL;
|
||||
using PARR.Mail;
|
||||
using PARR.Worker;
|
||||
@@ -8,6 +9,7 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
{
|
||||
services.InstallMailServices(hostContext.Configuration);
|
||||
services.InstallDalServices(hostContext.Configuration);
|
||||
services.InstallerSyncerServices(hostContext.Configuration);
|
||||
|
||||
services.AddHostedService<Worker>();
|
||||
})
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.AIHIT;
|
||||
|
||||
namespace PARR.Worker
|
||||
{
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> logger;
|
||||
private readonly IHostService hostService;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
|
||||
public Worker(ILogger<Worker> logger, IHostService hostService)
|
||||
public Worker(ILogger<Worker> logger, IServiceProvider serviceProvider)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.hostService = hostService;
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
@@ -19,12 +18,19 @@ namespace PARR.Worker
|
||||
logger.LogInformation("--- Сервис запущен! ---");
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
var hosts = await hostService.Get().ToListAsync();
|
||||
foreach ( var host in hosts ) { logger.LogInformation($"{host.HostName}"); }
|
||||
// syncher.InvokeAsync();
|
||||
using var scope = serviceProvider.CreateScope();
|
||||
var services = scope.ServiceProvider;
|
||||
var syncer = services.GetService<ISyncher>();
|
||||
|
||||
if (syncer != null) await syncer.InvokeAsync();
|
||||
|
||||
//var hosts = await hostService.Get().ToListAsync();
|
||||
//foreach ( var host in hosts ) { logger.LogInformation($"{host.HostName}"); }
|
||||
|
||||
|
||||
//await attachmentUploader.UploadAsync();
|
||||
//logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
await Task.Delay(60000, stoppingToken);
|
||||
await Task.Delay(60 * 1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=10.99.253.184;Database=parr;User Id=app_parr; Password=PosdfkhT&)%sdfligL&%5546;"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
Reference in New Issue
Block a user