чут чут работа над письмами (абстрактМейлВоркер + МейлКит) + классы РепортЛоджик
This commit is contained in:
parent
9dfc3a737d
commit
11db469329
@ -0,0 +1,39 @@
|
|||||||
|
using LawCompanyBusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using LawCompanyBusinessLogic.OfficePackage;
|
||||||
|
using LawCompanyContracts.BindingModels;
|
||||||
|
using LawCompanyContracts.BusinessLogicContracts;
|
||||||
|
using LawCompanyContracts.SearchModels;
|
||||||
|
using LawCompanyContracts.StoragesContracts;
|
||||||
|
using LawCompanyContracts.ViewModels;
|
||||||
|
using LawCompanyDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace HotelBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ReportLogicExecutor : IReportExecutorLogic
|
||||||
|
{
|
||||||
|
private readonly IHearingStorage _hearingStorage;
|
||||||
|
private readonly ILawyerStorage _lawyerStorage;
|
||||||
|
private readonly IVisitStorage _visitStorage;
|
||||||
|
private readonly IConsultationStorage _consultationStorage;
|
||||||
|
private readonly ICaseStorage _caseStorage;
|
||||||
|
private readonly AbstractSaveToExcelExecutor _saveToExcel;
|
||||||
|
private readonly AbstractSaveToWordExecutor _saveToWord;
|
||||||
|
private readonly AbstractSaveToPdfExecutor _saveToPdf;
|
||||||
|
|
||||||
|
public ReportLogicGuarantor(IHearingStorage hearingStorage, ILawyerStorage lawyerStorage,
|
||||||
|
IVisitStorage visitStorage, IConsultationStorage consultationStorage, ICaseStorage caseStorage,
|
||||||
|
AbstractSaveToExcelExecutor saveToExcel, AbstractSaveToWordExecutor saveToWord, AbstractSaveToPdfExecutor saveToPdf)
|
||||||
|
{
|
||||||
|
_hearingStorage = hearingStorage;
|
||||||
|
_lawyerStorage = lawyerStorage;
|
||||||
|
_visitStorage = visitStorage;
|
||||||
|
_consultationStorage = consultationStorage;
|
||||||
|
_caseStorage = caseStorage;
|
||||||
|
_saveToExcel = saveToExcel;
|
||||||
|
_saveToWord = saveToWord;
|
||||||
|
_saveToPdf = saveToPdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
using LawCompanyBusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using LawCompanyBusinessLogic.OfficePackage;
|
||||||
|
using LawCompanyContracts.BindingModels;
|
||||||
|
using LawCompanyContracts.BusinessLogicContracts;
|
||||||
|
using LawCompanyContracts.SearchModels;
|
||||||
|
using LawCompanyContracts.StoragesContracts;
|
||||||
|
using LawCompanyContracts.ViewModels;
|
||||||
|
using LawCompanyDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace LawCompanyBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class ReportLogicGuarantor : IReportGuarantorLogic
|
||||||
|
{
|
||||||
|
private readonly IVisitStorage _visitStorage;
|
||||||
|
private readonly IClientStorage _clientStorage;
|
||||||
|
private readonly ICaseStorage _caseStorage;
|
||||||
|
private readonly IConsultationStorage _consultationStorage;
|
||||||
|
private readonly IHearingStorage _hearingStorage;
|
||||||
|
private readonly AbstractSaveToExcelGuarantor _saveToExcel;
|
||||||
|
private readonly AbstractSaveToWordGuarantor _saveToWord;
|
||||||
|
private readonly AbstractSaveToPdfGuarantor _saveToPdf;
|
||||||
|
|
||||||
|
public ReportLogicOrganiser(IVisitStorage visitStorage, IClientStorage clientStorage, ICaseStorage caseStorage,
|
||||||
|
IConsultationStorage consultationStorage, IHearingStorage hearingStorage,
|
||||||
|
AbstractSaveToExcelGuarantor saveToExcel, AbstractSaveToWordGuarantor saveToWord, AbstractSaveToPdfGuarantor saveToPdf)
|
||||||
|
{
|
||||||
|
_visitStorage = visitStorage;
|
||||||
|
_clientStorage = clientStorage;
|
||||||
|
_caseStorage = caseStorage;
|
||||||
|
_consultationStorage = consultationStorage;
|
||||||
|
_hearingStorage = hearingStorage;
|
||||||
|
_saveToExcel = saveToExcel;
|
||||||
|
_saveToWord = saveToWord;
|
||||||
|
_saveToPdf = saveToPdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -15,4 +15,8 @@
|
|||||||
<ProjectReference Include="..\LawCompanyDataModels\LawCompanyDataModels.csproj" />
|
<ProjectReference Include="..\LawCompanyDataModels\LawCompanyDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="OfficePackage\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
using LawCompanyContracts.BindingModels;
|
||||||
|
using LawCompanyContracts.BusinessLogicContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace LawCompanyBusinessLogic.MailWorker
|
||||||
|
{
|
||||||
|
public abstract class AbstractMailWorker
|
||||||
|
{
|
||||||
|
protected string _mailLogin = string.Empty;
|
||||||
|
protected string _mailPassword = string.Empty;
|
||||||
|
protected string _smtpClientHost = string.Empty;
|
||||||
|
protected int _smtpClientPort;
|
||||||
|
protected string _popHost = string.Empty;
|
||||||
|
protected int _popPort;
|
||||||
|
private readonly IExecutorLogic _executorLogic;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IExecutorLogic executorLogic)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_executorLogic = executorLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MailConfig(MailConfigBindingModel config)
|
||||||
|
{
|
||||||
|
_mailLogin = config.MailLogin;
|
||||||
|
_mailPassword = config.MailPassword;
|
||||||
|
_smtpClientHost = config.SmtpClientHost;
|
||||||
|
_smtpClientPort = config.SmtpClientPort;
|
||||||
|
_popHost = config.PopHost;
|
||||||
|
_popPort = config.PopPort;
|
||||||
|
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void MailSendAsync(MailSendInfoBindingModel info)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject);
|
||||||
|
|
||||||
|
await SendMailAsync(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using LawCompanyContracts.BindingModels;
|
||||||
|
using LawCompanyContracts.BusinessLogicContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using System.Net.Mime;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace LawCompanyBusinessLogic.MailWorker
|
||||||
|
{
|
||||||
|
public class MailKitWorker : AbstractMailWorker
|
||||||
|
{
|
||||||
|
public MailKitWorker(ILogger<MailKitWorker> logger, IExecutorLogic _executorLogic) : base(logger, _executorLogic) { }
|
||||||
|
|
||||||
|
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||||
|
{
|
||||||
|
using var objMailMessage = new MailMessage();
|
||||||
|
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
objMailMessage.From = new MailAddress(_mailLogin);
|
||||||
|
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
||||||
|
objMailMessage.Subject = info.Subject;
|
||||||
|
objMailMessage.Body = info.Text;
|
||||||
|
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||||
|
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||||
|
Attachment attachment = new Attachment("C:\\Reports\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
|
||||||
|
objMailMessage.Attachments.Add(attachment);
|
||||||
|
|
||||||
|
objSmtpClient.UseDefaultCredentials = false;
|
||||||
|
objSmtpClient.EnableSsl = true;
|
||||||
|
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||||
|
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||||
|
|
||||||
|
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,13 @@
|
|||||||
{
|
{
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:19906",
|
|
||||||
"sslPort": 44345
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"LawCompanyGuarantorApp": {
|
"LawCompanyGuarantorApp": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "https://localhost:7250;http://localhost:5131",
|
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
},
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"applicationUrl": "https://localhost:7250;http://localhost:5131"
|
||||||
},
|
},
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "IISExpress",
|
||||||
@ -24,5 +16,13 @@
|
|||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:19906",
|
||||||
|
"sslPort": 44345
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user