Esempio n. 1
0
        public Task <string> RenderHtmlPageAsync(HttpContext context)
        {
            var requestFeature        = context.Features.Get <IHttpRequestFeature>();
            var unencodedPathAndQuery = requestFeature.RawTarget;

            var request = context.Request;
            var baseUrl = $"{request.Scheme}://{request.Host}";

            var props = new RenderFuncProps()
            {
                requestUrl    = unencodedPathAndQuery,
                baseUrl       = baseUrl,
                assets        = _assesResolver.ResolveAssets(context),
                inlineScripts = new[]
                {
                    new InlineScript()
                    {
                        position = "top",
                        script   = _telemetryProvider.GetCodeSnippet(),
                    },
                },
            };

            var objectArgs = new object[] { props };

            return(_jsService.InvokeFromFileAsync <JsonElement>(_options.Value.SsrScriptPath, "default", objectArgs)
                   .ContinueWith(task => task.Result.GetProperty("html").GetString()));
        }
Esempio n. 2
0
        public Task <string> RenderAsync(string url, object data)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                throw new System.ArgumentException($"{nameof(url)} must not be null or empty", nameof(url));
            }

            return(_nodeJSService.InvokeFromFileAsync <string>(_serverJsPath, args: new object[] { url, data }));
        }
        /// <summary>
        /// Withdraws using the metahash-js library on a NodeJS process.
        /// </summary>
        /// <param name="toAddress"></param>
        /// <param name="amount"></param>
        /// <returns>The transaction Id if succeeded, null if not</returns>
        public async Task <string> Withdraw(string toAddress, double amount)
        {
            var    privateKey    = _botConfiguration.Value.PrivateKey;
            var    mhcHashAmount = (amount * 1000000).ToString(CultureInfo.InvariantCulture);
            var    text          = "MetaBoyTipBot withdrawal";
            Result result        = await _nodeJsService.InvokeFromFileAsync <Result>(MainNodeFilePath, "sendTx", new object[] { privateKey, toAddress, mhcHashAmount, text });

            _logger.LogInformation($"Withdraw to {toAddress} for amount {amount} ({mhcHashAmount} hash): {result.Json}");
            return(result.TransactionId);
        }
Esempio n. 4
0
        public async Task Invoke(HttpContext context, INodeJSService nodeService)
        {
            if (IsRequestingAsyncApiIndex(context.Request))
            {
                using (var client = _httpClientFactory.CreateClient())
                    using (var response = await client.GetAsync($"{context.Request.Scheme}://{context.Request.Host.Value}/asyncapi/asyncapi.json"))
                    {
                        var asyncapiDocument = await response.Content.ReadAsStringAsync();

                        await nodeService.InvokeFromFileAsync($"{AppDomain.CurrentDomain.BaseDirectory}/app.js", args : new [] { asyncapiDocument, "AsyncApi" });
                    }
            }
            await _next(context);
        }
Esempio n. 5
0
        public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
        {
            var response = context.HttpContext.Response;
            var buffer   = new StringBuilder();


            var result = await _nodeJSService.InvokeFromFileAsync <string>("./render.js", args : new object[] { context.HttpContext.Request.Path.ToString(), "http://localhost:5000", context.Object });

            buffer.Append(result);

            // buffer.AppendLine("Hello " + context.HttpContext.Request.Path);

            await response.WriteAsync(buffer.ToString());
        }
Esempio n. 6
0
        public async Task <MjmlResponse> Render(object view, CancellationToken token)
        {
            var options = new MjmlRenderOptions
            {
                KeepComments = _options.DefaultKeepComments,
                Beautify     = _options.DefaultBeautify,
                Minify       = false // unsupported until we can re-add uglify
            };

            var args   = new[] { view, options };
            var result = await _nodeServices.InvokeFromFileAsync <MjmlResponse>(_renderer.FileName, null, args, token);

            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Renders the tree using ELK.js.
        /// </summary>
        private async Task <string> RenderTree(INodeJSService js, TreeLayoutVM tree, DynamicConfig cfg)
        {
            var thoroughness = Interpolator.MapValue(
                cfg.TreeRenderThoroughness,
                new IntervalMap(1, 10, 1, 10),
                new IntervalMap(11, 50, 11, 600),
                new IntervalMap(51, 100, 301, 15000)
                );

            var json   = JsonConvert.SerializeObject(tree);
            var result = await js.InvokeFromFileAsync <string>("./External/tree/tree-layout.js", args : new object[] { json, thoroughness });

            if (string.IsNullOrEmpty(result))
            {
                throw new Exception("Failed to render tree: output is empty.");
            }

            return(result);
        }
Esempio n. 8
0
            public async Task <TranspileResult> Handle(Transpile request, CancellationToken cancellationToken)
            {
                if (request.Source == null)
                {
                    return(new TranspileResult()
                    {
                        Code = "", Frontmatter = new Dictionary <string, string>()
                    });
                }
                var files = await ctx.MdxBundle.ToListAsync();

                Data result1 = await node
                               .InvokeFromFileAsync <Data>("./transpile-react.js", args : new object[] { request.Source, files })
                               .ConfigureAwait(false);

                return(new TranspileResult()
                {
                    Code = result1.Code, Frontmatter = result1.FrontMatter
                });
            }
        public async Task <IActionResult> IndexReact2()
        {
            var result = await _nodeJSService.InvokeFromFileAsync <string>("./render.js", args : new object[] { "/Home/IndexReact", "http://localhost:5000" });

            return(Content(result, "text/html"));
        }
Esempio n. 10
0
        public async Task Connect()
        {
            await node.InvokeFromFileAsync <string>(INTEROP_MODULE, "init");

            Listen();
        }
Esempio n. 11
0
 private Task <T> InvokeExportAsync <T>(string exportedFunctionName, params object[] args)
 {
     return(_nodeJSService.InvokeFromFileAsync <T>(_modulePath, exportedFunctionName, args));
 }