public static async Task<RenderToStringResult> RenderToString(string applicationBasePath, INodeServices nodeServices, JavaScriptModuleExport bootModule, string requestAbsoluteUrl, string requestPathAndQuery) {
     return await nodeServices.InvokeExport<RenderToStringResult>(nodeScript.Value.FileName, "renderToString",
         applicationBasePath,
         bootModule,
         requestAbsoluteUrl,
         requestPathAndQuery);
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env, INodeServices nodeServices)
        {
            app.UseDeveloperExceptionPage();

            // Dynamically transpile any .js files under the '/js/' directory
            app.Use(next => async context => {
                var requestPath = context.Request.Path.Value;
                if (requestPath.StartsWith("/js/") && requestPath.EndsWith(".js")) {
                    var fileInfo = env.WebRootFileProvider.GetFileInfo(requestPath);
                    if (fileInfo.Exists) {
                        var transpiled = await nodeServices.Invoke<string>("./Node/transpilation.js", fileInfo.PhysicalPath, requestPath);
                        await context.Response.WriteAsync(transpiled);
                        return;
                    }
                }

                // Not a JS file, or doesn't exist - let some other middleware handle it
                await next.Invoke(context);
            });

            app.UseStaticFiles();
            loggerFactory.AddConsole();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
 public static async Task<string> RenderToString(INodeServices nodeServices, string componentModuleName, string componentExportName, string requestUrl) {
     return await nodeServices.InvokeExport<string>(nodeScript.FileName, "renderToString", new {
         moduleName = componentModuleName,
         exportName = componentExportName,
         requestUrl = requestUrl
     });
 }
 public ReactPrerenderTagHelper(IServiceProvider nodeServices, IHttpContextAccessor contextAccessor)
 {
     this.contextAccessor = contextAccessor;
     this.nodeServices = (INodeServices)nodeServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
     
     // Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
     // in your startup file, but then again it might be confusing that you don't need to.
     if (this.nodeServices == null) {
         this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http);
     }
 }
 public AngularPrerenderTagHelper(IServiceProvider serviceProvider, IHttpContextAccessor contextAccessor)
 {
     this.contextAccessor = contextAccessor;
     this.nodeServices = (INodeServices)serviceProvider.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
     
     // Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
     // in your startup file, but then again it might be confusing that you don't need to.
     if (this.nodeServices == null) {
         var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof (IApplicationEnvironment));
         this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, appEnv.ApplicationBasePath);
     }
 }
Beispiel #6
0
        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, INodeServices nodeServices)
        {
            loggerFactory.MinimumLevel = LogLevel.Warning;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            // Configure the HTTP request pipeline.

            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();

            // Add the following to the request pipeline only in development environment.
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // send the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }
            
            // Dynamically transpile any .js files under the '/js/' directory
            app.Use(next => async context => {
                var requestPath = context.Request.Path.Value;
                if (requestPath.StartsWith("/js/") && requestPath.EndsWith(".js")) {
                    var fileInfo = env.WebRootFileProvider.GetFileInfo(requestPath); 
                    if (fileInfo.Exists) {
                        var transpiled = await nodeServices.Invoke<string>("transpilation.js", fileInfo.PhysicalPath, requestPath);
                        await context.Response.WriteAsync(transpiled);
                        return;
                    }
                }
                
                // Not a JS file, or doesn't exist - let some other middleware handle it
                await next.Invoke(context);
            });
            
            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action?}/{id?}",
                    defaults: new { controller="Home", action = "Index" });
            });
        }
        static INodeServices fallbackNodeServices; // Used only if no INodeServices was registered with DI

        public static void UseWebpackDevMiddleware(this IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options = null) {
            // Validate options
            if (options != null) {
                if (options.ReactHotModuleReplacement && !options.HotModuleReplacement) {
                    throw new ArgumentException("To enable ReactHotModuleReplacement, you must also enable HotModuleReplacement.");
                }
            }

            // Get the NodeServices instance from DI
            var nodeServices = (INodeServices)appBuilder.ApplicationServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
            
            // Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
            // in your startup file, but then again it might be confusing that you don't need to.
            var appEnv = (IApplicationEnvironment)appBuilder.ApplicationServices.GetService(typeof(IApplicationEnvironment));
            if (nodeServices == null) {
                nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, appEnv.ApplicationBasePath);
            }
            
            // Get a filename matching the middleware Node script
            var script = EmbeddedResourceReader.Read(typeof (WebpackDevMiddleware), "/Content/Node/webpack-dev-middleware.js");
            var nodeScript = new StringAsTempFile(script); // Will be cleaned up on process exit

            // Tell Node to start the server hosting webpack-dev-middleware
            var devServerOptions = new {
                webpackConfigPath = Path.Combine(appEnv.ApplicationBasePath, "webpack.config.js"),
                suppliedOptions = options ?? new WebpackDevMiddlewareOptions()
            };
            var devServerInfo = nodeServices.InvokeExport<WebpackDevServerInfo>(nodeScript.FileName, "createWebpackDevServer", JsonConvert.SerializeObject(devServerOptions)).Result;

            // Proxy the corresponding requests through ASP.NET and into the Node listener 
            appBuilder.Map(devServerInfo.PublicPath, builder => {
                builder.RunProxy(new ProxyOptions {
                    Host = WebpackDevMiddlewareHostname,
                    Port = devServerInfo.Port.ToString()
                });
            });
            
            // While it would be nice to proxy the /__webpack_hmr requests too, these return an EventStream,
            // and the Microsoft.Aspnet.Proxy code doesn't handle that entirely - it throws an exception after
            // a while. So, just serve a 302 for those.
            appBuilder.Map(WebpackHotMiddlewareEndpoint, builder => {
                builder.Use(next => async ctx => {
                    ctx.Response.Redirect($"http://localhost:{ devServerInfo.Port.ToString() }{ WebpackHotMiddlewareEndpoint }");
                    await Task.Yield();
                });
            });
        }
 public static Task<RenderToStringResult> RenderToString(
     string applicationBasePath,
     INodeServices nodeServices,
     JavaScriptModuleExport bootModule,
     string requestAbsoluteUrl,
     string requestPathAndQuery,
     object customDataParameter)
 {
     return nodeServices.InvokeExport<RenderToStringResult>(
         NodeScript.Value.FileName,
         "renderToString",
         applicationBasePath,
         bootModule,
         requestAbsoluteUrl,
         requestPathAndQuery,
         customDataParameter);
 }
        public PrerenderTagHelper(IServiceProvider serviceProvider)
        {
            var hostEnv = (IHostingEnvironment) serviceProvider.GetService(typeof(IHostingEnvironment));
            _nodeServices = (INodeServices) serviceProvider.GetService(typeof(INodeServices)) ?? _fallbackNodeServices;
            _applicationBasePath = hostEnv.ContentRootPath;

            // Consider removing the following. Having it means you can get away with not putting app.AddNodeServices()
            // in your startup file, but then again it might be confusing that you don't need to.
            if (_nodeServices == null)
            {
                _nodeServices = _fallbackNodeServices = Configuration.CreateNodeServices(new NodeServicesOptions
                {
                    HostingModel = Configuration.DefaultNodeHostingModel,
                    ProjectPath = _applicationBasePath
                });
            }
        }
        private static async Task MeasureLatency(INodeServices nodeServices) {
            // Ensure the connection is open, so we can measure per-request timings below
            var response = await nodeServices.Invoke<string>("latencyTest", "C#");
            Console.WriteLine(response);

            // Now perform a series of requests, capturing the time taken
            const int requestCount = 100;
            var watch = Stopwatch.StartNew();
            for (var i = 0; i < requestCount; i++) {
                await nodeServices.Invoke<string>("latencyTest", "C#");
            }

            // Display results
            var elapsedSeconds = (float)watch.ElapsedTicks / Stopwatch.Frequency;
            Console.WriteLine("\nTotal time: {0:F2} milliseconds", 1000 * elapsedSeconds);
            Console.WriteLine("\nTime per invocation: {0:F2} milliseconds", 1000 * elapsedSeconds / requestCount);
        }
Beispiel #11
0
        public void Dispose()
        {
            if (_nodeServices != null)
            {
                _nodeServices.Dispose();
                _nodeServices = null;
                // the node services doesn't "WaitForExit". it should though.
                // this should be enough time for the process to fully exit.
                Thread.Sleep(TimeSpan.FromSeconds(.5));
            }

            if (_scriptsDirectory != null)
            {
                _scriptsDirectory.Dispose();
                _scriptsDirectory = null;
            }
        }
Beispiel #12
0
 public HomeController(INodeServices nodeServices, IViewRenderService viewRenderService)
 {
     this.nodeServices      = nodeServices;
     this.viewRenderService = viewRenderService;
 }
Beispiel #13
0
 protected AccountBaseController(ILoggerFactory loggerFactory, Cache cache, IServiceProvider serviceProvider, INodeServices nodeServices) : base(loggerFactory, cache, serviceProvider, nodeServices)
 {
 }
Beispiel #14
0
 public AdvisorV1Controller(ILoggerFactory loggerFactory, Cache cache, IServiceProvider serviceProvider, INodeServices nodeServices) : base(loggerFactory, cache, serviceProvider, nodeServices)
 {
 }
Beispiel #15
0
 public VideoConverter(INodeServices nodeServices)
 {
     _nodeServices = nodeServices;
 }
Beispiel #16
0
 public ValuesController(INodeServices nodeService)
 {
     _nodeService = nodeService;
 }
Beispiel #17
0
 public NeoBlockchainRepository(
     INodeServices _nodeServices)
 {
     nodeServices = _nodeServices;
 }
 public JavaScriptCompileHelper(INodeServices NodeServices) {
     if (NodeServices == null) {
         throw new ArgumentNullException(nameof(NodeServices));
     }
     this.nodeServices = NodeServices;
 }
Beispiel #19
0
 public HomeController(INodeServices nodeServices)
 {
     this.nodeServices = nodeServices;
 }
Beispiel #20
0
 public RenderService(INodeServices nodeServices)
 {
     _nodeServices = nodeServices;
 }
 public ValuesController(INodeServices nodeServices)
 {
     this.nodeServices = nodeServices;
 }
Beispiel #22
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     _nodeServices?.Dispose();
     _nodeServices = null;
 }
Beispiel #23
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, INodeServices node)
        {
            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Run(async(context) =>
            {
                var result = node.InvokeAsync <int>("./node/node", 1, 2).Result;
                await context.Response.WriteAsync($"Hello World!{result}");
            });
        }
Beispiel #24
0
 public AuthenticateController(ServerDBContext context, INodeServices _nodeServices)
 {
     db           = context;
     nodeServices = _nodeServices;
 }
Beispiel #25
0
 public ElmRenderTagHelper(INodeServices _nodeServices)
 {
     nodeServices = _nodeServices;
 }
        public async Task <IActionResult> Index([FromServices] INodeServices nodeServices)
        {
            ViewData["ResultFromNode"] = await nodeServices.InvokeAsync <string>("./angular/server.js", Request.Path);

            return(View());
        }
Beispiel #27
0
 public BemhtmlMiddleware(RequestDelegate next, INodeServices node)
 {
     this.next = next;
     this.node = node;
 }
Beispiel #28
0
 private static async Task <string> DoLogin(INodeServices nodeService)
 {
     //Invoke the javascript module with parameters to execute in Node environment.
     return(await nodeService.InvokeAsync <string>(Path.Combine(System.AppContext.BaseDirectory, "scripts", "auth.js")));
 }
Beispiel #29
0
 public LoginController(INodeServices service)
 {
     _services = service;
 }
Beispiel #30
0
 public TemplateService(INodeServices nodeServices)
 {
     _nodeServices = nodeServices;
 }
Beispiel #31
0
        public async Task <IActionResult> MyAction([FromServices] INodeServices nodeServices)
        {
            var r = await nodeServices.InvokeAsync <int>("./addNumbers", 1, 2);

            return(Content("1 + 2 = " + r));
        }
Beispiel #32
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env, INodeServices nodeServices)
        {
            app.UseDeveloperExceptionPage();

            // Dynamically transpile any .js files under the '/js/' directory
            app.Use(next => async context => {
                var requestPath = context.Request.Path.Value;
                if (requestPath.StartsWith("/js/") && requestPath.EndsWith(".js"))
                {
                    var fileInfo = env.WebRootFileProvider.GetFileInfo(requestPath);
                    if (fileInfo.Exists)
                    {
                        var transpiled = await nodeServices.InvokeAsync <string>("./Node/transpilation.js", fileInfo.PhysicalPath, requestPath);
                        await context.Response.WriteAsync(transpiled);
                        return;
                    }
                }

                // Not a JS file, or doesn't exist - let some other middleware handle it
                await next.Invoke(context);
            });

            app.UseStaticFiles();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Beispiel #33
0
 public GoalOptionBusiness(ILoggerFactory loggerFactory, Cache cache, INodeServices nodeServices) : base(loggerFactory, cache, nodeServices)
 {
 }
 internal static void Init(INodeServices nodeServices)
 {
     _instance = new NodePluginBridge(nodeServices);
 }
Beispiel #35
0
 public MarkdownCompiler(IPathResolver pathResolver)
 {
     _scriptsDirectory = new TempScriptDirectory();
     _nodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, _scriptsDirectory.TempDirectory);
 }
 public ResizeImageController(IHostingEnvironment environment, INodeServices nodeServices)
 {
     _environment = environment;
     _nodeServices = nodeServices;
 }
Beispiel #37
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, GameData gameData, INodeServices node)
        {
            // Calculate score for solution for each assignment
            gameData.Threads.Where(t => t.Assignment != null).Select(t => t.Assignment).ToList().ForEach(a => a.CalculateAssignmentScore(node));

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
                    HotModuleReplacement      = true,
                    ReactHotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseAuthentication();

            app.UseSession();
            app.UseMvc(routes => {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
                routes.MapRoute(
                    name: "api",
                    template: "api/{controller=Home}/{action=Index}/{id?}");
            });

            // Workaround for SPA letting requests under /api return 404
            app.MapWhen(x => !x.Request.Path.Value.StartsWith("/api"), builder => {
                builder.UseMvc(routes => {
                    routes.MapSpaFallbackRoute(
                        name: "spa-fallback",
                        defaults: new { controller = "Home", action = "Index" });
                });
            });
        }
 public BibliographyProcessor(INodeServices nodeServices) : base(nodeServices)
 {
     _overrideManager = new PA.OverrideManager();
 }
 private NodePluginBridge(INodeServices nodeServices)
 {
     _nodeService = nodeServices;
 }
Beispiel #40
0
 public CachedTemplateService(INodeServices nodeServices, IMemoryCache memoryCache)
 {
     _nodeServices = nodeServices;
     _memoryCache  = memoryCache;
 }
Beispiel #41
0
 public encryptPwd(INodeServices _nodeServices)
 {
     nodeServices = _nodeServices;
 }
Beispiel #42
0
 public PdfProvider(INodeServices nodeServices)
 {
     _nodeServices = nodeServices;
 }
 /// <summary>
 /// Create controller with service
 /// </summary>
 /// <param name="nodes"></param>
 public WriteController(INodeServices <string> nodes)
 {
     _nodes = nodes;
 }
Beispiel #44
0
 public BaseProcessor(INodeServices nodeServices)
 {
     NodeServices = nodeServices;
 }