Using Html/Pdf Initializer
This commit is contained in:
31
WGneu/Documents/Html.cs
Normal file
31
WGneu/Documents/Html.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using RazorLight;
|
||||
using RazorLight.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGneu.Documents {
|
||||
public static class Html {
|
||||
private static RazorLightEngine? Engine = null;
|
||||
public static bool IsReady => Engine != null;
|
||||
|
||||
public static async Task Init(Action evtHandler) {
|
||||
var e = new RazorLightEngineBuilder()
|
||||
.UseFileSystemProject(@"C:\Users\Lorenz\source\repos\WGneu\WGneu\Documents")
|
||||
.UseMemoryCachingProvider()
|
||||
.Build();
|
||||
|
||||
await e.CompileTemplateAsync("BusinessLetter");
|
||||
|
||||
Engine = e;
|
||||
evtHandler();
|
||||
}
|
||||
|
||||
public static async Task<string> CompileRenderAsync(string key, object model) {
|
||||
if (Engine == null) throw new InvalidOperationException("The razor engine has not been initialized yet");
|
||||
return await Engine.CompileRenderAsync(key, model);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user