2024-12-02 10:24:02 +00:00
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase;
|
2024-11-25 04:33:26 +00:00
|
|
|
|
using Demo.Data.Repository;
|
|
|
|
|
using Demo.Domain.UseCase;
|
2024-12-02 10:24:02 +00:00
|
|
|
|
using Demo.UI;
|
2024-11-25 04:33:26 +00:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2024-12-02 10:24:02 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-11-25 04:33:26 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2024-12-02 10:24:02 +00:00
|
|
|
|
using System;
|
2024-11-25 04:33:26 +00:00
|
|
|
|
using System.Collections.Generic;
|
2024-12-02 10:24:02 +00:00
|
|
|
|
using System.Diagnostics;
|
2024-11-25 04:33:26 +00:00
|
|
|
|
using System.IO;
|
2024-12-02 10:24:02 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-11-25 04:33:26 +00:00
|
|
|
|
using Demo.Domain.Models;
|
2024-10-21 22:57:01 +00:00
|
|
|
|
|
2024-10-28 12:42:04 +00:00
|
|
|
|
namespace Demo
|
2024-10-21 22:57:01 +00:00
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2024-12-02 10:24:02 +00:00
|
|
|
|
static async Task Main(string[] args)
|
2024-10-21 22:57:01 +00:00
|
|
|
|
{
|
2024-11-25 04:33:26 +00:00
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
// Добавляем сервисы в контейнер
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
builder.Services.AddScoped<IUserRepository, SQLUserRepositoryImpl>();
|
|
|
|
|
builder.Services.AddScoped<IGroupRepository, SQLGroupRepositoryImpl>();
|
|
|
|
|
builder.Services.AddScoped<IPresenceRepository, SQLPresenceRepository>();
|
|
|
|
|
builder.Services.AddScoped<UserUseCase>();
|
|
|
|
|
builder.Services.AddScoped<GroupUseCase>();
|
|
|
|
|
builder.Services.AddScoped<UseCasePresence>();
|
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
// Добавляем контекст базы данных
|
|
|
|
|
builder.Services.AddDbContext<RemoteDatabaseContext>(options =>
|
|
|
|
|
options.UseNpgsql("Host=45.67.56.214;Port=5421;Username=user5;Database=user5;Password=EtEJqhsf"));
|
|
|
|
|
|
|
|
|
|
// Добавляем Swagger
|
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
|
2024-11-25 04:33:26 +00:00
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Настройка конвейера обработки запросов
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
{
|
2024-12-02 10:24:02 +00:00
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI();
|
2024-11-25 04:33:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Инициализация данных
|
|
|
|
|
using (var scope = app.Services.CreateScope())
|
|
|
|
|
{
|
|
|
|
|
var services = scope.ServiceProvider;
|
2024-12-02 10:24:02 +00:00
|
|
|
|
var dbContext = services.GetRequiredService<RemoteDatabaseContext>();
|
2024-11-25 04:33:26 +00:00
|
|
|
|
DataInitializer.Initialize(dbContext);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Запуск консольного меню
|
2024-12-02 10:24:02 +00:00
|
|
|
|
using (var scope = app.Services.CreateScope())
|
2024-11-25 04:33:26 +00:00
|
|
|
|
{
|
2024-12-02 10:24:02 +00:00
|
|
|
|
var services = scope.ServiceProvider;
|
|
|
|
|
var context = services.GetRequiredService<RemoteDatabaseContext>();
|
|
|
|
|
var userRepository = new SQLUserRepositoryImpl(context);
|
|
|
|
|
var groupRepository = new SQLGroupRepositoryImpl(context);
|
|
|
|
|
var presenceRepository = new SQLPresenceRepository(context);
|
|
|
|
|
|
|
|
|
|
var userUseCase = new UserUseCase(userRepository);
|
|
|
|
|
var groupUseCase = new GroupUseCase(groupRepository);
|
|
|
|
|
var presenceUseCase = new UseCasePresence(presenceRepository);
|
|
|
|
|
|
|
|
|
|
var userConsole = new UserConsole(userUseCase);
|
|
|
|
|
var groupConsole = new GroupConsole(groupUseCase);
|
|
|
|
|
var presenceConsole = new PresenceConsole(presenceUseCase, userUseCase); // Передаем userUseCase
|
|
|
|
|
var excelExporter = new ExcelExporter();
|
|
|
|
|
|
|
|
|
|
// Создаем данные для экспорта
|
|
|
|
|
var group = new Group { Name = "Group 1" };
|
|
|
|
|
var users = new List<User> { new User { Id = Guid.NewGuid(), FIO = "User 1" } }; // Используем Guid для Id
|
|
|
|
|
var presence = new List<Presence> { new Presence { UserId = users[0].Id, IsAttendance = true } };
|
|
|
|
|
|
|
|
|
|
// Указываем путь для сохранения файла
|
|
|
|
|
string directoryPath = @"C:\Users\class_Student\Source\Repos\slarny4\Demo1\Excel";
|
|
|
|
|
string filePath = Path.Combine(directoryPath, "GroupInfo.xlsx");
|
|
|
|
|
|
|
|
|
|
// Проверяем, существует ли директория, и если нет, создаем её
|
|
|
|
|
if (!Directory.Exists(directoryPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(directoryPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Вызываем метод для экспорта данных в Excel
|
|
|
|
|
excelExporter.ExportGroupInfoToExcel(group, users, presence, filePath);
|
|
|
|
|
|
|
|
|
|
var mainMenu = new MainMenu(userConsole, groupConsole, presenceConsole, excelExporter, groupUseCase, userUseCase, presenceUseCase);
|
|
|
|
|
mainMenu.ShowMenu();
|
2024-11-25 04:33:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
// Запуск веб-сервера асинхронно
|
|
|
|
|
var url = "http://localhost:5000";
|
|
|
|
|
var serverTask = app.RunAsync(url);
|
|
|
|
|
|
|
|
|
|
// Открытие браузера с Swagger UI после запуска сервера
|
|
|
|
|
await Task.Delay(1000); // Небольшая задержка, чтобы сервер успел запуститься
|
|
|
|
|
OpenBrowser(url + "/swagger");
|
2024-11-25 04:33:26 +00:00
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
// Ожидание завершения сервера
|
|
|
|
|
await serverTask;
|
|
|
|
|
}
|
2024-11-25 04:33:26 +00:00
|
|
|
|
|
2024-12-02 10:24:02 +00:00
|
|
|
|
private static void OpenBrowser(string url)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process.Start(url);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// Если запуск через Process.Start не работает, попробуем другой метод
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
|
|
|
|
url = url.Replace("&", "^&");
|
|
|
|
|
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
|
|
|
|
|
}
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
|
|
|
|
{
|
|
|
|
|
Process.Start("xdg-open", url);
|
|
|
|
|
}
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
|
|
{
|
|
|
|
|
Process.Start("open", url);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-23 09:52:43 +00:00
|
|
|
|
}
|
2024-10-21 22:57:01 +00:00
|
|
|
|
}
|
2024-10-24 08:50:32 +00:00
|
|
|
|
}
|