public static string GetCurrentDirectory() { if (_provider == null) { return(Directory.GetCurrentDirectory()); } return(_provider.GetCurrentDirectory()); }
public async Task GenerateAsync(SourceType source, string name) { try { var problemParser = GetProblemParser(source); var problem = await problemParser.ParseAsync(name).ConfigureAwait(false); logger.LogDebug($"Problem parsed from {source}."); var interfaceNode = await interfaceGenerator.GenerateAsync(problem).ConfigureAwait(false); logger.LogInformation($"Interface generated."); var classNode = await classGenerator.GenerateAsync(interfaceNode).ConfigureAwait(false); logger.LogInformation("Class generated."); var testClassNode = await testClassGenerator.GenerateAsync(classNode).ConfigureAwait(false); logger.LogInformation("Test class generated."); var interfacePath = Path.Combine(directoryProvider.GetCurrentDirectory().FullName, config.SrcPath, problem.Title.ToClassName()); await csFileSaver.SaveAsync(interfaceNode, interfacePath).ConfigureAwait(false); logger.LogInformation($"Interface saved to '{interfacePath}'."); var classPath = Path.Combine(directoryProvider.GetCurrentDirectory().FullName, config.SrcPath, problem.Title.ToClassName()); await csFileSaver.SaveAsync(classNode, classPath).ConfigureAwait(false); logger.LogInformation($"Class saved to '{classPath}'."); var testsPath = Path.Combine(directoryProvider.GetCurrentDirectory().FullName, config.TestsPath); await csFileSaver.SaveAsync(testClassNode, testsPath).ConfigureAwait(false); logger.LogInformation($"Test class saved to '{testsPath}'."); var readmePath = Path.Combine(directoryProvider.GetCurrentDirectory().FullName, config.ReadmePath); await readmeUpdater.Insert(problem, readmePath).ConfigureAwait(false); logger.LogInformation($"Readme updated ({readmePath})."); } catch (Exception e) { logger.LogCritical(e, "Error occurred while generation."); } }