From d038e9407956fdd4d7e4c1bba0babf73988ce41f Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Sun, 30 Apr 2023 18:15:47 +0400 Subject: [PATCH] program edited --- JewelryStore/Program.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index 50bf9fa..2794caf 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -9,6 +9,8 @@ using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using JewelryStoreBusinessLogic.OfficePackage; using JewelryStoreBusinessLogic.OfficePackage.Implements; +using JewelryStoreBusinessLogic.MailWorker; +using JewelryStoreContracts.BindingModels; namespace JewelryStore { @@ -29,6 +31,27 @@ namespace JewelryStore 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,9 +66,11 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); @@ -53,6 +78,7 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -71,6 +97,6 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); } - + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); } } \ No newline at end of file