コード例 #1
0
        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);
                    }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: lvyitian/BaristaCore
        public ComputeTheAnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddBaristaCore();

            m_serviceProvider = serviceCollection.BuildServiceProvider();
            m_runtimeFactory  = m_serviceProvider.GetRequiredService <IBaristaRuntimeFactory>();
        }
コード例 #3
0
        static BaristaFunction()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddBaristaCore();

            var provider = serviceCollection.BuildServiceProvider();

            s_baristaRuntimeFactory = provider.GetRequiredService <IBaristaRuntimeFactory>();
            s_pipeline = new BaristaPipeline();
        }
コード例 #4
0
        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>();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public BrewMiddleware(RequestDelegate next, IBaristaRuntimeFactory baristaRuntimeFactory)
 {
     m_next = next;
     m_baristaRuntimeFactory = baristaRuntimeFactory;
 }