using System.Diagnostics; namespace CodeBase.Orchestrators { public class ScipOrchestrator { private readonly Dictionary _indexerCommands; // Внедряем IConfiguration через конструктор public ScipOrchestrator(IConfiguration configuration) { // Считываем секцию из appsettings.json в словарь при старте приложения _indexerCommands = configuration.GetSection("ScipIndexers").Get>() ?? new Dictionary(); } public async Task GenerateScipAsync(string localRepoPath, string language) { var absolutePath = Path.GetFullPath(localRepoPath); var scipFilePath = Path.Combine(absolutePath, "index.scip"); if (File.Exists(scipFilePath)) { Console.WriteLine($"[SCIP] Файл графа уже существует: {scipFilePath}"); return true; } var langKey = language.Trim().ToLowerInvariant(); // 1. Ищем команду по ключу из файла if (!_indexerCommands.TryGetValue(langKey, out var commandTemplate)) { Console.WriteLine($"[SCIP ERROR] Язык '{langKey}' не найден в конфигурации appsettings.json."); return false; } // Обманываем scip-python, подкидывая ему маркер корня проекта, чтобы он не требовал Git if (langKey == "python") { var dummyFilePath = Path.Combine(absolutePath, "pyproject.toml"); var setupFilePath = Path.Combine(absolutePath, "setup.py"); // Если ни одного из файлов конфигурации нет, создаем пустышку if (!File.Exists(dummyFilePath) && !File.Exists(setupFilePath)) { File.WriteAllText(dummyFilePath, ""); // Создаем физический файл нулевого размера Console.WriteLine("[SCIP] Создан пустой файл pyproject.toml для обхода ограничений парсера."); } } // 2. Подставляем путь к репозиторию в шаблон команды (заменяем {0}) string dockerArguments = string.Format(commandTemplate, absolutePath); Console.WriteLine($"[SCIP] Запускаем индексацию для проекта: {absolutePath} (Язык: {langKey})"); var processStartInfo = new ProcessStartInfo { FileName = "docker", Arguments = dockerArguments, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; using var process = new Process { StartInfo = processStartInfo }; process.Start(); var outputTask = process.StandardOutput.ReadToEndAsync(); var errorTask = process.StandardError.ReadToEndAsync(); await process.WaitForExitAsync(); if (process.ExitCode != 0) { var error = await errorTask; Console.WriteLine($"[SCIP ERROR] Ошибка генерации графа:\n{error}"); return false; } return true; } } }