Edit Program.cs

This commit is contained in:
ShabOl 2024-04-19 23:46:09 +04:00
parent 2a2d3d1845
commit 2ed258e3b8
3 changed files with 36 additions and 4 deletions

View File

@ -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<MessageInfoLogic> Logger, IMessageInfoStorage MessageInfoStorage, IClientStorage ClientStorage)
{
_logger = Logger;
_messageInfoStorage = MessageInfoStorage;

View File

@ -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; }

View File

@ -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<MainForm>());
_serviceProvider = Services.BuildServiceProvider();
try
{
var MailSender = _serviceProvider.GetService<AbstractMailWorker>();
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<ILogger>();
Logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
}
Application.Run(_serviceProvider.GetRequiredService<MainForm>());
}
private static void ConfigureServices(ServiceCollection Services)
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.CheckMailAsync();
private static void ConfigureServices(ServiceCollection Services)
{
Services.AddLogging(option =>
{
@ -42,6 +68,7 @@ namespace AutoWorkshopView
Services.AddTransient<IRepairStorage, RepairStorage>();
Services.AddTransient<IClientStorage, ClientStorage>();
Services.AddTransient<IImplementerStorage, ImplementerStorage>();
Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
Services.AddTransient<IComponentLogic, ComponentLogic>();
Services.AddTransient<IOrderLogic, OrderLogic>();
@ -50,10 +77,12 @@ namespace AutoWorkshopView
Services.AddTransient<IClientLogic, ClientLogic>();
Services.AddTransient<IImplementerLogic, ImplementerLogic>();
Services.AddTransient<IWorkProcess, WorkModeling>();
Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
Services.AddTransient<AbstractSaveToWord, SaveToWord>();
Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
Services.AddTransient<MainForm>();
Services.AddTransient<FormComponent>();
@ -67,6 +96,7 @@ namespace AutoWorkshopView
Services.AddTransient<FormClients>();
Services.AddTransient<FormImplementers>();
Services.AddTransient<FormImplementer>();
Services.AddTransient<FormMail>();
}
}
}