From 948b33051593984a376b24a6627b05c7dd5b7aa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Fri, 17 May 2024 10:14:26 +0400 Subject: [PATCH 1/2] Full done --- SushiBar/SushiBar/Program.cs | 2 +- SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index 4605c28..7982341 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -47,7 +47,7 @@ namespace SushiBarView catch (Exception ex) { var logger = _serviceProvider.GetService(); - logger?.LogError(ex, "<22><> <20><> <20> <20><>"); + logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé"); } Application.Run(_serviceProvider.GetRequiredService()); diff --git a/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs b/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs index d396709..268fa2a 100644 --- a/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs +++ b/SushiBar/SushiBarBusinessLogic/MailWorker/MailKitWorker.cs @@ -44,7 +44,7 @@ namespace SushiBarBusinessLogic.MailWorker { var list = new List(); using var client = new Pop3Client(); - await Task.Run(() => + await Task.Run(() => { try { From 7745cfc783bf57e4da602cacb59c07a90d732c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Sat, 18 May 2024 23:29:20 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9D=D0=B0=203=20=D1=8D=D1=82=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=20=D0=B6=D0=B8=D0=B7=D0=BD=D0=B8=20=D0=BD=D0=B0=D0=B4?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=B8=D1=82=D1=8C?= 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 | 83 +++++++++++++++++++ .../DataListSingleton.cs | 2 + .../Implements/MessageInfoStorage.cs | 61 ++++++++++++++ .../Models/MessageInfo.cs | 53 ++++++++++++ 6 files changed, 256 insertions(+) create mode 100644 SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs create mode 100644 SushiBar/SushiBarFileImplement/Models/MessageInfo.cs create mode 100644 SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs create mode 100644 SushiBar/SushiBarListImplement/Models/MessageInfo.cs diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs index b0c1fcc..1cf7549 100644 --- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -11,11 +11,13 @@ namespace SushiBarFileImplement private readonly string SushiFileName = "Sushi.xml"; private readonly string ClientFileName = "Client.xml"; private readonly string ImplementerFileName = "Implementer.xml"; + private readonly string MessageInfoFileName = "MessageInfo.xml"; public List Ingredients { get; private set; } public List Orders { get; private set; } public List ListSushi { get; private set; } public List Clients { get; private set; } public List Implementers { get; private set; } + public List Messages { get; private set; } public static DataFileSingleton GetInstance() { @@ -32,6 +34,7 @@ namespace SushiBarFileImplement 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 SaveMessages() => SaveData(Orders, ImplementerFileName, "Messages", x => x.GetXElement); private DataFileSingleton() { @@ -40,6 +43,7 @@ namespace SushiBarFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; + Messages = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..eed14a8 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,53 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarFileImplement.Models; + +namespace SushiBarFileImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataFileSingleton _source; + public MessageInfoStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + if (model.MessageId != null) + { + return _source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + return _source.Messages + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return _source.Messages + .Select(x => x.GetViewModel) + .ToList(); + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + _source.SaveMessages(); + return newMessage.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs b/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..ea89b78 --- /dev/null +++ b/SushiBar/SushiBarFileImplement/Models/MessageInfo.cs @@ -0,0 +1,83 @@ +using PrecastConcretePlantDataModels.Models; +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SushiBarFileImplement.Models +{ + [DataContract] + public class MessageInfo : IMessageInfoModel + { + [DataMember] + public string MessageId { get; private set; } = string.Empty; + [DataMember] + public int? ClientId { get; private set; } + [DataMember] + public string SenderName { get; private set; } = string.Empty; + [DataMember] + public DateTime DateDelivery { get; private set; } = DateTime.Now; + [DataMember] + public string Subject { get; private set; } = string.Empty; + [DataMember] + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public static MessageInfo? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Body = element.Attribute("Body")!.Value, + Subject = element.Attribute("Subject")!.Value, + ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value), + MessageId = element.Attribute("MessageId")!.Value, + SenderName = element.Attribute("SenderName")!.Value, + DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value), + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + + public XElement GetXElement => new("MessageInfo", + new XAttribute("Body", Body), + new XAttribute("Subject", Subject), + new XAttribute("ClientId", ClientId), + new XAttribute("MessageId", MessageId), + new XAttribute("SenderName", SenderName), + new XAttribute("DateDelivery", DateDelivery) + ); + } +} diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index 5b6c0d2..9e0b832 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -11,6 +11,7 @@ namespace SushiBarListImplement public List ListSushi { get; set; } public List Clients { get; set; } public List Implementers { get; set; } + public List Messages { get; set; } private DataListSingleton() { Ingredients = new List(); @@ -18,6 +19,7 @@ namespace SushiBarListImplement ListSushi = new List(); Clients = new List(); Implementers = new List(); + Messages = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs b/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..820aa3a --- /dev/null +++ b/SushiBar/SushiBarListImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,61 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; + +namespace SushiBarListImplement.Implements +{ + public class MessageInfoStorage : IMessageInfoStorage + { + private readonly DataListSingleton _source; + public MessageInfoStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) + { + foreach (var message in _source.Messages) + { + if (model.MessageId != null && model.MessageId.Equals(message.MessageId)) + return message.GetViewModel; + } + return null; + } + + public List GetFilteredList(MessageInfoSearchModel model) + { + List result = new(); + foreach (var item in _source.Messages) + { + if (item.ClientId.HasValue && item.ClientId == model.ClientId) + { + result.Add(item.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + List result = new(); + foreach (var item in _source.Messages) + { + result.Add(item.GetViewModel); + } + return result; + } + + public MessageInfoViewModel? Insert(MessageInfoBindingModel model) + { + var newMessage = MessageInfo.Create(model); + if (newMessage == null) + { + return null; + } + _source.Messages.Add(newMessage); + return newMessage.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarListImplement/Models/MessageInfo.cs b/SushiBar/SushiBarListImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..2e967e1 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Models/MessageInfo.cs @@ -0,0 +1,53 @@ +using PrecastConcretePlantDataModels.Models; +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Models +{ + public class MessageInfo : IMessageInfoModel + { + public string MessageId { get; private set; } = string.Empty; + + public int? ClientId { get; private set; } + + public string SenderName { get; private set; } = string.Empty; + + public DateTime DateDelivery { get; private set; } = DateTime.Now; + + public string Subject { get; private set; } = string.Empty; + + public string Body { get; private set; } = string.Empty; + + public static MessageInfo? Create(MessageInfoBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Body = model.Body, + Subject = model.Subject, + ClientId = model.ClientId, + MessageId = model.MessageId, + SenderName = model.SenderName, + DateDelivery = model.DateDelivery, + }; + } + + public MessageInfoViewModel GetViewModel => new() + { + Body = Body, + Subject = Subject, + ClientId = ClientId, + MessageId = MessageId, + SenderName = SenderName, + DateDelivery = DateDelivery, + }; + } +}