// 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 async Task <IActionResult> Index(string imagePath, int maxWidth, int maxHeight) { // Validate incoming params if (maxWidth < 0 || maxHeight < 0 || maxWidth > MaxDimension || maxHeight > MaxDimension || (maxWidth + maxHeight) == 0) { return(BadRequest("Invalid dimensions")); } var mimeType = GetContentType(imagePath); if (Array.IndexOf(AllowedMimeTypes, mimeType) < 0) { return(BadRequest("Disallowed image format")); } // Locate source image on disk var fileInfo = _environment.WebRootFileProvider.GetFileInfo(imagePath); if (!fileInfo.Exists) { return(NotFound()); } // Invoke Node and pipe the result to the response var imageStream = await _nodeServices.Invoke <Stream>( "./Node/resizeImage", fileInfo.PhysicalPath, mimeType, maxWidth, maxHeight); return(File(imageStream, mimeType)); }
// 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?}"); }); }
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); }
// 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" }); }); }
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); }
// 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" }); }); }