diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/MessageInfoLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/MessageInfoLogic.cs index 1da4d6a..c4cbb90 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/MessageInfoLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/MessageInfoLogic.cs @@ -14,7 +14,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics private readonly IMessageInfoStorage _messageInfoStorage; private readonly IClientStorage _clientStorage; - public MessageInfoLogic(ILogger Logger, IMessageInfoStorage MessageInfoStorage, IClientStorage ClientStorage) + public MessageInfoLogic(ILogger Logger, IMessageInfoStorage MessageInfoStorage, IClientStorage ClientStorage) { _logger = Logger; _messageInfoStorage = MessageInfoStorage; diff --git a/AutoWorkshopDatabaseImplement/Models/MessageInfo.cs b/AutoWorkshopDatabaseImplement/Models/MessageInfo.cs index 5b4be1e..c05855d 100644 --- a/AutoWorkshopDatabaseImplement/Models/MessageInfo.cs +++ b/AutoWorkshopDatabaseImplement/Models/MessageInfo.cs @@ -1,11 +1,13 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.ViewModels; using AutoWorkshopDataModels.Models; +using System.ComponentModel.DataAnnotations; namespace AutoWorkshopDatabaseImplement.Models { public class MessageInfo : IMessageInfoModel { + [Key] public string MessageId { get; set; } = string.Empty; public int? ClientId { get; set; } diff --git a/AutoWorkshopView/Program.cs b/AutoWorkshopView/Program.cs index 131a87c..b6d2732 100644 --- a/AutoWorkshopView/Program.cs +++ b/AutoWorkshopView/Program.cs @@ -9,6 +9,8 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopBusinessLogic.MailWorker; +using AutoWorkshopContracts.BindingModels; namespace AutoWorkshopView { @@ -25,11 +27,35 @@ namespace AutoWorkshopView var Services = new ServiceCollection(); ConfigureServices(Services); - _serviceProvider = Services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); + _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["SmtpClient Port"]), + 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) + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.CheckMailAsync(); + + private static void ConfigureServices(ServiceCollection Services) { Services.AddLogging(option => { @@ -42,6 +68,7 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); @@ -50,10 +77,12 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddSingleton(); Services.AddTransient(); Services.AddTransient(); @@ -67,6 +96,7 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); } } }