2024-04-30 21:22:23 +03:00
|
|
|
using Microsoft.OpenApi.Models;
|
2024-08-16 13:44:43 +04:00
|
|
|
using Serilog;
|
|
|
|
using ServiceSourceBusinessLogic.BusinessLogic;
|
|
|
|
using ServiceSourceBusinessLogic.MailKitWorker;
|
|
|
|
using ServiceSourceBusinessLogic.OfficePackage;
|
|
|
|
using ServiceSourceBusinessLogic.OfficePackage.Implements;
|
|
|
|
using ServiceStationContracts.BindingModels;
|
|
|
|
using ServiceStationContracts.BusinessLogic;
|
|
|
|
using ServiceStationContracts.BusinessLogicContracts;
|
|
|
|
using ServiceStationsContracts.StorageContracts;
|
|
|
|
using ServiceStationsDataBaseImplement.Implements;
|
2024-04-30 21:22:23 +03:00
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
2024-08-16 13:44:43 +04:00
|
|
|
builder.Services.AddControllersWithViews();
|
|
|
|
builder.Services.AddSession();
|
|
|
|
|
2024-04-30 21:22:23 +03:00
|
|
|
// Add services to the container.
|
|
|
|
|
2024-08-16 13:44:43 +04:00
|
|
|
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
|
|
|
builder.Services.AddTransient<IExecutorStorage, ExecutorStorage>();
|
|
|
|
builder.Services.AddTransient<ITaskStorage, TaskStorage>();
|
|
|
|
builder.Services.AddTransient<IWorkStorage, WorkStorage>();
|
|
|
|
|
|
|
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
|
|
|
builder.Services.AddTransient<IExecutorLogic, ExecutorLogic>();
|
|
|
|
builder.Services.AddTransient<IReportLogic, ReportLogic>();
|
|
|
|
builder.Services.AddTransient<ITaskLogic, TaskLogic>();
|
|
|
|
builder.Services.AddTransient<IWorkLogic, WorkLogic>();
|
|
|
|
|
|
|
|
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcek>();
|
|
|
|
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
|
|
|
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
|
|
|
|
|
|
|
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
|
|
|
|
|
|
|
builder.Services.AddLogging(option => {
|
|
|
|
var configuration = new ConfigurationBuilder()
|
|
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
|
|
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var logger = new LoggerConfiguration()
|
|
|
|
.ReadFrom.Configuration(configuration)
|
|
|
|
.CreateLogger();
|
|
|
|
|
|
|
|
option.AddSerilog(logger);
|
|
|
|
});
|
|
|
|
|
2024-04-30 21:22:23 +03:00
|
|
|
builder.Services.AddControllers();
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
builder.Services.AddSwaggerGen(x => x.SwaggerDoc("v1", new OpenApiInfo { Title = "ServiceSourceRestAPI", Version = "v1" }));
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
2024-08-16 13:44:43 +04:00
|
|
|
var mailSender = app.Services.GetService<AbstractMailWorker>();
|
|
|
|
|
|
|
|
mailSender?.MailConfig(new MailConfigBindingModel {
|
|
|
|
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
|
|
|
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
|
|
|
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
|
|
|
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
|
|
|
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
|
|
|
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
|
|
|
});
|
|
|
|
|
2024-04-30 21:22:23 +03:00
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment()) {
|
|
|
|
app.UseSwagger();
|
|
|
|
app.UseSwaggerUI(x => x.SwaggerEndpoint("/swagger/v1/swagger.json", "ServiceSourceRestAPI v1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
2024-08-16 13:44:43 +04:00
|
|
|
app.UseRouting();
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseSession();
|
2024-04-30 21:22:23 +03:00
|
|
|
|
2024-08-16 13:44:43 +04:00
|
|
|
app.UseRouting();
|
2024-04-30 21:22:23 +03:00
|
|
|
|
2024-08-16 13:44:43 +04:00
|
|
|
app.UseAuthorization();
|
2024-04-30 21:22:23 +03:00
|
|
|
|
2024-08-16 13:44:43 +04:00
|
|
|
app.MapControllerRoute(
|
|
|
|
name: "default",
|
|
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
2024-04-30 21:22:23 +03:00
|
|
|
|
2024-08-16 13:44:43 +04:00
|
|
|
app.Run();
|