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); } }
// 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); }
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; } }
public HomeController(INodeServices nodeServices, IViewRenderService viewRenderService) { this.nodeServices = nodeServices; this.viewRenderService = viewRenderService; }
protected AccountBaseController(ILoggerFactory loggerFactory, Cache cache, IServiceProvider serviceProvider, INodeServices nodeServices) : base(loggerFactory, cache, serviceProvider, nodeServices) { }
public AdvisorV1Controller(ILoggerFactory loggerFactory, Cache cache, IServiceProvider serviceProvider, INodeServices nodeServices) : base(loggerFactory, cache, serviceProvider, nodeServices) { }
public VideoConverter(INodeServices nodeServices) { _nodeServices = nodeServices; }
public ValuesController(INodeServices nodeService) { _nodeService = nodeService; }
public NeoBlockchainRepository( INodeServices _nodeServices) { nodeServices = _nodeServices; }
public JavaScriptCompileHelper(INodeServices NodeServices) { if (NodeServices == null) { throw new ArgumentNullException(nameof(NodeServices)); } this.nodeServices = NodeServices; }
public HomeController(INodeServices nodeServices) { this.nodeServices = nodeServices; }
public RenderService(INodeServices nodeServices) { _nodeServices = nodeServices; }
public ValuesController(INodeServices nodeServices) { this.nodeServices = nodeServices; }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { _nodeServices?.Dispose(); _nodeServices = null; }
// 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}"); }); }
public AuthenticateController(ServerDBContext context, INodeServices _nodeServices) { db = context; nodeServices = _nodeServices; }
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()); }
public BemhtmlMiddleware(RequestDelegate next, INodeServices node) { this.next = next; this.node = node; }
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"))); }
public LoginController(INodeServices service) { _services = service; }
public TemplateService(INodeServices nodeServices) { _nodeServices = nodeServices; }
public async Task <IActionResult> MyAction([FromServices] INodeServices nodeServices) { var r = await nodeServices.InvokeAsync <int>("./addNumbers", 1, 2); return(Content("1 + 2 = " + r)); }
// 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?}"); }); }
public GoalOptionBusiness(ILoggerFactory loggerFactory, Cache cache, INodeServices nodeServices) : base(loggerFactory, cache, nodeServices) { }
internal static void Init(INodeServices nodeServices) { _instance = new NodePluginBridge(nodeServices); }
public MarkdownCompiler(IPathResolver pathResolver) { _scriptsDirectory = new TempScriptDirectory(); _nodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, _scriptsDirectory.TempDirectory); }
public ResizeImageController(IHostingEnvironment environment, INodeServices nodeServices) { _environment = environment; _nodeServices = nodeServices; }
// 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; }
public CachedTemplateService(INodeServices nodeServices, IMemoryCache memoryCache) { _nodeServices = nodeServices; _memoryCache = memoryCache; }
public encryptPwd(INodeServices _nodeServices) { nodeServices = _nodeServices; }
public PdfProvider(INodeServices nodeServices) { _nodeServices = nodeServices; }
/// <summary> /// Create controller with service /// </summary> /// <param name="nodes"></param> public WriteController(INodeServices <string> nodes) { _nodes = nodes; }
public BaseProcessor(INodeServices nodeServices) { NodeServices = nodeServices; }