コード例 #1
0
        public static void UseScriptConsole(this IApplicationBuilder app, IServiceCollection theServices)
        {
            var appS = app.ApplicationServices;
            var scriptManager = new ScriptManager();

            var services = new ServiceCollection();
            services.Clear();
            foreach (var s in theServices)
               services.Insert(0, s);

            services.AddInstance<ScriptManager>(scriptManager);
            var fp = new DebugFileProvider(new EmbeddedFileProvider(typeof(ScriptConsoleBuilderExtensions).Assembly, "ScriptConsole"));

            services
                .AddMvc()
                .AddControllersAsServices(new[] { typeof(ScriptConsoleController), typeof(HomeController) })
                .AddRazorOptions(r => r.FileProvider = fp);

            services.AddLogging();
            var provider = services.BuildServiceProvider();

            app.Map("/ScriptConsole", builder =>
            {
                var routeBuilder = new RouteBuilder()
                {
                    DefaultHandler = new MvcRouteHandler(),
                    ServiceProvider = new ShadowedServiceProvider(provider, app.ApplicationServices)
                };
                routeBuilder.MapRoute("ScriptConsole", "{action}", new { controller = "ScriptConsole", action = "Index" });
                routeBuilder.MapRoute("ScriptConsoleX", "{controller}/{action}", new { controller = "ScriptConsole", action = "Index" });

                var route = routeBuilder.Build();
                builder.Use(next =>
                {
                    return async (context) =>
                    {
                        context.ApplicationServices = new ShadowedServiceProvider(provider, context.ApplicationServices);
                        context.RequestServices = new ShadowedServiceProvider(provider, context.RequestServices);
                        await route.RouteAsync(new RouteContext(context));
                    };
                });

            });
        }
コード例 #2
0
        public ScriptExecutionContext(ScriptManager manager, int id)
        {
            this.Id = id;
            this.scriptIdx = 0;
            this.manager = manager;
            this.executions = new List<ScriptExecutionInfo>();
            this.runningScripts = new HashSet<ScriptExecutionInfo>();

            this.setup = new ScriptRuntimeSetup();

            setup.LanguageSetups.Add(Python.CreateLanguageSetup(new Dictionary<string, object>()));

            this.Runtime = new ScriptRuntime(setup);
            this.output = new SharedMemoryStream();
            this.Runtime.IO.SetOutput(this.output, Encoding.UTF8);

            this.Engine = Runtime.GetEngine("python");

            this.scope = Engine.CreateScope();
        }