/
KDP
/
SuprTimeLogAutomation
Обзор
Документация
Войти
/
KDP
/
SuprTimeLogAutomation
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Services/TimeLogService.cs
47 строк
2 KB
Timshin Mikhail
first commit
24 июн 2026, 14:52
24 июн 2026, 14:52
61ceede
Код
Авторство
О чём код?
using System.Diagnostics; using System.Text.Json; using SuprTimeLogAutomation.Models; namespace SuprTimeLogAutomation.Services; public class TimeLogService { public async Task<string> GenerateTimeLogJsonAsync(string programPath, int weekNumber) { var jsonFileName = $"w{weekNumber}.json"; var jsonPath = Path.Combine(programPath, jsonFileName); var psi = new ProcessStartInfo { FileName = "powershell.exe", Arguments = $"-NoProfile -ExecutionPolicy Bypass -Command \"cd '{programPath}'; .\\TimeLog4supr.exe /D /w {weekNumber} /j {jsonFileName}\"", RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; using var process = Process.Start(psi); await process.WaitForExitAsync(); if (process.ExitCode != 0) { var error = await process.StandardError.ReadToEndAsync(); throw new Exception($"Ошибка выполнения TimeLog4supr: {error}"); } if (!File.Exists(jsonPath)) throw new FileNotFoundException($"JSON-файл не создан: {jsonPath}"); return jsonPath; } public async Task<List<TimeLogEntry>?> ParseTimeLogAsync(string jsonPath) { var json = await File.ReadAllTextAsync(jsonPath); return JsonSerializer.Deserialize<List<TimeLogEntry>>(json, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); } }