diff --git a/ShipyardView/App.config b/ShipyardView/App.config new file mode 100644 index 0000000..caf7695 --- /dev/null +++ b/ShipyardView/App.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ShipyardView/Program.cs b/ShipyardView/Program.cs index fc310c8..edb0b00 100644 --- a/ShipyardView/Program.cs +++ b/ShipyardView/Program.cs @@ -12,6 +12,7 @@ using ShipyardBusinessLogic.OfficePackage.Implements; using ShipyardBusinessLogic.OfficePackage; using ShipyardContracts.StorageContracts; using ShipyardDatabaseImplement; +using ShipyardContracts.BindingModels; namespace ShipyardView { @@ -31,7 +32,36 @@ namespace ShipyardView var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); + 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, 10000); + } + catch (Exception ex) + { + var logger = _serviceProvider.GetService(); + logger?.LogError(ex, "exception with mail"); + } + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) { @@ -67,6 +97,11 @@ namespace ShipyardView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddSingleton(); } - } + private static void MailCheck(object obj) => ServiceProvider?.GetService()?.MailCheck(); + } } \ No newline at end of file