/
KDP
/
SuprTimeLogAutomation
Обзор
Документация
Войти
/
KDP
/
SuprTimeLogAutomation
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Program.cs
80 строк
3 KB
Krylov Dmitry
Поддержка нулевого номера недели как текущего.
08 авг 2026, 10:15
08 авг 2026, 10:15
5e6f671
Код
Авторство
О чём код?
using System.Globalization; using OpenQA.Selenium.Chrome; using SuprTimeLogAutomation.Helpers; using SuprTimeLogAutomation.Services; namespace SuprTimeLogAutomation; class Program { public static async Task Main(string[] args) { Services.SuprTimeLogAutomation automation = null; try { Console.WriteLine("Запуск автоматизации трудозатрат..."); // 1. Загрузка конфигурации var config = await ConfigService.LoadAsync(); if (config.TimeLog.WeekNumber < 1) { // 0 или -1 рассматриваем как желание текущей недели. config.TimeLog.WeekNumber = CultureInfo.InvariantCulture.Calendar .GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); } Console.WriteLine($"Конфиг загружен. Неделя: {config.TimeLog.WeekNumber}"); // 2. Инициализация маппера ProjectMapper.Initialize(config.ProjectMapping); // 3. Генерация и парсинг JSON var timeLogService = new TimeLogService(); Console.WriteLine("Генерация JSON..."); var jsonPath = await timeLogService.GenerateTimeLogJsonAsync( config.TimeLog.ProgramPath, config.TimeLog.WeekNumber); Console.WriteLine("Парсинг JSON..."); var entries = await timeLogService.ParseTimeLogAsync(jsonPath); Console.WriteLine($"Загружено записей: {entries.Sum(e => e.Details?.Count ?? 0)}"); // 4. Настройка Selenium var chromeOptions = new ChromeOptions(); // 5. Автоматизация SUPR automation = new Services.SuprTimeLogAutomation(chromeOptions, config.Selenium); Console.WriteLine("Открытие SUPR..."); automation.NavigateToSite( config.Supr.BaseUrl, config.Supr.Username, config.Supr.Password); Console.WriteLine("Навигация к форме трудозатрат..."); automation.NavigateToWeeklyTimeLog(); Console.WriteLine($"Открытие формы для недели {config.TimeLog.WeekNumber}..."); automation.OpenWeekEntryForm(config.TimeLog.WeekNumber); Console.WriteLine("Заполнение трудозатрат..."); automation.FillTimeEntries(entries); Console.WriteLine("Готово! Трудозатраты успешно внесены."); Console.WriteLine("Для выхода нажмите Enter ..."); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine($"✗ Ошибка: {ex.Message}"); Console.WriteLine(ex.StackTrace); Environment.ExitCode = 1; } finally { // 🔥 Гарантированная очистка ресурсов ДАЖЕ при ошибке automation?.Dispose(); Console.WriteLine("🧹 Ресурсы освобождены. Можно удалять папку."); } } }