From 8dbfbd88e98a50489bffe44954b438ccc22d0043 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 12:37:49 +0400 Subject: [PATCH 01/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B4?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=20=D0=BC=D0=BE=D0=B6=D0=B5=D0=BB=D0=B8=20=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D1=8C=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/IMessageInfoModel.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 SecuritySystem/SecuritySystemDataModels/Models/IMessageInfoModel.cs diff --git a/SecuritySystem/SecuritySystemDataModels/Models/IMessageInfoModel.cs b/SecuritySystem/SecuritySystemDataModels/Models/IMessageInfoModel.cs new file mode 100644 index 0000000..35682f7 --- /dev/null +++ b/SecuritySystem/SecuritySystemDataModels/Models/IMessageInfoModel.cs @@ -0,0 +1,12 @@ +namespace SecuritySystemDataModels.Models +{ + public interface IMessageInfoModel + { + string MessageId { get; } + int? ClientId { get; } + string SenderName { get; } + DateTime DateDelivery { get; } + string Subject { get; } + string Body { get; } + } +} -- 2.25.1 From b92ffdc4419883c6d3039e7eade6e22608c1877a Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 12:43:15 +0400 Subject: [PATCH 02/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B1=D0=B8=D0=BD=D0=B4=D0=B8=D0=BD=D0=B3=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D0=BF=D0=B8=D1=81=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/MessageInfoBindingModel.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 SecuritySystem/SecuritySystemContracts/BindingModels/MessageInfoBindingModel.cs diff --git a/SecuritySystem/SecuritySystemContracts/BindingModels/MessageInfoBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/MessageInfoBindingModel.cs new file mode 100644 index 0000000..d251a33 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/MessageInfoBindingModel.cs @@ -0,0 +1,14 @@ +using SecuritySystemDataModels.Models; + +namespace SecuritySystemContracts.BindingModels +{ + public class MessageInfoBindingModel : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + public int? ClientId { get; set; } = null; + public string SenderName { get; set; } = string.Empty; + public DateTime DateDelivery { get; set; } = DateTime.Now; + public string Subject { get; set; } = string.Empty; + public string Body { get; set; } = string.Empty; + } +} -- 2.25.1 From 07883d676971e1be5cfceffe1b39a9693d21cefa Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 12:50:52 +0400 Subject: [PATCH 03/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20view=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D1=8C=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/MessageInfoViewModel.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 SecuritySystem/SecuritySystemContracts/ViewModels/MessageInfoViewModel.cs diff --git a/SecuritySystem/SecuritySystemContracts/ViewModels/MessageInfoViewModel.cs b/SecuritySystem/SecuritySystemContracts/ViewModels/MessageInfoViewModel.cs new file mode 100644 index 0000000..0d5d25f --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/ViewModels/MessageInfoViewModel.cs @@ -0,0 +1,20 @@ +using SecuritySystemDataModels.Models; +using System.ComponentModel; + +namespace SecuritySystemContracts.ViewModels +{ + public class MessageInfoViewModel : IMessageInfoModel + { + [DisplayName("Идентификатор")] + public string MessageId { get; set; } = string.Empty; + public int? ClientId { get; set; } = null; + [DisplayName("Отправитель")] + public string SenderName { get; set; } = string.Empty; + [DisplayName("Дата получения")] + public DateTime DateDelivery { get; set; } = DateTime.Now; + [DisplayName("Тема")] + public string Subject { get; set; } = string.Empty; + [DisplayName("Текст")] + public string Body { get; set; } = string.Empty; + } +} -- 2.25.1 From 7a7ff677a3f9abb986459243c698d8813796aa1f Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 12:57:21 +0400 Subject: [PATCH 04/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20search=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D1=8C=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SearchModels/MessageInfoSearchModel.cs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 SecuritySystem/SecuritySystemContracts/SearchModels/MessageInfoSearchModel.cs diff --git a/SecuritySystem/SecuritySystemContracts/SearchModels/MessageInfoSearchModel.cs b/SecuritySystem/SecuritySystemContracts/SearchModels/MessageInfoSearchModel.cs new file mode 100644 index 0000000..187e2f8 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/SearchModels/MessageInfoSearchModel.cs @@ -0,0 +1,8 @@ +namespace SecuritySystemContracts.SearchModels +{ + public class MessageInfoSearchModel + { + public string? MessageId { get; set; } + public int? ClientId { get; set; } + } +} -- 2.25.1 From 08c1677432e3f1f6194ded5f66b9ca2cb717413d Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 12:57:34 +0400 Subject: [PATCH 05/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=20=D0=BF=D0=B8=D1=81=D1=8C=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogicsContracts/IMessageInfoLogic.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IMessageInfoLogic.cs diff --git a/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IMessageInfoLogic.cs new file mode 100644 index 0000000..7a8e336 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BusinessLogicsContracts/IMessageInfoLogic.cs @@ -0,0 +1,13 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.BusinessLogicsContracts +{ + public interface IMessageInfoLogic + { + List? ReadList(MessageInfoSearchModel? model); + bool Create(MessageInfoBindingModel model); + } + +} -- 2.25.1 From dbc3979d0c5eddb019b76b7bbbafb2fc2c58e5b8 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 12:58:32 +0400 Subject: [PATCH 06/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B8=D1=81=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StoragesContracts/IMessageInfoStorage.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 SecuritySystem/SecuritySystemContracts/StoragesContracts/IMessageInfoStorage.cs diff --git a/SecuritySystem/SecuritySystemContracts/StoragesContracts/IMessageInfoStorage.cs b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IMessageInfoStorage.cs new file mode 100644 index 0000000..b23fa28 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/StoragesContracts/IMessageInfoStorage.cs @@ -0,0 +1,14 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemContracts.StoragesContracts +{ + public interface IMessageInfoStorage + { + List GetFullList(); + List GetFilteredList(MessageInfoSearchModel model); + MessageInfoViewModel? GetElement(MessageInfoSearchModel model); + MessageInfoViewModel? Insert(MessageInfoBindingModel model); + } +} -- 2.25.1 From ae4d111f326b4c0eadc84be4c123984ce5334881 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 13:28:14 +0400 Subject: [PATCH 07/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=B8=D1=81=D0=B5=D0=BC=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataListSingleton.cs | 2 + .../Implements/MessageInfoStorage.cs | 45 +++++++++++++++ .../Models/MessageInfo.cs | 55 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs create mode 100644 SecuritySystem/SecuritySystemListImplement/Models/MessageInfo.cs diff --git a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs index ad69514..bcb42c0 100644 --- a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs +++ b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs @@ -10,6 +10,7 @@ namespace SecuritySystemListImplement public List Secures { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List MessageInfos { get; set; } private DataListSingleton() { Components = new List(); @@ -17,6 +18,7 @@ namespace SecuritySystemListImplement Secures = new List(); Clients = new List(); Implementers = new List(); + MessageInfos = new List(); } public static DataListSingleton GetInstance() { diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..2f68309 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,45 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + public MessageInfoStorage(DataListSingleton source) + { + _source = source; + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + return GetFilteredList(model).FirstOrDefault(); + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + var messageInfos = GetFullList(); + if (!string.IsNullOrEmpty(model.MessageId)) + { + messageInfos = messageInfos.Where(x => x.MessageId == model.MessageId).ToList(); + } + if (model.ClientId != null) + { + messageInfos = messageInfos.Where(x => x.ClientId == model.ClientId).ToList(); + } + return messageInfos; + } + + public List GetFullList() + { + return _source.MessageInfos.Select(x => x.GetViewModel).ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/SecuritySystem/SecuritySystemListImplement/Models/MessageInfo.cs b/SecuritySystem/SecuritySystemListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..5d92b57 --- /dev/null +++ b/SecuritySystem/SecuritySystemListImplement/Models/MessageInfo.cs @@ -0,0 +1,55 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using System.Reflection; + +namespace SecuritySystemListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + public int? ClientId { get; set; } + public string SenderName { get; set; } = string.Empty; + public DateTime DateDelivery { get; set; } = DateTime.Now; + public string Subject { get; set; } = string.Empty; + public string Body { get; set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel? model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body, + }; + } + public void Update(MessageInfoBindingModel? model) + { + if (model == null) + { + return; + } + ClientId = model.ClientId; + SenderName = model.SenderName; + DateDelivery = model.DateDelivery; + Subject = model.Subject; + Body = model.Body; + } + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body, + }; + } +} -- 2.25.1 From 3ee55e1fd7a43c8fdc6e6e9f16a97f7ee5c198cf Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 13:28:33 +0400 Subject: [PATCH 08/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D1=80=D0=B5=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20=D0=B1=D0=B8=D0=B7?= =?UTF-8?q?=D0=BD=D0=B5=D1=81=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/MessageInfoLogic.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs new file mode 100644 index 0000000..37ed57a --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -0,0 +1,20 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.ViewModels; + +namespace SecuritySystemBusinessLogic.BusinessLogics +{ + public class MessageInfoLogic : IMessageInfoLogic + { + public bool Create(MessageInfoBindingModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(MessageInfoSearchModel? model) + { + throw new NotImplementedException(); + } + } +} -- 2.25.1 From bc20162bb991b378de2f90d4fad3b7aba695a46b Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 13:34:40 +0400 Subject: [PATCH 09/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/MessageInfoLogic.cs | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 37ed57a..297ba25 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -1,20 +1,69 @@ -using SecuritySystemContracts.BindingModels; +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.ViewModels; namespace SecuritySystemBusinessLogic.BusinessLogics { public class MessageInfoLogic : IMessageInfoLogic { + private readonly ILogger _logger; + private readonly IMessageInfoStorage _messageInfoStorage; + public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage) + { + _logger = logger; + _messageInfoStorage = messageInfoStorage; + } + public bool Create(MessageInfoBindingModel model) { - throw new NotImplementedException(); + CheckModel(model); + if (_messageInfoStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } public List? ReadList(MessageInfoSearchModel? model) { - throw new NotImplementedException(); + _logger.LogInformation("ReadList. MessageId:{Id}", model?.MessageId); + var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(MessageInfoBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.MessageId)) + { + throw new ArgumentNullException("Нет идентификатора письма", nameof(model.MessageId)); + } + _logger.LogInformation("MessageInfo. MessageId: {MessageId}", model.MessageId); + var element = _messageInfoStorage.GetElement(new MessageInfoSearchModel + { + MessageId = model.MessageId + }); + if (element != null) + { + throw new InvalidOperationException("Пиьсмо с таким идентификатором уже есть"); + } } } } -- 2.25.1 From 8da9d8b59c3e0e647e2822e7aa97a976eada2113 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 14:34:26 +0400 Subject: [PATCH 10/26] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=84=D1=83?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=B8=D1=81=D1=8C=D0=BC=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=BF?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/MessageInfoStorage.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs index 2f68309..7b7a253 100644 --- a/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs +++ b/SecuritySystem/SecuritySystemListImplement/Implements/MessageInfoStorage.cs @@ -2,6 +2,7 @@ using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.ViewModels; +using SecuritySystemListImplement.Models; namespace SecuritySystemListImplement.Implements { @@ -39,7 +40,13 @@ namespace SecuritySystemListImplement.Implements public MessageInfoViewModel? Insert(MessageInfoBindingModel model) { - throw new NotImplementedException(); + var messageInfo = MessageInfo.Create(model); + if (messageInfo == null) + { + return null; + } + _source.MessageInfos.Add(messageInfo); + return messageInfo.GetViewModel; } } } -- 2.25.1 From 4d9d154821ae43b83a598c613b0e8fd2812fde93 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 14:36:48 +0400 Subject: [PATCH 11/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=B8=D1=81=D0=B5=D0=BC=20=D0=B2=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataFileSingleton.cs | 4 + .../Implements/MessageInfoStorage.cs | 53 ++++++++++++ .../Models/MessageInfo.cs | 81 +++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 SecuritySystem/SecuritySystemFileImplement/Implements/MessageInfoStorage.cs create mode 100644 SecuritySystem/SecuritySystemFileImplement/Models/MessageInfo.cs diff --git a/SecuritySystem/SecuritySystemFileImplement/DataFileSingleton.cs b/SecuritySystem/SecuritySystemFileImplement/DataFileSingleton.cs index fb52862..435e39b 100644 --- a/SecuritySystem/SecuritySystemFileImplement/DataFileSingleton.cs +++ b/SecuritySystem/SecuritySystemFileImplement/DataFileSingleton.cs @@ -11,11 +11,13 @@ namespace SecuritySystemFileImplement private readonly string SecureFileName = "Secure.xml"; private readonly string ClientFileName = "Client.xml"; private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessageInfoFileName = "MessageInfo.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Secures { get; private set; } public List Clients { get; private set; } public List Implementers { get; private set; } + public List MessageInfos { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -29,6 +31,7 @@ namespace SecuritySystemFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + public void SaveMessageInfos() => SaveData(MessageInfos, MessageInfoFileName, "MessageInfos", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; @@ -36,6 +39,7 @@ namespace SecuritySystemFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + MessageInfos = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/SecuritySystem/SecuritySystemFileImplement/Implements/MessageInfoStorage.cs b/SecuritySystem/SecuritySystemFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..e262bcf --- /dev/null +++ b/SecuritySystem/SecuritySystemFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,53 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemFileImplement.Models; + +namespace SecuritySystemFileImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private DataFileSingleton _source; + public MessageInfoStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + return GetFilteredList(model).FirstOrDefault(); + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + var messageInfos = GetFullList(); + if (!string.IsNullOrEmpty(model.MessageId)) + { + messageInfos = messageInfos.Where(x => x.MessageId == model.MessageId).ToList(); + } + if (model.ClientId != null) + { + messageInfos = messageInfos.Where(x => x.ClientId == model.ClientId).ToList(); + } + return messageInfos; + } + + public List GetFullList() + { + return _source.MessageInfos.Select(x => x.GetViewModel).ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var messageInfo = MessageInfo.Create(model); + if (messageInfo == null) + { + return null; + } + _source.MessageInfos.Add(messageInfo); + _source.SaveMessageInfos(); + return messageInfo.GetViewModel; + } + } +} diff --git a/SecuritySystem/SecuritySystemFileImplement/Models/MessageInfo.cs b/SecuritySystem/SecuritySystemFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..f04fe0d --- /dev/null +++ b/SecuritySystem/SecuritySystemFileImplement/Models/MessageInfo.cs @@ -0,0 +1,81 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using System.Reflection; +using System.Xml.Linq; + +namespace SecuritySystemFileImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; set; } = string.Empty; + public int? ClientId { get; set; } + public string SenderName { get; set; } = string.Empty; + public DateTime DateDelivery { get; set; } = DateTime.Now; + public string Subject { get; set; } = string.Empty; + public string Body { get; set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body, + }; + } + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + return new MessageInfo() + { + MessageId = element.Attribute("MessageId")!.Value, + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + SenderName = element.Element("SenderName")!.Value, + DateDelivery = Convert.ToDateTime(element.Element("DateDelivery")!.Value), + Subject = element.Element("Subject")!.Value, + Body = element.Element("Body")!.Value, + }; + } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + MessageId = model.MessageId; + ClientId = model.ClientId; + SenderName = model.SenderName; + DateDelivery = model.DateDelivery; + Subject = model.Subject; + Body = model.Body; + } + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body, + }; + public XElement GetXElement => new("MessageInfo", + new XAttribute("MessageId", MessageId), + new XElement("ClientId", ClientId.ToString()), + new XElement("SenderName", SenderName), + new XElement("DateDelivery", DateDelivery.ToString()), + new XElement("Subject", Subject), + new XElement("Body", Body) + ); + } +} -- 2.25.1 From f3d1de0db8191c12aa9773cd7ec4bca78b12d0f6 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 14:48:06 +0400 Subject: [PATCH 12/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=B8=D1=81=D0=B5=D0=BC=20=D0=B2=20=D0=91?= =?UTF-8?q?=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/MessageInfoStorage.cs | 50 +++++++++++++ .../Models/MessageInfo.cs | 75 +++++++++++++++++++ .../SecuritySystemDatabase.cs | 1 + 3 files changed, 126 insertions(+) create mode 100644 SecuritySystem/SecuritySystemDatabaseImplement/Implements/MessageInfoStorage.cs create mode 100644 SecuritySystem/SecuritySystemDatabaseImplement/Models/MessageInfo.cs diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Implements/MessageInfoStorage.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..051af28 --- /dev/null +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,50 @@ +using Microsoft.EntityFrameworkCore; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.SearchModels; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDatabaseImplement.Models; + +namespace SecuritySystemDatabaseImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + return GetFilteredList(model).FirstOrDefault(); + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + var messageInfos = GetFullList(); + if (!string.IsNullOrEmpty(model.MessageId)) + { + messageInfos = messageInfos.Where(x => x.MessageId == model.MessageId).ToList(); + } + if (model.ClientId != null) + { + messageInfos = messageInfos.Where(x => x.ClientId == model.ClientId).ToList(); + } + return messageInfos; + } + + public List GetFullList() + { + using var context = new SecuritySystemDatabase(); + return context.MessageInfos.Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var messageInfo = MessageInfo.Create(model); + if (messageInfo == null) + { + return null; + } + using var context = new SecuritySystemDatabase(); + context.MessageInfos.Add(messageInfo); + context.SaveChanges(); + return messageInfo.GetViewModel; + } + } +} diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Models/MessageInfo.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..3ebba42 --- /dev/null +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Models/MessageInfo.cs @@ -0,0 +1,75 @@ +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.MessageInfoModel.DataAnnotations.Schema; + +namespace SecuritySystemDatabaseImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + [Required] + public string MessageId { get; set; } = string.Empty; + public int? ClientId { get; set; } + public virtual Client? Client { get; set; } + [Required] + public string SenderName { get; set; } = string.Empty; + [Required] + public DateTime DateDelivery { get; set; } = DateTime.Now; + [Required] + public string Subject { get; set; } = string.Empty; + [Required] + public string Body { get; set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new MessageInfo() + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body, + }; + } + public static MessageInfo Create(MessageInfoViewModel model) + { + return new MessageInfo + { + MessageId = model.MessageId, + ClientId = model.ClientId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + Subject = model.Subject, + Body = model.Body, + }; + } + public void Update(MessageInfoBindingModel model) + { + if (model == null) + { + return; + } + MessageId = model.MessageId; + ClientId = model.ClientId; + SenderName = model.SenderName; + DateDelivery = model.DateDelivery; + Subject = model.Subject; + Body = model.Body; + } + public MessageInfoViewModel GetViewModel => new() + { + MessageId = MessageId, + ClientId = ClientId, + SenderName = SenderName, + DateDelivery = DateDelivery, + Subject = Subject, + Body = Body, + }; + } +} diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/SecuritySystemDatabase.cs b/SecuritySystem/SecuritySystemDatabaseImplement/SecuritySystemDatabase.cs index fc7c55b..7a74eae 100644 --- a/SecuritySystem/SecuritySystemDatabaseImplement/SecuritySystemDatabase.cs +++ b/SecuritySystem/SecuritySystemDatabaseImplement/SecuritySystemDatabase.cs @@ -21,6 +21,7 @@ namespace SecuritySystemDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } public virtual DbSet Implementers { set; get; } + public virtual DbSet MessageInfos { set; get; } } } -- 2.25.1 From ee3f0bf026d950039f3630d40140da561660ee1b Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 14:49:17 +0400 Subject: [PATCH 13/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B5=D0=BC=20=D0=B2=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B2=20?= =?UTF-8?q?=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SecuritySystem/SecuritySystemDatabaseImplement/Models/Client.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Models/Client.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Models/Client.cs index 390d53c..25376a2 100644 --- a/SecuritySystem/SecuritySystemDatabaseImplement/Models/Client.cs +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Models/Client.cs @@ -17,6 +17,8 @@ namespace SecuritySystemDatabaseImplement.Models public string Password { get; private set; } = string.Empty; [ForeignKey("ClientId")] public virtual List Orders { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List MessageInfos { get; set; } = new(); public static Client? Create(ClientBindingModel model) { if (model == null) -- 2.25.1 From 11cb3e0b57dc4b64fd7b75b4baa1207d51694081 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 14:54:55 +0400 Subject: [PATCH 14/26] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D0=91?= =?UTF-8?q?=D0=94=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=B8=D1=81=D1=8C=D0=BC?= =?UTF-8?q?=D0=B0,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=B2=20PK,=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=20=D0=BC=D0=B8=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0505105357_AddMessageInfoModel.Designer.cs | 298 ++++++++++++++++++ .../20240505105357_AddMessageInfoModel.cs | 48 +++ .../SecuritySystemDatabaseModelSnapshot.cs | 41 +++ .../Models/MessageInfo.cs | 6 +- 4 files changed, 390 insertions(+), 3 deletions(-) create mode 100644 SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240505105357_AddMessageInfoModel.Designer.cs create mode 100644 SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240505105357_AddMessageInfoModel.cs diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240505105357_AddMessageInfoModel.Designer.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240505105357_AddMessageInfoModel.Designer.cs new file mode 100644 index 0000000..b0e9fb9 --- /dev/null +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240505105357_AddMessageInfoModel.Designer.cs @@ -0,0 +1,298 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SecuritySystemDatabaseImplement; + +#nullable disable + +namespace SecuritySystemDatabaseImplement.Migrations +{ + [DbContext(typeof(SecuritySystemDatabase))] + [Migration("20240505105357_AddMessageInfoModel")] + partial class AddMessageInfoModel + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.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("SecuritySystemDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("SecureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("SecureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SecureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Secures"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("SecureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("SecureId"); + + b.ToTable("SecureComponents"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client") + .WithMany("MessageInfos") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b => + { + b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SecuritySystemDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure") + .WithMany("Orders") + .HasForeignKey("SecureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Secure"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.SecureComponent", b => + { + b.HasOne("SecuritySystemDatabaseImplement.Models.Component", "Component") + .WithMany("SecureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SecuritySystemDatabaseImplement.Models.Secure", "Secure") + .WithMany("Components") + .HasForeignKey("SecureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Secure"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b => + { + b.Navigation("MessageInfos"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Component", b => + { + b.Navigation("SecureComponents"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Secure", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240505105357_AddMessageInfoModel.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240505105357_AddMessageInfoModel.cs new file mode 100644 index 0000000..f74611f --- /dev/null +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/20240505105357_AddMessageInfoModel.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SecuritySystemDatabaseImplement.Migrations +{ + /// + public partial class AddMessageInfoModel : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + 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.CreateIndex( + name: "IX_MessageInfos_ClientId", + table: "MessageInfos", + column: "ClientId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "MessageInfos"); + } + } +} diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/SecuritySystemDatabaseModelSnapshot.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/SecuritySystemDatabaseModelSnapshot.cs index fea8e22..f47d526 100644 --- a/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/SecuritySystemDatabaseModelSnapshot.cs +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Migrations/SecuritySystemDatabaseModelSnapshot.cs @@ -94,6 +94,36 @@ namespace SecuritySystemDatabaseImplement.Migrations b.ToTable("Implementers"); }); + modelBuilder.Entity("SecuritySystemDatabaseImplement.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("SecuritySystemDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -183,6 +213,15 @@ namespace SecuritySystemDatabaseImplement.Migrations b.ToTable("SecureComponents"); }); + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.MessageInfo", b => + { + b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client") + .WithMany("MessageInfos") + .HasForeignKey("ClientId"); + + b.Navigation("Client"); + }); + modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Order", b => { b.HasOne("SecuritySystemDatabaseImplement.Models.Client", "Client") @@ -229,6 +268,8 @@ namespace SecuritySystemDatabaseImplement.Migrations modelBuilder.Entity("SecuritySystemDatabaseImplement.Models.Client", b => { + b.Navigation("MessageInfos"); + b.Navigation("Orders"); }); diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Models/MessageInfo.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Models/MessageInfo.cs index 3ebba42..c8564cc 100644 --- a/SecuritySystem/SecuritySystemDatabaseImplement/Models/MessageInfo.cs +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Models/MessageInfo.cs @@ -1,14 +1,14 @@ -using SecuritySystemContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.ViewModels; using SecuritySystemDataModels.Models; using System.ComponentModel.DataAnnotations; -using System.MessageInfoModel.DataAnnotations.Schema; namespace SecuritySystemDatabaseImplement.Models { + [PrimaryKey("MessageId")] public class MessageInfo : IMessageInfoModel { - [Required] public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } public virtual Client? Client { get; set; } -- 2.25.1 From 61641fcfdf6c3194255dd4029bf3054335b205d6 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 17:40:26 +0400 Subject: [PATCH 15/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D1=87=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MailWorker/AbstractMailWorker.cs | 74 ++++++++++++++++++ .../MailWorker/MailKitWorker.cs | 75 +++++++++++++++++++ .../SecuritySystemBusinessLogic.csproj | 1 + .../BindingModels/MailConfigBindingModel.cs | 12 +++ .../BindingModels/MailSendInfoBindingModel.cs | 9 +++ 5 files changed, 171 insertions(+) create mode 100644 SecuritySystem/SecuritySystemBusinessLogic/MailWorker/AbstractMailWorker.cs create mode 100644 SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs create mode 100644 SecuritySystem/SecuritySystemContracts/BindingModels/MailConfigBindingModel.cs create mode 100644 SecuritySystem/SecuritySystemContracts/BindingModels/MailSendInfoBindingModel.cs diff --git a/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/AbstractMailWorker.cs b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/AbstractMailWorker.cs new file mode 100644 index 0000000..a6d55d8 --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -0,0 +1,74 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemBusinessLogic.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 IMessageInfoLogic _messageInfoLogic; + private readonly ILogger _logger; + public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) + { + _logger = logger; + _messageInfoLogic = messageInfoLogic; + } + 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); + } + public async void MailCheck() + { + if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) + { + return; + } + if (string.IsNullOrEmpty(_popHost) || _popPort == 0) + { + return; + } + if (_messageInfoLogic == null) + { + return; + } + var list = await ReceiveMailAsync(); + _logger.LogDebug("Check Mail: {Count} new mails", list.Count); + foreach (var mail in list) + { + _messageInfoLogic.Create(mail); + } + } + protected abstract Task SendMailAsync(MailSendInfoBindingModel info); + protected abstract Task> ReceiveMailAsync(); + } + +} diff --git a/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs new file mode 100644 index 0000000..d4aae94 --- /dev/null +++ b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs @@ -0,0 +1,75 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using System.Net.Mail; +using System.Net; +using System.Text; +using MailKit.Net.Pop3; +using MailKit.Security; + +namespace SecuritySystemBusinessLogic.MailWorker +{ + public class MailKitWorker : AbstractMailWorker + { + public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic) { } + 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; + 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; + } + } + protected override async Task> ReceiveMailAsync() + { + var list = new List(); + using var client = new Pop3Client(); + await Task.Run(() => + { + try + { + client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect); + client.Authenticate(_mailLogin, _mailPassword); + for (int i = 0; i < client.Count; i++) + { + var message = client.GetMessage(i); + foreach (var mail in message.From.Mailboxes) + { + list.Add(new MessageInfoBindingModel + { + DateDelivery = message.Date.DateTime, + MessageId = message.MessageId, + SenderName = mail.Address, + Subject = message.Subject, + Body = message.TextBody + }); + } + } + } + catch (AuthenticationException) + { } + finally + { + client.Disconnect(true); + } + }); + return list; + } + } + +} diff --git a/SecuritySystem/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj b/SecuritySystem/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj index ee23f9b..9667d03 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj +++ b/SecuritySystem/SecuritySystemBusinessLogic/SecuritySystemBusinessLogic.csproj @@ -9,6 +9,7 @@ + diff --git a/SecuritySystem/SecuritySystemContracts/BindingModels/MailConfigBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/MailConfigBindingModel.cs new file mode 100644 index 0000000..6271d3b --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/MailConfigBindingModel.cs @@ -0,0 +1,12 @@ +namespace SecuritySystemContracts.BindingModels +{ + public class MailConfigBindingModel + { + public string MailLogin { get; set; } = string.Empty; + public string MailPassword { get; set; } = string.Empty; + public string SmtpClientHost { get; set; } = string.Empty; + public int SmtpClientPort { get; set; } + public string PopHost { get; set; } = string.Empty; + public int PopPort { get; set; } + } +} diff --git a/SecuritySystem/SecuritySystemContracts/BindingModels/MailSendInfoBindingModel.cs b/SecuritySystem/SecuritySystemContracts/BindingModels/MailSendInfoBindingModel.cs new file mode 100644 index 0000000..01bb177 --- /dev/null +++ b/SecuritySystem/SecuritySystemContracts/BindingModels/MailSendInfoBindingModel.cs @@ -0,0 +1,9 @@ +namespace SecuritySystemContracts.BindingModels +{ + public class MailSendInfoBindingModel + { + public string MailAddress { get; set; } = string.Empty; + public string Subject { get; set; } = string.Empty; + public string Text { get; set; } = string.Empty; + } +} -- 2.25.1 From f990cfe4a66fc07a3e2a991e46abf3338e5a7e77 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 18:05:56 +0400 Subject: [PATCH 16/26] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BA=D1=83=20=D0=BF=D0=B8=D1=81=D0=B5=D0=BC=20=D0=B2=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B5=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs index 8993fbd..eb39c92 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using SecuritySystemBusinessLogic.MailWorker; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.SearchModels; @@ -12,12 +13,16 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IClientStorage _clientStorage; static readonly object locker = new object(); + private readonly AbstractMailWorker _abstractMailWorker; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, AbstractMailWorker abstractMailWorker, IClientStorage clientStorage) { _logger = logger; _orderStorage = orderStorage; + _abstractMailWorker = abstractMailWorker; + _clientStorage = clientStorage; } public List? ReadList(OrderSearchModel? model) @@ -49,20 +54,20 @@ namespace SecuritySystemBusinessLogic.BusinessLogics public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (element == null) + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (order == null) { _logger.LogWarning("Read operation failed"); return false; } - if (element.Status != status - 1) + if (order.Status != status - 1) { _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } - if (element.ImplementerId.HasValue) + if (order.ImplementerId.HasValue) { - model.ImplementerId = element.ImplementerId; + model.ImplementerId = order.ImplementerId; } OrderStatus oldStatus = model.Status; model.Status = status; @@ -74,6 +79,11 @@ namespace SecuritySystemBusinessLogic.BusinessLogics _logger.LogWarning("Update operation failed"); return false; } + var orderClient = _clientStorage.GetElement(new ClientSearchModel { Id = order.ClientId }); + if (orderClient != null) + { + SendMail(orderClient, order); + } return true; } @@ -140,5 +150,37 @@ namespace SecuritySystemBusinessLogic.BusinessLogics _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); return element; } + + private void SendMail(ClientViewModel clientView, OrderViewModel orderView) + { + if (clientView == null || orderView == null) + { + return; + } + MailSendInfoBindingModel mailSendInfoBindingModel; + + string subject = $"Заказ #{orderView.Id}"; + string orderInfo = $"Ваш заказ #{orderView.Id} от {orderView.DateCreate} стоимостью {orderView.Sum}"; + + if (orderView.Status == OrderStatus.Принят) + { + mailSendInfoBindingModel = new MailSendInfoBindingModel + { + MailAddress = clientView.Email, + Subject = subject, + Text = orderInfo + " был принят" + }; + } + else + { + mailSendInfoBindingModel = new MailSendInfoBindingModel + { + MailAddress = clientView.Email, + Subject = subject, + Text = orderInfo + $" поменял статус на {orderView.Status}" + }; + } + _abstractMailWorker.MailSendAsync(mailSendInfoBindingModel); + } } } -- 2.25.1 From 55aff66f7b9ac44506a09e26d3bd5dfe0efc1ece Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 19:42:09 +0400 Subject: [PATCH 17/26] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D1=8B=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20?= =?UTF-8?q?=D1=81=20=D0=BF=D0=BE=D1=87=D1=82=D0=BE=D0=B9=20=D0=B2=20=D0=B3?= =?UTF-8?q?=D0=BB=D0=B0=D0=B2=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D1=8B?= =?UTF-8?q?,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=BE?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SecuritySystem/SecuritySystemView/App.config | 11 ++++++++ SecuritySystem/SecuritySystemView/Program.cs | 29 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 SecuritySystem/SecuritySystemView/App.config diff --git a/SecuritySystem/SecuritySystemView/App.config b/SecuritySystem/SecuritySystemView/App.config new file mode 100644 index 0000000..f7dfd6a --- /dev/null +++ b/SecuritySystem/SecuritySystemView/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs index 37b30ec..2568ba5 100644 --- a/SecuritySystem/SecuritySystemView/Program.cs +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -2,8 +2,10 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using SecuritySystemBusinessLogic.BusinessLogics; +using SecuritySystemBusinessLogic.MailWorker; using SecuritySystemBusinessLogic.OfficePackage; using SecuritySystemBusinessLogic.OfficePackage.Implements; +using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.StoragesContracts; using SecuritySystemDatabaseImplement.Implements; @@ -29,6 +31,28 @@ namespace SecuritySystemView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); + + try + { + var mailSender = _serviceProvider.GetService(); + mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, + MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, + SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]), + PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) + }); + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + } + catch (Exception ex) + { + var logger = _serviceProvider.GetService(); + logger?.LogError(ex, " "); + } + + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) @@ -43,16 +67,19 @@ namespace SecuritySystemView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -65,6 +92,8 @@ namespace SecuritySystemView services.AddTransient(); services.AddTransient(); services.AddTransient(); + //services.AddTransient(); } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file -- 2.25.1 From d6b3ec7b0305f16442116f3cbb282f0afc718e5f Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 20:50:11 +0400 Subject: [PATCH 18/26] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BA=D0=B8=20=D0=BF=D0=BE=D1=87=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/MessageInfoLogic.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 297ba25..c4b52ef 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -11,7 +11,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IMessageInfoStorage _messageInfoStorage; - public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage) + public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage) { _logger = logger; _messageInfoStorage = messageInfoStorage; @@ -51,10 +51,6 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { return; } - if (string.IsNullOrEmpty(model.MessageId)) - { - throw new ArgumentNullException("Нет идентификатора письма", nameof(model.MessageId)); - } _logger.LogInformation("MessageInfo. MessageId: {MessageId}", model.MessageId); var element = _messageInfoStorage.GetElement(new MessageInfoSearchModel { -- 2.25.1 From 0b2f2fa6aa0339c7dd3dedc01476c16dc112bb15 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 20:50:26 +0400 Subject: [PATCH 19/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SecuritySystem/SecuritySystemView/App.config | 10 +- .../SecuritySystemView/FormMain.Designer.cs | 11 +- SecuritySystem/SecuritySystemView/FormMain.cs | 10 ++ .../Mail/FormMails.Designer.cs | 66 ++++++++++ .../SecuritySystemView/Mail/FormMails.cs | 42 ++++++ .../SecuritySystemView/Mail/FormMails.resx | 120 ++++++++++++++++++ SecuritySystem/SecuritySystemView/Program.cs | 3 +- 7 files changed, 255 insertions(+), 7 deletions(-) create mode 100644 SecuritySystem/SecuritySystemView/Mail/FormMails.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/Mail/FormMails.cs create mode 100644 SecuritySystem/SecuritySystemView/Mail/FormMails.resx diff --git a/SecuritySystem/SecuritySystemView/App.config b/SecuritySystem/SecuritySystemView/App.config index f7dfd6a..ef81e19 100644 --- a/SecuritySystem/SecuritySystemView/App.config +++ b/SecuritySystem/SecuritySystemView/App.config @@ -1,11 +1,11 @@  - - - + + + - - + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormMain.Designer.cs b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs index 0845fe2..99c1116 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.Designer.cs +++ b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs @@ -43,6 +43,7 @@ buttonCreateOrder = new Button(); button4 = new Button(); buttonRefresh = new Button(); + почтаToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -50,7 +51,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, почтаToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1043, 28); @@ -174,6 +175,13 @@ buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRefresh_Click; // + // почтаToolStripMenuItem + // + почтаToolStripMenuItem.Name = "почтаToolStripMenuItem"; + почтаToolStripMenuItem.Size = new Size(65, 24); + почтаToolStripMenuItem.Text = "Почта"; + почтаToolStripMenuItem.Click += MailsToolStripMenuItem_Click; + // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); @@ -212,5 +220,6 @@ private ToolStripMenuItem клиентыToolStripMenuItem; private ToolStripMenuItem исполнителиToolStripMenuItem; private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem почтаToolStripMenuItem; } } \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormMain.cs b/SecuritySystem/SecuritySystemView/FormMain.cs index b9a58bf..4e7bc1a 100644 --- a/SecuritySystem/SecuritySystemView/FormMain.cs +++ b/SecuritySystem/SecuritySystemView/FormMain.cs @@ -3,6 +3,7 @@ using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemView.Client; using SecuritySystemView.Implementer; +using SecuritySystemView.Mail; using SecuritySystemView.Report; namespace SecuritySystemView @@ -213,5 +214,14 @@ namespace SecuritySystemView _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } + + private void MailsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMails)); + if (service is FormMails form) + { + form.ShowDialog(); + } + } } } diff --git a/SecuritySystem/SecuritySystemView/Mail/FormMails.Designer.cs b/SecuritySystem/SecuritySystemView/Mail/FormMails.Designer.cs new file mode 100644 index 0000000..b83ec9b --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Mail/FormMails.Designer.cs @@ -0,0 +1,66 @@ +namespace SecuritySystemView.Mail +{ + partial class FormMails + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(800, 450); + dataGridView.TabIndex = 0; + // + // FormMails + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormMails"; + Text = "Почта"; + Load += FormMails_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Mail/FormMails.cs b/SecuritySystem/SecuritySystemView/Mail/FormMails.cs new file mode 100644 index 0000000..d211c93 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Mail/FormMails.cs @@ -0,0 +1,42 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView.Mail +{ + public partial class FormMails : Form + { + private readonly ILogger _logger; + private readonly IMessageInfoLogic _logic; + public FormMails(ILogger logger, IMessageInfoLogic messageInfoLogic) + { + InitializeComponent(); + _logger = logger; + _logic = messageInfoLogic; + } + + private void FormMails_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["MessageId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + } + _logger.LogInformation("Загрузка почты"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки почты"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } +} diff --git a/SecuritySystem/SecuritySystemView/Mail/FormMails.resx b/SecuritySystem/SecuritySystemView/Mail/FormMails.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/Mail/FormMails.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs index 2568ba5..1245f95 100644 --- a/SecuritySystem/SecuritySystemView/Program.cs +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -11,6 +11,7 @@ using SecuritySystemContracts.StoragesContracts; using SecuritySystemDatabaseImplement.Implements; using SecuritySystemView.Client; using SecuritySystemView.Implementer; +using SecuritySystemView.Mail; using SecuritySystemView.Report; namespace SecuritySystemView @@ -92,7 +93,7 @@ namespace SecuritySystemView services.AddTransient(); services.AddTransient(); services.AddTransient(); - //services.AddTransient(); + services.AddTransient(); } private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } -- 2.25.1 From 75604db1a83c5142e12273165e6f69bd7d7e9809 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 22:02:27 +0400 Subject: [PATCH 20/26] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D0=BE=D1=87=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/MessageInfoLogic.cs | 13 +++++++++---- .../MailWorker/MailKitWorker.cs | 5 ++++- SecuritySystem/SecuritySystemView/App.config | 6 +++--- .../Mail/FormMails.Designer.cs | 19 ++++++++++++++++--- .../SecuritySystemView/Mail/FormMails.cs | 5 +++++ SecuritySystem/SecuritySystemView/Program.cs | 2 +- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs index c4b52ef..521597f 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -19,7 +19,10 @@ namespace SecuritySystemBusinessLogic.BusinessLogics public bool Create(MessageInfoBindingModel model) { - CheckModel(model); + if (!CheckModelIsValid(model)) + { + return false; + } if (_messageInfoStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); @@ -41,7 +44,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics return list; } - private void CheckModel(MessageInfoBindingModel model, bool withParams = true) + private bool CheckModelIsValid(MessageInfoBindingModel model, bool withParams = true) { if (model == null) { @@ -49,7 +52,7 @@ namespace SecuritySystemBusinessLogic.BusinessLogics } if (!withParams) { - return; + return true; } _logger.LogInformation("MessageInfo. MessageId: {MessageId}", model.MessageId); var element = _messageInfoStorage.GetElement(new MessageInfoSearchModel @@ -58,8 +61,10 @@ namespace SecuritySystemBusinessLogic.BusinessLogics }); if (element != null) { - throw new InvalidOperationException("Пиьсмо с таким идентификатором уже есть"); + _logger.LogDebug("Пиьсмо с таким идентификатором уже есть"); + return false; } + return true; } } } diff --git a/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs index d4aae94..d14f0d3 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs @@ -6,6 +6,7 @@ using System.Net; using System.Text; using MailKit.Net.Pop3; using MailKit.Security; +using System.Text.RegularExpressions; namespace SecuritySystemBusinessLogic.MailWorker { @@ -38,6 +39,8 @@ namespace SecuritySystemBusinessLogic.MailWorker protected override async Task> ReceiveMailAsync() { var list = new List(); + string regexpPattern = "(\\<(/?[^>]+)>)"; + Regex regexp = new Regex(regexpPattern); using var client = new Pop3Client(); await Task.Run(() => { @@ -56,7 +59,7 @@ namespace SecuritySystemBusinessLogic.MailWorker MessageId = message.MessageId, SenderName = mail.Address, Subject = message.Subject, - Body = message.TextBody + Body = regexp.Replace(message.HtmlBody, "") }); } } diff --git a/SecuritySystem/SecuritySystemView/App.config b/SecuritySystem/SecuritySystemView/App.config index ef81e19..7bf7a34 100644 --- a/SecuritySystem/SecuritySystemView/App.config +++ b/SecuritySystem/SecuritySystemView/App.config @@ -2,10 +2,10 @@ - + - - + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Mail/FormMails.Designer.cs b/SecuritySystem/SecuritySystemView/Mail/FormMails.Designer.cs index b83ec9b..17b5ef1 100644 --- a/SecuritySystem/SecuritySystemView/Mail/FormMails.Designer.cs +++ b/SecuritySystem/SecuritySystemView/Mail/FormMails.Designer.cs @@ -29,28 +29,40 @@ private void InitializeComponent() { dataGridView = new DataGridView(); + buttonRefresh = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // dataGridView // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Dock = DockStyle.Fill; - dataGridView.Location = new Point(0, 0); + dataGridView.Location = new Point(0, 42); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(800, 450); + dataGridView.Size = new Size(800, 408); dataGridView.TabIndex = 0; // + // buttonRefresh + // + buttonRefresh.Location = new Point(12, 7); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 1; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // // FormMails // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); Controls.Add(dataGridView); Name = "FormMails"; Text = "Почта"; @@ -62,5 +74,6 @@ #endregion private DataGridView dataGridView; + private Button buttonRefresh; } } \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Mail/FormMails.cs b/SecuritySystem/SecuritySystemView/Mail/FormMails.cs index d211c93..f31cab7 100644 --- a/SecuritySystem/SecuritySystemView/Mail/FormMails.cs +++ b/SecuritySystem/SecuritySystemView/Mail/FormMails.cs @@ -38,5 +38,10 @@ namespace SecuritySystemView.Mail MessageBoxIcon.Error); } } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } } } diff --git a/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs index 1245f95..4e6e102 100644 --- a/SecuritySystem/SecuritySystemView/Program.cs +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -45,7 +45,7 @@ namespace SecuritySystemView PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) }); - var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); + var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 5000); } catch (Exception ex) { -- 2.25.1 From 2e0f9b9bc4960a14f7a97be146783d95abdf3485 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 23:25:46 +0400 Subject: [PATCH 21/26] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B0=20=D0=B7=D0=B0=D0=BA?= =?UTF-8?q?=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/SecuritySystem/SecuritySystemDatabaseImplement/Implements/OrderStorage.cs b/SecuritySystem/SecuritySystemDatabaseImplement/Implements/OrderStorage.cs index e104890..030c07b 100644 --- a/SecuritySystem/SecuritySystemDatabaseImplement/Implements/OrderStorage.cs +++ b/SecuritySystem/SecuritySystemDatabaseImplement/Implements/OrderStorage.cs @@ -11,37 +11,33 @@ namespace SecuritySystemDatabaseImplement.Implements { public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return null; - } return GetFilteredList(model).FirstOrDefault(); } public List GetFilteredList(OrderSearchModel model) { var orders = GetFullList(); - if (model.Id.HasValue) + if (model.Id != null) { orders = orders.Where(x => x.Id == model.Id.Value).ToList(); } - if (model.Status.HasValue) + if (model.Status != null) { orders = orders.Where(x => x.Status == model.Status.Value).ToList(); } - if (model.ImplementerId.HasValue) + if (model.ImplementerId != null) { orders = orders.Where(x => x.ImplementerId == model.ImplementerId.Value).ToList(); } - if (model.DateFrom.HasValue) + if (model.DateFrom != null) { orders = orders.Where(x => x.DateCreate >= model.DateFrom.Value).ToList(); } - if (model.DateTo.HasValue) + if (model.DateTo != null) { orders = orders.Where(x => x.DateCreate <= model.DateTo.Value).ToList(); } - if (model.ClientId.HasValue) + if (model.ClientId != null) { orders = orders.Where(x => x.ClientId == model.ClientId.Value).ToList(); } -- 2.25.1 From f73d555c0e479b24ac1943100d535523555be498 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 23:26:14 +0400 Subject: [PATCH 22/26] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B8=20=D0=BF=D1=80=D0=B8=D0=BD=D1=8F=D1=82=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B5=D0=BC,=20=D0=BE=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=B0=D1=82=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D1=8F=D0=BD=D1=82=D0=B8=D0=B8=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=D0=B0=20=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D1=85=D0=BE=D0=B4=D0=B5=20=D0=B5=D0=B3=D0=BE=20=D1=81=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D1=8F=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 1 + .../Views/Home/Register.cshtml | 2 +- .../BusinessLogics/ClientLogic.cs | 7 +++++++ .../BusinessLogics/OrderLogic.cs | 19 +++++++++++++------ .../MailWorker/MailKitWorker.cs | 1 + .../SecuritySystemRestApi/Program.cs | 4 ++++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs b/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs index 6db61af..5152790 100644 --- a/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs +++ b/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs @@ -3,6 +3,7 @@ using SecurirySystemClientApp.Models; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.ViewModels; using System.Diagnostics; +using System.Text; namespace SecurirySystemClientApp.Controllers { diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml index 10020f6..6e08d01 100644 --- a/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Register.cshtml @@ -6,7 +6,7 @@
-
Логин:
+
Email:
diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs index ada8fcc..dd77745 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs @@ -4,6 +4,7 @@ using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.ViewModels; +using System.Text.RegularExpressions; namespace SecuritySystemBusinessLogic.BusinessLogics { @@ -93,6 +94,12 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет email клиента", nameof(model.Email)); } + string regexepEmailPattern = "^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$"; + Regex regexpEmail = new Regex(regexepEmailPattern); + if (!regexpEmail.IsMatch(model.Email)) + { + throw new ArgumentException("Email не валидный"); + } if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs index eb39c92..f7e5563 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/OrderLogic.cs @@ -42,13 +42,17 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { CheckModel(model); if (model.Status != OrderStatus.Неизвестен) return false; - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) + + var inserted = _orderStorage.Insert(model); + if (inserted == null) { _logger.LogWarning("Insert operation failed"); return false; } - return true; + + model.Id = inserted.Id; + + return ChangeStatus(model, OrderStatus.Принят); } public bool ChangeStatus(OrderBindingModel model, OrderStatus status) @@ -73,16 +77,19 @@ namespace SecuritySystemBusinessLogic.BusinessLogics model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) + + var updatedOrder = _orderStorage.Update(model); + + if (updatedOrder == null) { model.Status = oldStatus; _logger.LogWarning("Update operation failed"); return false; } - var orderClient = _clientStorage.GetElement(new ClientSearchModel { Id = order.ClientId }); + var orderClient = _clientStorage.GetElement(new ClientSearchModel { Id = updatedOrder.ClientId }); if (orderClient != null) { - SendMail(orderClient, order); + SendMail(orderClient, updatedOrder); } return true; } diff --git a/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs index d14f0d3..e4659d6 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs @@ -15,6 +15,7 @@ namespace SecuritySystemBusinessLogic.MailWorker public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic) { } protected override async Task SendMailAsync(MailSendInfoBindingModel info) { + if (info.MailAddress == null) return; using var objMailMessage = new MailMessage(); using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort); try diff --git a/SecuritySystem/SecuritySystemRestApi/Program.cs b/SecuritySystem/SecuritySystemRestApi/Program.cs index 68f2f70..4649aa6 100644 --- a/SecuritySystem/SecuritySystemRestApi/Program.cs +++ b/SecuritySystem/SecuritySystemRestApi/Program.cs @@ -3,6 +3,7 @@ using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.StoragesContracts; using SecuritySystemDatabaseImplement.Implements; using Microsoft.OpenApi.Models; +using SecuritySystemBusinessLogic.MailWorker; var builder = WebApplication.CreateBuilder(args); builder.Logging.SetMinimumLevel(LogLevel.Trace); @@ -12,9 +13,12 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddSingleton(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -- 2.25.1 From 68e7e61991465b49534fe103af2b3c0e6d75a824 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sun, 5 May 2024 23:41:35 +0400 Subject: [PATCH 23/26] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2=20=D0=B2=D0=BE=D1=80?= =?UTF-8?q?=D0=BA=D0=B5=D1=80=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/WorkModeling.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/WorkModeling.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/WorkModeling.cs index a86af2a..5949202 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/WorkModeling.cs @@ -26,10 +26,16 @@ namespace SecuritySystemBusinessLogic.BusinessLogics _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel + var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); + var inWorkOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выполняется }); + if (orders != null && inWorkOrders != null) { - Status = OrderStatus.Принят - }); + orders.AddRange(inWorkOrders); + } + else + { + orders = inWorkOrders; + } if (orders == null || orders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); -- 2.25.1 From daaed01ccd9ba0b18f4d7ccbfe68c323f4624a01 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 6 May 2024 01:13:01 +0400 Subject: [PATCH 24/26] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B2=D0=B5=D0=B1,=20=D0=BD=D0=B5=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D0=BE=D1=82=D0=BE=D0=B1?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BB=D0=B8=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=20=D0=B2=20=D0=B2=D0=B5=D0=B1=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 10 ++ .../Views/Home/Mails.cshtml | 48 +++++++++ .../Views/Home/Mails.cshtml.cs | 12 +++ .../Views/Shared/_Layout.cshtml | 97 ++++++++++--------- SecuritySystem/SecuritySystem.sln | 2 +- .../Controllers/ClientController.cs | 21 +++- .../SecuritySystemRestApi/Program.cs | 14 +++ .../SecuritySystemRestApi/appsettings.json | 8 +- 8 files changed, 161 insertions(+), 51 deletions(-) create mode 100644 SecuritySystem/SecurirySystemClientApp/Views/Home/Mails.cshtml create mode 100644 SecuritySystem/SecurirySystemClientApp/Views/Home/Mails.cshtml.cs diff --git a/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs b/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs index 5152790..54a71aa 100644 --- a/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs +++ b/SecuritySystem/SecurirySystemClientApp/Controllers/HomeController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using SecurirySystemClientApp.Models; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.ViewModels; @@ -134,6 +135,15 @@ namespace SecurirySystemClientApp.Controllers var prod = APIClient.GetRequest($"api/main/getsecure?secureId={secure}"); return count * (prod?.Price ?? 1); } + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + } } } diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Mails.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Home/Mails.cshtml new file mode 100644 index 0000000..35033f9 --- /dev/null +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Mails.cshtml @@ -0,0 +1,48 @@ +@using SecuritySystemContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Почта"; +} +
+

Письма

+
+
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Дата письма + + Заголовок + + Текст +
+ @Html.DisplayFor(modelItem => item.DateDelivery) + + @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem => item.Body) +
+ } +
diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Home/Mails.cshtml.cs b/SecuritySystem/SecurirySystemClientApp/Views/Home/Mails.cshtml.cs new file mode 100644 index 0000000..647d142 --- /dev/null +++ b/SecuritySystem/SecurirySystemClientApp/Views/Home/Mails.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace SecurirySystemClientApp.Views.Home +{ + public class MailsModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/SecuritySystem/SecurirySystemClientApp/Views/Shared/_Layout.cshtml b/SecuritySystem/SecurirySystemClientApp/Views/Shared/_Layout.cshtml index 2266cf1..92cd4ba 100644 --- a/SecuritySystem/SecurirySystemClientApp/Views/Shared/_Layout.cshtml +++ b/SecuritySystem/SecurirySystemClientApp/Views/Shared/_Layout.cshtml @@ -1,52 +1,55 @@  - - - - @ViewData["Title"] - SecuritySystemClientApp - - - - - - -
- -
-
-
- @RenderBody() -
-
- - - @RenderSection("Scripts", required: false) - + + +
+
+ @RenderBody() +
+
+ + + @RenderSection("Scripts", required: false) + diff --git a/SecuritySystem/SecuritySystem.sln b/SecuritySystem/SecuritySystem.sln index 74cd1bb..fb2437b 100644 --- a/SecuritySystem/SecuritySystem.sln +++ b/SecuritySystem/SecuritySystem.sln @@ -19,7 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemDatabaseImple EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecuritySystemRestApi", "SecuritySystemRestApi\SecuritySystemRestApi.csproj", "{A45C62CE-D0FF-4347-A6FF-773A6563BDA9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecurirySystemClientApp", "SecurirySystemClientApp\SecurirySystemClientApp.csproj", "{4DEDBF73-8644-48A2-B9FC-604F96EE0324}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SecurirySystemClientApp", "SecurirySystemClientApp\SecurirySystemClientApp.csproj", "{4DEDBF73-8644-48A2-B9FC-604F96EE0324}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/SecuritySystem/SecuritySystemRestApi/Controllers/ClientController.cs b/SecuritySystem/SecuritySystemRestApi/Controllers/ClientController.cs index 89eef6c..e76aaa7 100644 --- a/SecuritySystem/SecuritySystemRestApi/Controllers/ClientController.cs +++ b/SecuritySystem/SecuritySystemRestApi/Controllers/ClientController.cs @@ -12,11 +12,12 @@ namespace SecuritySystemRestApi.Controllers { private readonly ILogger _logger; private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger - logger) + private readonly IMessageInfoLogic _mailLogic; + public ClientController(IClientLogic logic, ILogger logger, IMessageInfoLogic mailLogic) { _logger = logger; _logic = logic; + _mailLogic = mailLogic; } [HttpGet] public ClientViewModel? Login(string login, string password) @@ -61,6 +62,22 @@ namespace SecuritySystemRestApi.Controllers throw; } } + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } } } diff --git a/SecuritySystem/SecuritySystemRestApi/Program.cs b/SecuritySystem/SecuritySystemRestApi/Program.cs index 4649aa6..5abb560 100644 --- a/SecuritySystem/SecuritySystemRestApi/Program.cs +++ b/SecuritySystem/SecuritySystemRestApi/Program.cs @@ -4,6 +4,7 @@ using SecuritySystemContracts.StoragesContracts; using SecuritySystemDatabaseImplement.Implements; using Microsoft.OpenApi.Models; using SecuritySystemBusinessLogic.MailWorker; +using SecuritySystemContracts.BindingModels; var builder = WebApplication.CreateBuilder(args); builder.Logging.SetMinimumLevel(LogLevel.Trace); @@ -33,6 +34,19 @@ builder.Services.AddSwaggerGen(c => }); var app = builder.Build(); + +var mailSender = app.Services.GetService(); +mailSender?.MailConfig(new MailConfigBindingModel +{ + MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty, + MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty, + SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()), + PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString()) +}); + + // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/SecuritySystem/SecuritySystemRestApi/appsettings.json b/SecuritySystem/SecuritySystemRestApi/appsettings.json index 10f68b8..8ad850a 100644 --- a/SecuritySystem/SecuritySystemRestApi/appsettings.json +++ b/SecuritySystem/SecuritySystemRestApi/appsettings.json @@ -5,5 +5,11 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "SmtpClientHost": "smtp.beget.com", + "SmtpClientPort": "2525", + "PopHost": "pop3.beget.com", + "PopPort": "995", + "MailLogin": "securitysystemshop@nspotapov.ru", + "MailPassword": "2iD8*KBY" } -- 2.25.1 From 73609b199950ea4c52ffd00277f2f8c5a88f7b15 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 6 May 2024 10:45:43 +0400 Subject: [PATCH 25/26] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ClientLogic.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs index dd77745..6af4b76 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/ClientLogic.cs @@ -104,6 +104,12 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); } + string regexpPasswordPattern = "^((\\w+\\d+\\W+)|(\\w+\\W+\\d+)|(\\d+\\w+\\W+)|(\\d+\\W+\\w+)|(\\W+\\w+\\d+)|(\\W+\\d+\\\r\nw+))[\\w\\d\\W]*$"; + Regex regexPassword = new Regex(regexpPasswordPattern); + if (!regexPassword.IsMatch(model.Password)) + { + throw new ArgumentException("Пароль не соответствует требованиям безопасности"); + } if (string.IsNullOrEmpty(model.ClientFIO)) { throw new ArgumentNullException("Нет фио клиента", nameof(model.ClientFIO)); -- 2.25.1 From 4e98e8ac4765d13d18bc31508a86a4ee97680f6d Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 6 May 2024 11:04:52 +0400 Subject: [PATCH 26/26] =?UTF-8?q?=D0=92=D1=81=D0=B5=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/MessageInfoLogic.cs | 12 ++++++++++-- .../MailWorker/MailKitWorker.cs | 4 +--- .../Controllers/ClientController.cs | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 521597f..801241c 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using DocumentFormat.OpenXml.Drawing; +using Microsoft.Extensions.Logging; using SecuritySystemContracts.BindingModels; using SecuritySystemContracts.BusinessLogicsContracts; using SecuritySystemContracts.SearchModels; @@ -11,10 +12,12 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IMessageInfoStorage _messageInfoStorage; - public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage) + private readonly IClientLogic _clientLogic; + public MessageInfoLogic(ILogger logger, IMessageInfoStorage messageInfoStorage, IClientLogic clientLogic) { _logger = logger; _messageInfoStorage = messageInfoStorage; + _clientLogic = clientLogic; } public bool Create(MessageInfoBindingModel model) @@ -23,6 +26,11 @@ namespace SecuritySystemBusinessLogic.BusinessLogics { return false; } + var client = _clientLogic.ReadElement(new ClientSearchModel { Email = model.SenderName }); + if (client != null) + { + model.ClientId = client.Id; + } if (_messageInfoStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); diff --git a/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs index e4659d6..5d383fe 100644 --- a/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs +++ b/SecuritySystem/SecuritySystemBusinessLogic/MailWorker/MailKitWorker.cs @@ -40,8 +40,6 @@ namespace SecuritySystemBusinessLogic.MailWorker protected override async Task> ReceiveMailAsync() { var list = new List(); - string regexpPattern = "(\\<(/?[^>]+)>)"; - Regex regexp = new Regex(regexpPattern); using var client = new Pop3Client(); await Task.Run(() => { @@ -60,7 +58,7 @@ namespace SecuritySystemBusinessLogic.MailWorker MessageId = message.MessageId, SenderName = mail.Address, Subject = message.Subject, - Body = regexp.Replace(message.HtmlBody, "") + Body = message.TextBody != null ? message.TextBody : message.HtmlBody }); } } diff --git a/SecuritySystem/SecuritySystemRestApi/Controllers/ClientController.cs b/SecuritySystem/SecuritySystemRestApi/Controllers/ClientController.cs index e76aaa7..af23d65 100644 --- a/SecuritySystem/SecuritySystemRestApi/Controllers/ClientController.cs +++ b/SecuritySystem/SecuritySystemRestApi/Controllers/ClientController.cs @@ -67,10 +67,11 @@ namespace SecuritySystemRestApi.Controllers { try { - return _mailLogic.ReadList(new MessageInfoSearchModel + var mails = _mailLogic.ReadList(new MessageInfoSearchModel { ClientId = clientId }); + return mails; } catch (Exception ex) { -- 2.25.1