-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIdeController.cs
More file actions
71 lines (56 loc) · 2.24 KB
/
IdeController.cs
File metadata and controls
71 lines (56 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using DevMiniOS.Interfaces;
using DevMiniOS.Models;
using DevMiniOS.Services;
using Microsoft.AspNetCore.Mvc;
namespace DevMiniOS.Controllers
{
public class IdeController : Controller
{
private readonly IPlanner _planner;
private readonly OutputService _outputSerivce;
private readonly GitService _gitService;
public IdeController(IPlanner planner, OutputService outputSerivce, GitService gitService)
{
_planner = planner;
_outputSerivce = outputSerivce;
_gitService = gitService;
}
public IActionResult Index()
{
return View(); // return the Index view
}
[HttpPost]
public async Task<IActionResult> Generate(string naturalLanguage, string language)
{
//Planning
Plan plan = await _planner.CreatePlanAsync(naturalLanguage);
//Output
OutputResult outputResult = _outputSerivce.GenerateOutput(plan, language);
//Write files to disk
string projectRoot = "./output"; // Or get from config
string languageDirectory = Path.Combine(projectRoot, naturalLanguage);
if (!Directory.Exists(languageDirectory))
{
Directory.CreateDirectory(languageDirectory);
}
foreach (var file in outputResult.GeneratedFiles)
{
string fullpath = Path.Combine(languageDirectory, file.Path);
string? directory = Path.GetDirectoryName(fullpath);
if(!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
System.IO.File.WriteAllText(fullpath, file.Contents);
}
//Git Operation
_gitService.InitializeRepository();
_gitService.AddChanges();
_gitService.CommitChanges("Commit Successful");
// Pass data to view
ViewBag.DslSummary = outputResult.DslSummary;
ViewBag.GeneratedFiles = outputResult.GeneratedFiles;
return View("Output");
}
}
}