ISEbd-22_Baygulov_A.A._Sush.../SushiBar/SushiBarView/Program.cs

103 lines
4.6 KiB
C#
Raw Permalink Normal View History

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarDatabaseImplement.Implements;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.StoragesContracts;
using NLog.Extensions.Logging;
using SushiBarBusinessLogic.OfficePackage.Implements;
using SushiBarBusinessLogic.OfficePackage;
2024-05-03 23:18:28 +04:00
using Microsoft.EntityFrameworkCore.Design;
using SushiBarBusinessLogic;
2024-05-04 18:04:21 +04:00
using SushiBarDatabaseImplement;
2024-06-01 16:27:44 +04:00
using SushiBarBusinessLogic.MailWorker;
using SushiBarContracts.BindingModels;
namespace SushiBarView
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
2024-03-14 21:54:43 +04:00
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
2024-06-01 16:27:44 +04:00
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"])
});
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000);
}
catch (Exception ex)
{
var logger = _serviceProvider.GetService<ILogger>();
logger?.LogError(ex, "Mails Problem");
}
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
2024-05-04 18:04:21 +04:00
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
2024-05-03 23:18:28 +04:00
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ISushiStorage, SushiStorage>();
2024-05-22 22:23:36 +04:00
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
2024-06-01 16:27:44 +04:00
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
2024-06-01 16:27:44 +04:00
services.AddTransient<IComponentLogic, ComponentLogic>();
2024-05-03 23:18:28 +04:00
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISushiLogic, SushiLogic>();
2024-05-22 22:23:36 +04:00
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
2024-06-01 16:27:44 +04:00
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
2024-06-01 16:27:44 +04:00
services.AddTransient<FormMain>();
2024-05-03 23:18:28 +04:00
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormSushis>();
2024-05-22 22:23:36 +04:00
services.AddTransient<FormSushiComponent>();
services.AddTransient<FormSushi>();
2024-05-03 23:18:28 +04:00
services.AddTransient<FormReportOrders>();
2024-05-22 22:23:36 +04:00
services.AddTransient<FormReportSushiComponents>();
2024-05-04 18:04:21 +04:00
services.AddTransient<FormImplementers>();
services.AddTransient<FormImplementer>();
2024-05-22 22:23:36 +04:00
services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<FormClients>();
2024-06-01 16:27:44 +04:00
services.AddTransient<FormMail>();
services.AddTransient<EntityFrameworkDesignServicesBuilder>();
2024-05-22 22:23:36 +04:00
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
services.AddTransient<FormMain>();
2024-05-03 23:18:28 +04:00
}
2024-06-01 16:27:44 +04:00
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
}
2024-03-14 21:54:43 +04:00
}