Exemple #1
0
        public void Configure(IApplicationBuilder app)
        {
            app.UseWebSockets();
            app.UseDotNetify(c => c.UseDeveloperLogging());

#pragma warning disable 618
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true,
                HotModuleReplacementClientOptions = new Dictionary <string, string> {
                    { "reload", "true" }
                },
            });
#pragma warning restore 618

            app.UseStaticFiles();
            app.UseRouting();

            app.UseEndpoints(endpoints => endpoints.MapHub <DotNetifyHub>("/dotnetify"));
            app.UseSsr(typeof(App), (string[] args) => StaticNodeJSService.InvokeFromFileAsync <string>("wwwroot/ssr", null, args));

            app.Run(async(context) =>
            {
                // Client-side rendering.
                using (var reader = new StreamReader(File.OpenRead("wwwroot/index.html")))
                    await context.Response.WriteAsync(reader.ReadToEnd());
            });
        }
        public async void InvokeFromFileAsync_WithTypeParameter_InvokesFromFile()
        {
            // Arrange
            const int             dummyResult            = 1;
            const string          dummyModulePath        = "dummyModulePath";
            const string          dummyExportName        = "dummyExportName";
            var                   dummyArgs              = new object[0];
            var                   dummyCancellationToken = new CancellationToken();
            Mock <INodeJSService> mockNodeJSService      = _mockRepository.Create <INodeJSService>();

            mockNodeJSService.
            Setup(t => t.InvokeFromFileAsync <int>(dummyModulePath, dummyExportName, dummyArgs, dummyCancellationToken)).
            ReturnsAsync(dummyResult);
            var dummyServices = new ServiceCollection();

            dummyServices.AddSingleton(typeof(INodeJSService), mockNodeJSService.Object);
            StaticNodeJSService.SetServices(dummyServices);

            // Act
            int result = await StaticNodeJSService.InvokeFromFileAsync <int>(dummyModulePath, dummyExportName, dummyArgs, dummyCancellationToken).ConfigureAwait(false);

            // Assert
            _mockRepository.VerifyAll();
            Assert.Equal(dummyResult, result);
        }
Exemple #3
0
        public static async Task <T> InvokeNode <T>(BotData data, string scriptFile, object[] parameters)
        {
            data.Logger.LogHeader();
            var result = await StaticNodeJSService.InvokeFromFileAsync <T>(scriptFile, null, parameters, data.CancellationToken);

            data.Logger.Log($"Executed NodeJS script with result: {result}", LogColors.PaleChestnut);
            return(result);
        }
        public async void InvokeFromFileAsync_InvokesJavascript()
        {
            // Arrange
            const string dummyResultString = "success";

            // Act
            DummyResult result = await StaticNodeJSService.
                                 InvokeFromFileAsync <DummyResult>("dummyModule.js", args : new[] { dummyResultString }).ConfigureAwait(false);

            // Assert
            Assert.Equal(dummyResultString, result.Result);
        }
Exemple #5
0
        public void Configure(IApplicationBuilder app)
        {
            app.UseWebSockets();
            app.UseDotNetify(c => c.UseDeveloperLogging());

#pragma warning disable 618
            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
            {
                HotModuleReplacement = true,
                HotModuleReplacementClientOptions = new Dictionary <string, string> {
                    { "reload", "true" }
                },
            });
#pragma warning restore 618

            app.UseStaticFiles();
            app.UseRouting();
            app.UseEndpoints(endpoints => endpoints.MapHub <DotNetifyHub>("/dotnetify"));

            app.UseSsr(typeof(App), (string[] args) => StaticNodeJSService.InvokeFromFileAsync <string>("wwwroot/ssr", null, args), DefaultRequestHandler);

            // Client-side rendering.
            app.Run(DefaultRequestHandler);
        }
Exemple #6
0
 public Task InvokeFromFileAsync(string modulePath, string exportName = null, object[] args = null, CancellationToken cancellationToken = default)
 {
     return(StaticNodeJSService.InvokeFromFileAsync(modulePath, exportName, args, cancellationToken));
 }
        public NodeJS_ASTWrapper(
            string source
            )
        {
            var nodeJSPath = Path.Combine(
                Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location
                    ),
                "AstParser",
                "NodeImpl",
                "NodeJS"
                );
            var nodeModulesPath = Path.Combine(
                nodeJSPath,
                "node_modules"
                );
            var indexJSPath = Path.Combine(
                nodeJSPath,
                "index.js"
                );

            // Check for existing node_modules, install if needed
            if (!Directory.Exists(
                    nodeModulesPath
                    ))
            {
                var cmdProcessInfo = new ProcessStartInfo
                {
                    FileName         = "npm",
                    WorkingDirectory = nodeJSPath,
                    UseShellExecute  = true,
                    Arguments        = "install",
                };
                var cmdProcess = Process.Start(
                    cmdProcessInfo
                    );
                cmdProcess.WaitForExit();
            }

            var result = StaticNodeJSService.InvokeFromFileAsync <string>(
                indexJSPath,
                args: new object[]
            {
                source
            }
                ).GetAwaiter().GetResult();

            // Use for testing the generated AST
            //File.WriteAllText(
            //    Path.Combine(
            //        ".",
            //        "AstParser",
            //        "NodeImpl",
            //        "NodeJS",
            //        "_generated",
            //        "ast.json"
            //    ),
            //    result
            //);
            var ast = JsonSerializer.Deserialize <ASTModel>(
                result,
                new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true,
            }
                );

            RootNode = new NodeJS_Node(
                ast.Program
                );
        }
 /// <summary>
 /// Print to pdf.
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 protected virtual async Task Print(params object[] args)
 {
     await StaticNodeJSService.InvokeFromFileAsync(_module, _method, args);
 }