public static async Task Invoke(BrewOrder brewOrder, IBaristaRuntimeFactory baristaRuntimeFactory, IBaristaModuleLoader moduleLoader, Func <BaristaContext, JsValue, Task> processBrewResult) { //Brew: using (var rt = baristaRuntimeFactory.CreateRuntime()) using (var ctx = rt.CreateContext()) using (var scope = ctx.Scope()) { JsValue result = null; switch (brewOrder.Language) { case ResourceKind.Tsx: case ResourceKind.Jsx: result = ctx.EvaluateTypeScriptModule(brewOrder.Code, moduleLoader, true); break; case ResourceKind.TypeScript: result = ctx.EvaluateTypeScriptModule(brewOrder.Code, moduleLoader); break; case ResourceKind.Json: result = ctx.JSON.Parse(ctx.CreateString(brewOrder.Code)); break; case ResourceKind.JavaScript: result = ctx.EvaluateModule(brewOrder.Code, moduleLoader); break; } await processBrewResult?.Invoke(ctx, result); } }
public ComputeTheAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything() { var serviceCollection = new ServiceCollection(); serviceCollection.AddBaristaCore(); m_serviceProvider = serviceCollection.BuildServiceProvider(); m_runtimeFactory = m_serviceProvider.GetRequiredService <IBaristaRuntimeFactory>(); }
static BaristaFunction() { var serviceCollection = new ServiceCollection(); serviceCollection.AddBaristaCore(); var provider = serviceCollection.BuildServiceProvider(); s_baristaRuntimeFactory = provider.GetRequiredService <IBaristaRuntimeFactory>(); s_pipeline = new BaristaPipeline(); }
public TypeScriptTranspiler() { var myMemoryModuleLoader = new InMemoryModuleLoader(); myMemoryModuleLoader.RegisterModule(new TypeScriptModule()); var serviceCollection = new ServiceCollection(); serviceCollection.AddBaristaCore(moduleLoader: myMemoryModuleLoader); m_provider = serviceCollection.BuildServiceProvider(); m_runtimeFactory = m_provider.GetRequiredService <IBaristaRuntimeFactory>(); }
public HttpResponseMessage Brew(BrewOrder brewOrder, IBaristaRuntimeFactory baristaRuntimeFactory, IBaristaModuleLoader moduleLoader) { if (brewOrder == null) { throw new ArgumentNullException(nameof(brewOrder)); } if (baristaRuntimeFactory == null) { throw new ArgumentNullException(nameof(baristaRuntimeFactory)); } //Brew: HttpResponseMessage responseMessage = null; BrewMiddleware.Invoke(brewOrder, baristaRuntimeFactory, moduleLoader, (ctx, brewResult) => { responseMessage = Serve(ctx, brewResult); return(Task.CompletedTask); }).GetAwaiter().GetResult(); return(responseMessage); }
public BrewMiddleware(RequestDelegate next, IBaristaRuntimeFactory baristaRuntimeFactory) { m_next = next; m_baristaRuntimeFactory = baristaRuntimeFactory; }