From e2ea58be1a24b96650898772bc98e34292f9d51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 8 May 2024 11:23:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BA=D0=BE=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=B7=D1=8F=20=D0=B4=D0=BE=D0=B1=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=D1=81=D1=8F=20=D1=81=D0=B8=D0=BB=D0=BE=D0=B9,=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D0=BA=D0=BE=D0=BB=20=D0=BD=D0=B5=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D1=8F=20=D0=B2=D1=8B=D0=BF=D1=80=D0=BE=D1=81=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B8=20=D0=B2=D1=8B=D0=BC=D0=BE=D0=BB=D0=B8=D1=82=D1=8C,?= =?UTF-8?q?=20=D0=BE=D0=BD=20=D0=BF=D1=80=D0=B8=D1=85=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D1=82=20=D1=81=20=D0=BD=D0=B5=D0=B1=D0=B5=D1=81=20-=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BF=D1=80=D0=BE=D1=88=D0=B5=D0=BD=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B5=D0=B6=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ClientLogic.cs | 10 ++--- .../MailWorker/AbstractMailWorker.cs | 18 ++++---- .../MailWorker/MailKitWorker.cs | 10 ++--- ... 20240508053502_InitialCreate.Designer.cs} | 43 ++++++++++++++++++- ...ate.cs => 20240508053502_InitialCreate.cs} | 29 +++++++++++++ .../CarpentryWorkshopDatabaseModelSnapshot.cs | 41 ++++++++++++++++++ 6 files changed, 131 insertions(+), 20 deletions(-) rename CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/{20240505132850_InitialCreate.Designer.cs => 20240508053502_InitialCreate.Designer.cs} (85%) rename CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/{20240505132850_InitialCreate.cs => 20240508053502_InitialCreate.cs} (85%) diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs index 7d4cab5..2867ac0 100644 --- a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -105,11 +105,11 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics { throw new ArgumentException("Некорретно введен email клиента", nameof(model.Email)); } - if (!Regex.IsMatch(model.Password, @"^(?=.*\d)(?=.*\W)(?=.*[^\d\s]).+$")) - { - throw new ArgumentException("Некорректно введен пароль клиента", nameof(model.Password)); - } - if (string.IsNullOrEmpty(model.Password)) + if (!Regex.IsMatch(model.Password, @"^(?=.*\d)(?=.*\W)(?=.*[^\d\s]).+$")) + { + throw new ArgumentException("Некорректно введен пароль клиента", nameof(model.Password)); + } + if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); } diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/MailWorker/AbstractMailWorker.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/MailWorker/AbstractMailWorker.cs index e4e5834..0d37188 100644 --- a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/MailWorker/AbstractMailWorker.cs +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -13,13 +13,12 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker protected string _popHost = string.Empty; protected int _popPort; private readonly IMessageInfoLogic _messageInfoLogic; - private readonly IClientLogic _clientLogic; private readonly ILogger _logger; - public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) + public AbstractMailWorker(ILogger logger, + IMessageInfoLogic messageInfoLogic) { _logger = logger; _messageInfoLogic = messageInfoLogic; - _clientLogic = clientLogic; } public void MailConfig(MailConfigBindingModel config) { @@ -29,7 +28,8 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker _smtpClientPort = config.SmtpClientPort; _popHost = config.PopHost; _popPort = config.PopPort; - _logger.LogDebug("Config: {login}, {password}, {clientHost},{ clientPOrt}, { popHost}, { popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort); + _logger.LogDebug($"Config: {_mailLogin}, {_mailPassword}, " + + $"{_smtpClientHost}, {_smtpClientPort}, {_popHost}, {_popPort}"); } public async void MailSendAsync(MailSendInfoBindingModel info) { @@ -41,7 +41,9 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker { return; } - if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text)) + if (string.IsNullOrEmpty(info.MailAddress) || + string.IsNullOrEmpty(info.Subject) || + string.IsNullOrEmpty(info.Text)) { return; } @@ -66,12 +68,10 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker _logger.LogDebug("Check Mail: {Count} new mails", list.Count); foreach (var mail in list) { - mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id; _messageInfoLogic.Create(mail); } } protected abstract Task SendMailAsync(MailSendInfoBindingModel info); - protected abstract Task> - ReceiveMailAsync(); + protected abstract Task> ReceiveMailAsync(); } -} +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/MailWorker/MailKitWorker.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/MailWorker/MailKitWorker.cs index e4a9f01..444d262 100644 --- a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/MailWorker/MailKitWorker.cs +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/MailWorker/MailKitWorker.cs @@ -11,7 +11,8 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker { public class MailKitWorker : AbstractMailWorker { - public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { } + public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) + : base(logger, messageInfoLogic) { } protected override async Task SendMailAsync(MailSendInfoBindingModel info) { using var objMailMessage = new MailMessage(); @@ -35,8 +36,7 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker throw; } } - protected override async Task> - ReceiveMailAsync() + protected override async Task> ReceiveMailAsync() { var list = new List(); using var client = new Pop3Client(); @@ -57,12 +57,12 @@ namespace CarpentryWorkshopBusinessLogic.MailWorker MessageId = message.MessageId, SenderName = mail.Address, Subject = message.Subject, - Body = message.TextBody + Body = message.TextBody != null ? message.TextBody : message.HtmlBody }); } } } - catch (MailKit.Security.AuthenticationException) + catch (AuthenticationException) { } finally { diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240505132850_InitialCreate.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240508053502_InitialCreate.Designer.cs similarity index 85% rename from CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240505132850_InitialCreate.Designer.cs rename to CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240508053502_InitialCreate.Designer.cs index dc91bfe..a13b8c7 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240505132850_InitialCreate.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240508053502_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace CarpentryWorkshopDatabaseImplement.Migrations { [DbContext(typeof(CarpentryWorkshopDatabase))] - [Migration("20240505132850_InitialCreate")] + [Migration("20240508053502_InitialCreate")] partial class InitialCreate { /// @@ -97,6 +97,36 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("MessageInfos"); + }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -186,6 +216,15 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.ToTable("WoodComponents"); }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b => { b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client") @@ -232,6 +271,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); }); diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240505132850_InitialCreate.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240508053502_InitialCreate.cs similarity index 85% rename from CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240505132850_InitialCreate.cs rename to CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240508053502_InitialCreate.cs index d705df7..50cdecb 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240505132850_InitialCreate.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240508053502_InitialCreate.cs @@ -70,6 +70,27 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations table.PrimaryKey("PK_Woods", x => x.Id); }); + migrationBuilder.CreateTable( + name: "MessageInfos", + columns: table => new + { + MessageId = table.Column(type: "nvarchar(450)", nullable: false), + ClientId = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MessageInfos", x => x.MessageId); + table.ForeignKey( + name: "FK_MessageInfos_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id"); + }); + migrationBuilder.CreateTable( name: "Orders", columns: table => new @@ -134,6 +155,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_MessageInfos_ClientId", + table: "MessageInfos", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ClientId", table: "Orders", @@ -163,6 +189,9 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "MessageInfos"); + migrationBuilder.DropTable( name: "Orders"); diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs index af33fb7..bfb4eda 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs @@ -94,6 +94,36 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.Property("MessageId") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageId"); + + b.HasIndex("ClientId"); + + b.ToTable("MessageInfos"); + }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -183,6 +213,15 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.ToTable("WoodComponents"); }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("Messages") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b => { b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Client", "Client") @@ -229,6 +268,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Client", b => { + b.Navigation("Messages"); + b.Navigation("Orders"); });