2024-08-19 17:49:44 +04:00
|
|
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
|
using Serilog;
|
|
|
|
|
using ServiceStationBusinessLogic.BusinessLogic;
|
|
|
|
|
using ServiceStationBusinessLogic.MailKitWorker;
|
|
|
|
|
using ServiceStationBusinessLogic.OfficePackage;
|
|
|
|
|
using ServiceStationBusinessLogic.OfficePackage.Implements;
|
|
|
|
|
using ServiceStationContracts.BindingModels;
|
|
|
|
|
using ServiceStationContracts.BusinessLogic;
|
|
|
|
|
using ServiceStationContracts.StorageContracts;
|
|
|
|
|
using ServiceStationsDataBaseImplement.Implements;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ServiceStationRestAPI {
|
|
|
|
|
public class Program {
|
|
|
|
|
public static void Main(string[] args) {
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
builder.Services.AddControllersWithViews();
|
|
|
|
|
builder.Services.AddSession();
|
|
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
|
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
|
|
|
|
builder.Services.AddTransient<IExecutorStorage, ExecutorStorage>();
|
|
|
|
|
builder.Services.AddTransient<ITaskStorage, TaskStorage>();
|
|
|
|
|
builder.Services.AddTransient<IWorkStorage, WorkStorage>();
|
2024-08-20 10:37:39 +04:00
|
|
|
|
builder.Services.AddTransient<IWorkClientStorage, WorkClientStorage>();
|
2024-08-19 17:49:44 +04:00
|
|
|
|
|
|
|
|
|
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
|
|
|
|
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
|
|
|
|
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
|
|
|
|
|
|
|
|
|
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>();
|
2024-08-20 10:37:39 +04:00
|
|
|
|
builder.Services.AddTransient<IWorkClientLogic, WorkClientLogic>();
|
2024-08-19 17:49:44 +04:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
builder.Services.AddSwaggerGen(c =>
|
|
|
|
|
{
|
|
|
|
|
c.SwaggerDoc("v1", new OpenApiInfo {
|
|
|
|
|
Title = "ServiceStationRestApi",
|
|
|
|
|
Version = "v1"
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
if (app.Environment.IsDevelopment()) {
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ServiceStationRestApi v1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
app.UseSession(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
app.MapControllerRoute(
|
|
|
|
|
name: "default",
|
|
|
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
|
|
|
|
|
|
app.Run();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|