PIbd-23-Volkov-N.A.-Compute.../ComputersShop/ComputersShopView/Program.cs

98 lines
4.8 KiB
C#
Raw Normal View History

2024-02-05 20:36:39 +04:00
using ComputersShopBusinessLogic.BusinessLogics;
2024-03-18 18:43:53 +04:00
using ComputersShopBusinessLogic.OfficePackage.Implements;
using ComputersShopBusinessLogic.OfficePackage;
2024-02-05 20:36:39 +04:00
using ComputersShopContracts.BusinessLogicContracts;
using ComputersShopContracts.StoragesContracts;
2024-03-04 22:33:22 +04:00
using ComputersShopDataBaseImplement.Implements;
2024-02-05 20:36:39 +04:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
2024-04-16 23:11:45 +04:00
using ComputersShopBusinessLogic.MailWorker;
using ComputersShopContracts.BindingModels;
2024-02-18 13:58:39 +04:00
2024-02-05 20:36:39 +04:00
namespace ComputersShopView
{
internal static class Program
2024-04-16 23:11:45 +04:00
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_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["SmtpClientPort"]),
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
});
2024-02-05 20:36:39 +04:00
2024-04-16 23:11:45 +04:00
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000);
}
catch (Exception ex)
{
var logger = _serviceProvider.GetService<ILogger>();
logger?.LogError(ex, "Error");
}
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
2024-02-05 20:36:39 +04:00
2024-04-16 23:11:45 +04:00
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IComputerStorage, ComputerStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
2024-02-05 20:36:39 +04:00
2024-04-16 23:11:45 +04:00
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IComputerLogic, ComputerLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
2024-03-18 18:43:53 +04:00
2024-04-16 23:11:45 +04:00
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
services.AddTransient<FormMain>();
services.AddTransient<FormClients>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormComputer>();
services.AddTransient<FormComputers>();
services.AddTransient<FormComputerComponent>();
services.AddTransient<FormReportComputerComponents>();
services.AddTransient<FormReportOrders>();
services.AddTransient<FormImplementer>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormMails>();
}
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
}
2024-02-05 20:36:39 +04:00
}