feat: 在前端显示编译过程中的日志 (#67)

Reviewed-on: PostGuard/Canon#67
This commit is contained in:
2024-04-29 23:55:36 +08:00
parent 4d325569fa
commit 911c813996
15 changed files with 243 additions and 204 deletions

View File

@@ -4,15 +4,10 @@ using MongoDB.EntityFrameworkCore.Extensions;
namespace Canon.Server.Services;
public class CompileDbContext : DbContext
public class CompileDbContext(DbContextOptions<CompileDbContext> options) : DbContext(options)
{
public DbSet<CompileResult> CompileResults { get; init; }
public CompileDbContext(DbContextOptions<CompileDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

View File

@@ -13,6 +13,8 @@ public class CompilerService(
ILexer lexer,
IGrammarParser grammarParser,
SyntaxTreeTraveller traveller,
CCodeGenerateVisitor visitor,
ICompilerLogger compilerLogger,
CompileDbContext dbContext,
GridFsService gridFsService,
SyntaxTreePresentationService syntaxTreePresentationService,
@@ -39,7 +41,6 @@ public class CompilerService(
await using Stream imageStream = syntaxTreePresentationService.Present(root);
string filename = await gridFsService.UploadStream(imageStream, "image/png");
CCodeGenerateVisitor visitor = new();
traveller.Travel(root, visitor);
CompileResult result = new()
@@ -48,7 +49,8 @@ public class CompilerService(
CompileId = Guid.NewGuid().ToString(),
CompiledCode = visitor.Builder.Build(),
SytaxTreeImageFilename = filename,
CompileTime = DateTime.Now
CompileTime = DateTime.Now,
CompileInformation = compilerLogger.Build()
};
await dbContext.CompileResults.AddAsync(result);