public async Task <List <T> > Data <T>() { string tx = JsonConvert.SerializeObject(_transformSteps); string nodeResponse; // Collection Chaining if (_dynamicViewName == null) { nodeResponse = await _nodeServices.InvokeExportAsync <string>(_databaseConfiguration.ServicePath, "transformRaw", _databaseConfiguration.ServiceInitPath, _databaseConfiguration.DatabaseInstancePath, _collection, tx, null, true); } // Dynamic View (branchResultset) chaining else { //var txParamString = ""; nodeResponse = await _nodeServices.InvokeExportAsync <string>(_databaseConfiguration.ServicePath, "dynamicViewTransform", _databaseConfiguration.ServiceInitPath, _databaseConfiguration.DatabaseInstancePath, _collection, _dynamicViewName, _transformName, _transformParams, tx); } List <T> typedObjects = JsonConvert.DeserializeObject <List <T> >(nodeResponse); return(typedObjects); }
public async Task ProcessNodeData([FromServices] INodeServices nodeServices) { var climateDataRaw = await nodeServices.InvokeExportAsync <ClimateDataRaw[]>(VeriSureAppFilePath, "sendClimateData"); var alarmData = await nodeServices.InvokeExportAsync <AlarmStatus>(VeriSureAppFilePath, "sendAlarmStatus"); ClimateData[] climateData = new ClimateData[climateDataRaw.Length]; for (int i = 0; i < climateDataRaw.Length; i++) { climateData[i] = new ClimateData(); climateData[i].Temperature = float.Parse(climateDataRaw[i].Temperature.Remove(climateDataRaw[i].Temperature.IndexOf('&'))); if (climateDataRaw[i].Humidity.Equals(string.Empty)) { climateData[i].Humidity = 0; } else { climateData[i].Humidity = float.Parse(climateDataRaw[i].Humidity.Remove(climateDataRaw[i].Humidity.IndexOf('%'))); } climateData[i].Location = climateDataRaw[i].Location; climateData[i].Timestamp = climateDataRaw[i].Timestamp.Replace("Today", "I dag"); } ViewData["ClimateData"] = climateData; ViewData["AlarmStatusDate"] = alarmData.Date.Replace("Today", "I dag"); ViewData["AlarmStatus"] = alarmData.Status; ViewData["AlarmUser"] = alarmData.Name; ViewData["AlarmLabel"] = alarmData.Label; AlarmTime = alarmData.Date; }
public async Task <IActionResult> ContractPrice( [FromServices] INodeServices node, //[FromServices] KyubeyContext db, [FromServices] ITokenRepository _tokenRepository, [FromServices] IConfiguration config, string id, CancellationToken token) { try { using (var txClient = new HttpClient { BaseAddress = new Uri(config["TransactionNode"]) }) { var currentTokenInfo = _tokenRepository.GetOne(id); var currentPriceJavascript = _tokenRepository.GetPriceJsText(id); using (var tableResponse = await txClient.PostAsJsonAsync("/v1/chain/get_table_rows", new { code = currentTokenInfo.Basic.Contract.Pricing, scope = currentTokenInfo.Basic.Price_Scope, table = currentTokenInfo.Basic.Price_Table, json = true })) { if (string.IsNullOrWhiteSpace(currentTokenInfo.Basic.Price_Scope) || string.IsNullOrWhiteSpace(currentTokenInfo.Basic.Price_Scope)) { return(Json(new { BuyPrice = 0, SellPrice = 0 })); } var text = await tableResponse.Content.ReadAsStringAsync(); var rows = JsonConvert.DeserializeObject <Table>(text).rows; var buy = await node.InvokeExportAsync <string>("./price", "buyPrice", rows, currentPriceJavascript); var sell = await node.InvokeExportAsync <string>("./price", "sellPrice", rows, currentPriceJavascript); var buyPrice = Convert.ToDouble(buy.Contains(".") ? buy.TrimEnd('0') : buy); var sellPrice = Convert.ToDouble(sell.Contains(".") ? sell.TrimEnd('0') : sell); return(Json(new { BuyPrice = buyPrice, SellPrice = sellPrice })); } } } catch (Exception e) { Console.WriteLine(e); throw e; } }
public async Task <IActionResult> MultipleFunctions() { var result1 = await _nodeServices.InvokeExportAsync <string>("./ServerSideJs/multipleFunctions", "returnFive"); var result2 = await _nodeServices.InvokeExportAsync <string>("./ServerSideJs/multipleFunctions", "returnTen"); return(View(new MultipleFunctionsViewModel { DataFromFunction1 = result1, DataFromFunction2 = result2 })); }
public void StartServer() { if (_started) { return; } object options = CreateOptions(); _nodeServices.InvokeExportAsync <object>(_modulePath, "start", options).GetAwaiter().GetResult(); _started = true; }
public IActionResult Invite() { string ethAddr = User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value; var id = nodeServices.InvokeExportAsync <string>("wwwroot/Scripts/Telegram.js", "getId", ethAddr).Result; //var callbackUrl = Url.Action("Login", "Account", new { refId = id }, protocol: HttpContext.Request.Scheme); //ViewBag.callbackUrl = callbackUrl; if (id == "0") { return(Content("Please Join on Coinpay.CR Affiliate Game to get your Referral Link")); } return(View("Invite", id)); }
public async Task SimpleMethodCallWorks() { await initTask; var result = await nodeServices.InvokeExportAsync <int>("binding-test", "testMethod1", 2); Assert.Equal(3, result); }
public async Task RenderAsync(ViewContext context) { var fileInfo = new FileInfo(Path); var html = await _nodeServices.InvokeExportAsync <string>("./art-template", "render", fileInfo.FullName, context.ViewData.Model); context.Writer.Write(html); }
/// <summary> /// Performs server-side EmPage prerendering by invoking code in Node.js. /// </summary> /// <param name="applicationBasePath"></param> /// <param name="nodeServices"></param> /// <param name="applicationStoppingToken"></param> /// <param name="serverBundlePath"></param> /// <param name="httpContext"></param> /// <param name="customDataParameter"></param> /// <param name="timeoutMilliseconds"></param> /// <returns></returns> public static async Task <RenderToStringResult> RenderToString( string applicationBasePath, INodeServices nodeServices, CancellationToken applicationStoppingToken, string serverBundlePath, HttpContext httpContext, object customDataParameter, int timeoutMilliseconds) { var requestFeature = httpContext.Features.Get <IHttpRequestFeature>(); var unencodedPathAndQuery = requestFeature.RawTarget; var request = httpContext.Request; var unencodedAbsoluteUrl = $"{request.Scheme}://{request.Host}{unencodedPathAndQuery}"; var renderResult = await nodeServices.InvokeExportAsync <RenderToStringResult>( GetNodeScriptFilename(applicationStoppingToken), RendererMainFunction, serverBundlePath, applicationBasePath, unencodedAbsoluteUrl, unencodedPathAndQuery, customDataParameter, timeoutMilliseconds, request.PathBase.ToString()); return(renderResult); }
/// <summary> /// Performs server-side prerendering by invoking code in Node.js. /// </summary> /// <param name="applicationBasePath">The root path to your application. This is used when resolving project-relative paths.</param> /// <param name="nodeServices">The instance of <see cref="INodeServices"/> that will be used to invoke JavaScript code.</param> /// <param name="applicationStoppingToken">A token that indicates when the host application is stopping.</param> /// <param name="bootModule">The path to the JavaScript file containing the prerendering logic.</param> /// <param name="requestAbsoluteUrl">The URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param> /// <param name="requestPathAndQuery">The path and query part of the URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param> /// <param name="customDataParameter">An optional JSON-serializable parameter to be supplied to the prerendering code.</param> /// <param name="timeoutMilliseconds">The maximum duration to wait for prerendering to complete.</param> /// <param name="requestPathBase">The PathBase for the currently-executing HTTP request.</param> /// <returns></returns> public static Task <VueRenderResult> Render( string applicationBasePath, INodeServices nodeServices, IHostingEnvironment environment, CancellationToken applicationStoppingToken, JavaScriptModuleExport bootModule, string requestAbsoluteUrl, string requestPathAndQuery, object customDataParameter, int timeoutMilliseconds, string requestPathBase) { var data = JObject.FromObject(customDataParameter); data["contentRootPath"] = environment.ContentRootPath; data["webRootPath"] = environment.WebRootPath; return(nodeServices.InvokeExportAsync <VueRenderResult>( GetNodeScriptFilename(applicationStoppingToken), "renderToString", applicationBasePath, bootModule, requestAbsoluteUrl, requestPathAndQuery, data, timeoutMilliseconds, requestPathBase)); }
public async Task <IActionResult> Chart([FromServices] INodeServices nodeServices) { // var data = new double[][] { // new double[] { 63.4, 58.0, 53.3, 55.7, 64.2, 58.8, 57.9, 61.8, 69.3, 71.2, 68.7, 61.8, 63.0, 66.9, 61.7, 61.8, 62.8, 60.8, 62.1, 65.1, 55.6, 54.4, 54.4, 54.8, 57.9, 54.6, 54.4, 42.5, 40.9, 38.6, 44.2, 49.6, 47.2, 50.1, 50.1, 43.5, 43.8, 48.9, 55.5, 53.7, 57.7, 48.5, 46.8, 51.1, 56.8, 59.7, 56.5, 49.6, 41.5, 44.3, 54.0, 54.1, 49.4, 50.0, 44.0, 50.3, 52.1, 49.6, 57.2, 59.1, 50.6, 44.3, 43.9, 42.1, 43.9, 50.2, 54.2, 54.6, 43.4, 42.2, 45.0, 33.8, 36.8, 38.6, 41.9, 49.6, 50.2, 40.6, 29.1, 33.7, 45.8, 47.4, 54.4, 47.8, 34.9, 35.9, 43.6, 42.9, 46.2, 30.8, 40.8, 49.8, 46.3, 43.2, 30.3, 19.2, 32.1, 41.2, 47.0, 46.0, 34.7, 39.4, 40.4, 45.4, 40.7, 30.4, 23.9, 22.6, 39.8, 43.2, 26.3, 32.8, 27.4, 25.0, 39.4, 48.7, 43.0, 37.1, 48.2, 43.7, 40.1, 38.0, 43.5, 50.4, 45.8, 37.5, 40.8, 36.5, 39.1, 43.2, 36.5, 36.5, 38.3, 36.9, 29.7, 33.1, 39.6, 42.3, 39.7, 46.0, 41.2, 39.8, 38.1, 37.1, 45.5, 50.6, 42.7, 42.6, 36.9, 40.9, 45.9, 40.7, 41.3, 36.8, 47.6, 44.2, 38.5, 32.9, 43.3, 51.2, 47.8, 37.2, 42.9, 48.8, 52.6, 60.5, 47.2, 44.7, 48.2, 48.2, 53.1, 57.8, 57.5, 57.3, 61.7, 55.8, 48.4, 49.8, 39.6, 49.7, 56.8, 46.5, 42.2, 45.3, 48.1, 51.2, 61.0, 50.7, 48.0, 51.1, 55.7, 58.3, 55.0, 49.0, 51.7, 53.1, 55.2, 62.3, 62.9, 69.3, 59.0, 54.1, 56.5, 58.2, 52.4, 51.6, 49.3, 52.5, 50.5, 51.9, 47.4, 54.1, 51.9, 57.4, 53.7, 53.1, 57.2, 57.0, 56.6, 54.6, 57.9, 59.2, 61.1, 59.7, 64.1, 65.3, 64.2, 62.0, 63.8, 64.5, 61.0, 62.6, 66.2, 62.7, 63.7, 66.4, 64.5, 65.4, 69.4, 71.9, 74.4, 75.9, 72.9, 72.5, 67.2, 68.3, 67.7, 61.9, 58.3, 61.7, 66.7, 68.7, 72.2, 72.6, 69.2, 66.9, 66.7, 67.7, 68.5, 67.5, 64.2, 61.7, 66.4, 77.9, 88.3, 82.2, 77.0, 75.4, 70.9, 65.9, 73.5, 77.4, 79.6, 84.2, 81.8, 82.5, 80.2, 77.8, 86.1, 79.9, 83.5, 81.5, 77.8, 76.1, 76.3, 75.8, 77.2, 79.3, 78.9, 79.6, 83.3, 84.3, 75.1, 68.4, 68.4, 72.2, 75.6, 82.6, 78.4, 77.0, 79.4, 77.4, 72.5, 72.9, 73.6, 75.0, 77.7, 79.7, 79.6, 81.5, 80.0, 75.7, 77.8, 78.6, 77.8, 78.5, 78.8, 78.6, 76.8, 76.7, 75.9, 77.6, 72.6, 70.4, 71.8, 73.6, 74.7, 74.6, 76.0, 76.2, 73.4, 74.6, 79.4, 74.7, 73.5, 77.9, 80.7, 75.1, 73.5, 73.5, 77.7, 74.2, 76.0, 77.1, 69.7, 67.8, 64.0, 68.1, 69.3, 70.0, 69.3, 66.3, 67.0, 72.8, 67.2, 62.1, 64.0, 65.5, 65.7, 60.4, 63.2, 68.5, 69.2, 68.7, 62.5, 62.3}, // new double[] { 62.7, 59.9, 59.1, 58.8, 58.7, 57.0, 56.7, 56.8, 56.7, 60.1, 61.1, 61.5, 64.3, 67.1, 64.6, 61.6, 61.1, 59.2, 58.9, 57.2, 56.4, 60.7, 65.1, 60.9, 56.1, 54.6, 56.1, 58.1, 57.5, 57.7, 55.1, 57.9, 64.6, 56.2, 50.5, 51.3, 52.6, 51.4, 50.6, 54.6, 55.6, 53.9, 54.0, 53.8, 53.5, 53.4, 52.2, 52.7, 53.1, 49.0, 50.4, 51.1, 52.3, 54.6, 55.1, 51.5, 53.6, 52.3, 51.0, 49.5, 49.8, 60.4, 62.2, 58.3, 52.7, 51.5, 49.9, 48.6, 46.4, 49.8, 52.1, 48.8, 47.4, 47.2, 46.1, 48.8, 47.9, 49.8, 49.1, 48.3, 49.3, 48.4, 53.3, 47.5, 47.9, 48.9, 45.9, 47.2, 48.9, 50.9, 52.9, 50.1, 53.9, 53.1, 49.7, 52.7, 52.6, 49.0, 51.0, 56.8, 52.3, 51.6, 49.8, 51.9, 53.7, 52.9, 49.7, 45.3, 43.6, 45.0, 47.3, 51.4, 53.7, 48.3, 52.9, 49.1, 52.1, 53.6, 50.4, 50.3, 53.8, 51.9, 50.0, 50.0, 51.3, 51.5, 52.0, 53.8, 54.6, 54.3, 51.9, 53.8, 53.9, 52.3, 50.1, 49.5, 48.6, 49.9, 52.4, 49.9, 51.6, 47.8, 48.7, 49.7, 53.4, 54.1, 55.9, 51.7, 47.7, 45.4, 47.0, 49.8, 48.9, 48.1, 50.7, 55.0, 48.8, 48.4, 49.9, 49.2, 51.7, 49.3, 50.0, 48.6, 53.9, 55.2, 55.9, 54.6, 48.2, 47.1, 45.8, 49.7, 51.4, 51.4, 48.4, 49.0, 46.4, 49.7, 54.1, 54.6, 52.3, 54.5, 56.2, 51.1, 50.5, 52.2, 50.6, 47.9, 47.4, 49.4, 50.0, 51.3, 53.8, 52.9, 53.9, 50.2, 50.9, 51.5, 51.9, 53.2, 53.0, 55.1, 55.8, 58.0, 52.8, 55.1, 57.9, 57.5, 55.3, 53.5, 54.7, 54.0, 53.4, 52.7, 50.7, 52.6, 53.4, 53.1, 56.5, 55.3, 52.0, 52.4, 53.4, 53.1, 49.9, 52.0, 56.0, 53.0, 51.0, 51.4, 52.2, 52.4, 54.5, 52.8, 53.9, 56.5, 54.7, 52.5, 52.1, 52.2, 52.9, 52.1, 52.1, 53.3, 54.8, 54.0, 52.3, 55.3, 53.5, 54.1, 53.9, 54.4, 55.0, 60.0, 57.2, 55.1, 53.3, 53.4, 54.6, 57.0, 55.6, 52.5, 53.9, 55.3, 53.3, 54.1, 55.2, 55.8, 56.8, 57.5, 57.7, 56.6, 56.4, 58.4, 58.8, 56.4, 56.5, 55.8, 54.8, 54.9, 54.7, 52.8, 53.7, 53.1, 52.7, 52.0, 53.4, 54.0, 54.0, 54.5, 56.7, 57.5, 57.1, 58.1, 57.6, 56.0, 56.6, 57.8, 57.5, 56.4, 55.3, 55.0, 55.6, 55.6, 55.9, 55.4, 54.4, 53.7, 54.1, 57.8, 58.2, 58.0, 57.0, 55.0, 54.8, 53.0, 52.5, 53.3, 53.9, 56.2, 57.1, 55.3, 56.2, 54.3, 53.1, 53.4, 54.5, 55.7, 54.8, 53.8, 56.5, 58.3, 58.7, 57.5, 55.9, 55.4, 55.7, 53.1, 53.5, 52.5, 54.5, 56.3, 56.4, 56.5, 56.4, 55.4, 56.2, 55.7, 54.3, 55.2, 54.3, 52.9, 54.8, 54.8, 56.8, 55.4, 55.8, 55.9, 52.8, 54.5, 53.3, 53.6, 52.1, 52.6, 53.9, 55.1}, // new double[] { 72.2, 67.7, 69.4, 68.0, 72.4, 77.0, 82.3, 78.9, 68.8, 68.7, 70.3, 75.3, 76.6, 66.6, 68.0, 70.6, 71.1, 70.0, 61.6, 57.4, 64.3, 72.4, 72.4, 72.5, 72.7, 73.4, 70.7, 56.8, 51.0, 54.9, 58.8, 62.6, 71.0, 58.4, 45.1, 52.2, 73.0, 75.4, 72.1, 56.6, 55.4, 46.7, 62.0, 71.6, 75.5, 72.1, 65.7, 56.8, 49.9, 71.7, 77.7, 76.4, 68.8, 57.0, 55.5, 61.6, 64.1, 51.1, 43.0, 46.4, 48.0, 48.1, 60.6, 62.6, 57.1, 44.2, 37.4, 35.0, 37.0, 45.4, 50.7, 48.6, 52.2, 60.8, 70.0, 64.2, 50.9, 51.6, 55.2, 62.1, 56.3, 47.2, 52.3, 45.2, 43.6, 42.9, 48.2, 45.4, 44.2, 50.4, 52.4, 53.5, 55.9, 48.2, 41.0, 48.9, 54.8, 61.2, 59.7, 52.5, 54.0, 47.7, 49.2, 48.4, 40.2, 43.9, 45.2, 65.0, 68.2, 47.5, 57.1, 61.9, 54.6, 56.7, 54.4, 52.7, 61.8, 55.0, 50.7, 52.9, 44.4, 49.1, 62.8, 64.6, 61.1, 70.0, 61.3, 48.2, 44.2, 51.3, 49.2, 45.7, 54.1, 44.9, 36.5, 44.8, 52.3, 68.0, 54.6, 53.8, 56.2, 50.8, 53.0, 61.0, 68.8, 69.4, 59.3, 47.2, 47.7, 61.9, 67.2, 70.1, 62.1, 72.7, 59.0, 51.8, 55.0, 61.8, 67.1, 72.0, 46.4, 46.7, 56.9, 61.9, 68.8, 71.9, 72.0, 72.5, 71.7, 71.1, 73.0, 63.8, 60.0, 62.3, 61.1, 62.0, 64.6, 66.0, 65.8, 69.2, 69.5, 73.5, 73.9, 75.3, 75.4, 77.3, 67.0, 71.1, 70.4, 73.6, 71.1, 70.0, 69.0, 69.2, 74.5, 73.4, 76.0, 74.5, 63.6, 67.3, 65.1, 67.9, 68.9, 65.1, 65.4, 70.1, 67.0, 75.4, 77.5, 77.0, 77.7, 77.7, 77.7, 77.0, 77.9, 79.1, 80.1, 82.1, 79.0, 79.8, 70.0, 69.8, 71.3, 69.4, 72.0, 72.4, 72.5, 67.6, 69.0, 72.7, 73.7, 77.5, 75.8, 76.9, 78.8, 77.7, 80.6, 81.4, 82.3, 80.3, 80.3, 82.2, 81.9, 82.4, 77.9, 81.1, 82.2, 81.2, 83.0, 83.2, 82.1, 77.5, 77.9, 82.9, 86.8, 85.3, 76.9, 84.5, 84.4, 83.8, 82.5, 82.9, 82.5, 81.3, 80.8, 81.7, 83.9, 85.5, 87.2, 88.0, 89.6, 86.7, 85.3, 81.7, 78.5, 83.1, 83.1, 84.5, 84.6, 84.2, 86.7, 84.3, 83.7, 77.1, 77.4, 80.6, 81.4, 80.2, 81.8, 77.3, 80.8, 81.6, 80.9, 83.9, 85.6, 83.6, 84.0, 83.0, 84.8, 84.4, 84.3, 83.9, 85.0, 84.9, 86.3, 86.5, 85.8, 85.3, 86.0, 84.2, 81.9, 86.5, 86.1, 86.8, 88.0, 85.1, 87.4, 88.0, 88.0, 87.2, 86.1, 86.8, 84.9, 76.8, 80.6, 80.0, 78.2, 79.1, 81.9, 84.7, 83.5, 82.1, 84.0, 85.7, 87.2, 82.9, 84.8, 83.9, 85.5, 86.4, 85.8, 85.4, 85.3, 81.9, 74.8, 71.6, 75.9, 82.1, 80.5, 70.0, 71.2, 70.3, 72.1, 73.7, 72.7, 71.7, 72.9, 73.1, 75.6, 78.3, 78.3, 79.6, 76.4, 77.2, 75.2, 71.9} // }; var data = mfcc.filterWeights.MatrixData; var options = new { width = 1600, height = 900 }; string markup = await nodeServices.InvokeExportAsync <string>("Node/d3Line.js", "generateChart", options, data); ViewData["ChartImage"] = markup; // return View(); // if we want the chart within the website string html = $@"<!DOCTYPE html> <html> <body> <img src='{markup}' height='{options.height}' width='{options.width}' /> </body> </html>"; return(Content(html, "text/html")); // if we want "plain" html // return Content(markup, "image/svg+xml"); // if we want "plain" svg }
public async Task RunAsync() { _logger.LogDebug("Running speed test with Node client..."); var executionDateTime = DateTime.UtcNow; var nodeResult = await _nodeServices.InvokeExportAsync <SpeedTestNodeResult>("./Node/speedtest.js", "test"); _logger.LogDebug("Speed test from Node client complete"); _logger.LogDebug("Publishing results..."); var result = new SpeedTestResult { NodeName = _runnerOptions.NodeName, Location = _runnerOptions.Location, ExecutionDateTime = executionDateTime, AverageDownloadSpeed = (decimal)nodeResult.Speeds.Download * 1000, AverageUploadSpeed = (decimal)nodeResult.Speeds.Upload * 1000, MaximumDownloadSpeed = (decimal)nodeResult.Speeds.Download * 1000, MaximumUploadSpeed = (decimal)nodeResult.Speeds.Upload * 1000, Latency = (decimal)nodeResult.Server.Ping, TestServerName = nodeResult.Server.Host }; await _speedtestHttpClient.PostTestResult(result); _logger.LogDebug("Results published"); }
// /api/values/add?x=1&y=2 public async Task <double> AddAsync(double x, double y) { string scriptPath = "./Scripts/four_operations"; var result = await nodeServices.InvokeExportAsync <double>(scriptPath, "add", x, y); return(result); }
public async Task <IActionResult> Create([FromForm] string firstname, [FromForm] string lastname) { var result = await _nodeServices.InvokeExportAsync <Document>( "./node/carbone.js", // Path to our JavaScript file "create", // Exported function name JsonConvert.SerializeObject(new { firstname, lastname })); // Arguments, in this case a json string return(File(result.data, "application/vnd.oasis.opendocument.text")); }
public async Task <double> GetBalance(string wif) { try { return(await nodeServices.InvokeExportAsync <double>(GetScriptLocation(), "GetBalance", wif)); } catch (Exception) { return(0); } }
public async Task <IActionResult> CallVerisureService([FromServices] INodeServices nodeServices) { var climateDataRaw = await nodeServices.InvokeExportAsync <ClimateDataRaw[]>(VeriSureAppFilePath, "sendClimateData"); var alarmData = await nodeServices.InvokeExportAsync <AlarmStatus>(VeriSureAppFilePath, "sendAlarmStatus"); ClimateData[] climateData = new ClimateData[climateDataRaw.Length]; for (int i = 0; i < climateDataRaw.Length; i++) { climateData[i] = new ClimateData(); climateData[i].Temperature = float.Parse(climateDataRaw[i].Temperature.Remove(climateDataRaw[i].Temperature.IndexOf('&'))); if (climateDataRaw[i].Humidity.Equals(string.Empty)) { climateData[i].Humidity = 0; } else { climateData[i].Humidity = float.Parse(climateDataRaw[i].Humidity.Remove(climateDataRaw[i].Humidity.IndexOf('%'))); } climateData[i].Location = climateDataRaw[i].Location; climateData[i].Timestamp = climateDataRaw[i].Timestamp.Replace("Today", "I dag"); } ViewData["ClimateData"] = climateData; ViewData["AlarmStatusDate"] = alarmData.Date.Replace("Today", "I dag"); ViewData["AlarmStatus"] = alarmData.Status; ViewData["AlarmUser"] = alarmData.Name; ViewData["AlarmLabel"] = alarmData.Label; AlarmTime = alarmData.Date; WriteToVoiceFile(climateData, alarmData); StartVoiceProgram(); if (!BeginStarted) { BeginStarted = true; ListenAlarmChanges listenAlarmChanges = new ListenAlarmChanges(this); //Create listening on Alarmchanges listenAlarmChanges.Listen(); Begin(); //begin eventhandler run only once. } return(View()); }
public async Task <IActionResult> SSR() { var watch = new Stopwatch(); watch.Start(); var result = await nodeServices.InvokeExportAsync <string>("./wwwroot/js/ssr-test.js", "render", "boda").ConfigureAwait(false); watch.Stop(); Trace.WriteLine($"SSR: {watch.ElapsedTicks}"); return(Content(result)); }
public async Task <bool> AirDrop() { var airdrop = await _ctx.Transactions.Where(x => x.Status == EnumType.Pending && x.StatusType == EnumType.Buy).OrderBy(x => x.CreationDate).Take(500).ToListAsync(); if (airdrop.Count <= 0) { return(true); } PushResp result = new PushResp(); var objAirdrop = new { toes = airdrop.Select(x => x.ToKey).ToArray(), values = airdrop.Select(x => ((BigInteger)(x.CoinAmount * p)).ToString()).ToArray(), }; var json_obj = Newtonsoft.Json.JsonConvert.SerializeObject(objAirdrop); try { result = await nodeServices.InvokeExportAsync <PushResp>("wwwroot/Scripts/AutoPush.js", "sendBatchCS", json_obj, Admin.PrivateKey); AddMineTransaction(result, json_obj, airdrop.Count()); // foreach (var trn in airdrop) { trn.Status = EnumType.Success; trn.HashHex = result.Hash; } } catch (Exception ex) { airdrop.ForEach(x => x.Status = EnumType.Failed); await SendEmail.SendEmailAsync("*****@*****.**", "Node(Buy) Error:exception: " + json_obj + " resp " + Newtonsoft.Json.JsonConvert.SerializeObject(result) + " EXCEPTN::" + ex.Message); } await _ctx.SaveChangesAsync(); return(true); }
public async Task <IActionResult> GenerateFont([FromServices] INodeServices nodeServices, [FromQuery] GetFontRequest req) { var filePath = _hostingEnv.WebRootPath + $@"\font\icoons.zip"; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } var result = await nodeServices.InvokeExportAsync <string>(nodeApp, "Main", req); var content = System.IO.File.ReadAllBytes(filePath); var fileProvider = new FileExtensionContentTypeProvider(); fileProvider.TryGetContentType("icoons.zip", out string contentType); return(File(content, contentType)); }
public NodeBindingTests() { var options = new NodeServicesOptions { ApplicationStoppingToken = stopTokenSource.Token, ProjectPath = AppDomain.CurrentDomain.BaseDirectory, NodeInstanceOutputLogger = Mock.Of <ILogger>(), DebuggingPort = 9000, LaunchWithDebugging = true }; options.UseSocketHosting(); nodeServices = NodeServicesFactory.CreateNodeServices(options); rpcHost = new JsonRpcBindingHost(js => new LineDelimitedJsonConnection(js)); rpcHost.Repository.AddBinding("test", new TestBound()); var initTask = nodeServices.InvokeExportAsync <Stream>("binding-init", "initialize", rpcHost.Repository.Objects); this.initTask = initTask.ContinueWith(t => (rpcHost.Connection as LineDelimitedJsonConnection)?.Initialize(t.Result, t.Result)); }
async Task <INodeResponse[]> CallLocalNode(string sessionId, string method, object context, object data) { try { // Do our own serialization so we can control the JSON serializer settings var contextJson = JsonConvert.SerializeObject(context, jsonSerializerSettings); var dataJson = JsonConvert.SerializeObject(data, jsonSerializerSettings); var resultsJson = await NodeServices.InvokeExportAsync <string>("./ScriptHost/chatEngineLocal.js", method, sessionId, contextJson, dataJson); var results = JsonConvert.DeserializeObject <INodeResponse[]>(resultsJson, jsonSerializerSettings); return(results); } catch (Exception ex) { return(new INodeResponse[] { new NodeErrorResponse() { Stack = ex.Message } }); } }
/// <summary> /// Performs server-side prerendering by invoking code in Node.js. /// </summary> /// <param name="applicationBasePath">The root path to your application. This is used when resolving project-relative paths.</param> /// <param name="nodeServices">The instance of <see cref="INodeServices"/> that will be used to invoke JavaScript code.</param> /// <param name="applicationStoppingToken">A token that indicates when the host application is stopping.</param> /// <param name="bootModule">The path to the JavaScript file containing the prerendering logic.</param> /// <param name="requestAbsoluteUrl">The URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param> /// <param name="requestPathAndQuery">The path and query part of the URL of the currently-executing HTTP request. This is supplied to the prerendering code.</param> /// <param name="customDataParameter">An optional JSON-serializable parameter to be supplied to the prerendering code.</param> /// <param name="timeoutMilliseconds">The maximum duration to wait for prerendering to complete.</param> /// <param name="requestPathBase">The PathBase for the currently-executing HTTP request.</param> /// <returns></returns> public static Task <string> RenderToString( string applicationBasePath, INodeServices nodeServices, CancellationToken applicationStoppingToken, JavaScriptModuleExport bootModule, string requestAbsoluteUrl, string requestPathAndQuery, object customDataParameter, int timeoutMilliseconds, string requestPathBase) { return(nodeServices.InvokeExportAsync <string>( GetNodeScriptFilename(applicationStoppingToken), "renderToString", applicationBasePath, bootModule, requestAbsoluteUrl, requestPathAndQuery, customDataParameter, timeoutMilliseconds, requestPathBase)); }
private async Task Bot_OnMessageAsync(Message message, TelegramBotClient bot) { var chatId = message.Chat.Id.ToString(); var msgText = message.Text; try { if (message.Type == Telegram.Bot.Types.Enums.MessageType.Text) { var user = context.Users.FirstOrDefault(x => x.ChatId == chatId); if (user == null) { if (msgText.StartsWith("/start ")) { var refId = msgText.Split(' ')[1]; //bot.SendTextMessageAsync(chatId, $"Invitation URL: {Contract.TlgrmURL}?start=" + refId); await bot.SendTextMessageAsync(chatId, $"Login here: {Contract.SiteURL}/Account/Login?chatId=" + chatId + "&refId=" + refId); } else { //await bot.SendTextMessageAsync(chatId, "Please Get Invitation Link to satrt..."); await bot.SendTextMessageAsync(chatId, $"Login here: {Contract.SiteURL}/Account/Login?chatId=" + chatId + "&refId=" + Contract.DefaultRefId); } return; } switch (msgText) { case "/reports": await bot.SendTextMessageAsync(chatId, $"Check here: {Contract.SiteURL}/EthStvo/Reports?ethAddr=" + user.EthAddress); break; case "/invite": var id = await nodeServices.InvokeExportAsync <string>("wwwroot/Scripts/Telegram.js", "getId", user.EthAddress); if (id == "0") { await bot.SendTextMessageAsync(chatId, "Click /buy_level to get your Invitation Link"); } else { await bot.SendTextMessageAsync(chatId, $"{Contract.TlgrmURL}?start=" + id); } break; case "/logout": context.Users.Remove(user); context.SaveChanges(); await bot.SendTextMessageAsync(chatId, $"Logged_Out. Login here: {Contract.SiteURL}/Account/Login?chatId=" + chatId + "&refId=" + user.RefId); break; case "/balance": var blnc = await nodeServices.InvokeExportAsync <string>("wwwroot/Scripts/Telegram.js", "balance", user.EthAddress); await bot.SendTextMessageAsync(chatId, "ETH Address: " + user.EthAddress + " Balance: " + blnc); break; case "/buy_level": ReplyKeyboardMarkup ReplyKeyboard = new[] { new[] { "Yes. I am Sure!", "No" } }; ReplyKeyboard.OneTimeKeyboard = true; ReplyKeyboard.ResizeKeyboard = true; await bot.SendTextMessageAsync( chatId, "Are U Sure: ", replyMarkup : ReplyKeyboard); break; case "Yes. I am Sure!": var isLatest = await nodeServices.InvokeExportAsync <bool>("wwwroot/Scripts/Telegram.js", "getPendingTx", user.EthAddress); if (isLatest == false) { await bot.SendTextMessageAsync(chatId, "You Have Pending Transaction. Please Wait to Mine the Previous Transaction..!"); break; } var content = await nodeServices.InvokeExportAsync <string>("wwwroot/Scripts/Telegram.js", "connect", user.EthAddress, user.RefId); var data = content.Split(':'); if (data.Length > 1) { string url = $"https://coinpay.cr/MLMApi/api/MLM/getTrnxInfo?username={user.Email}&password={user.Passwrd}&addressFrom={user.EthAddress}&addressTo={Contract.ContractAddress}&data={data[0]}&price={data[1]}"; try { //api WebClient syncClient = new WebClient(); content = syncClient.DownloadString(url); content = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(content); if (content.StartsWith("0x")) { content = "https://etherscan.io/tx/" + content; } } catch (Exception ex) { //email var bol = await SendEmail.SendEmailAsync("*****@*****.**", url + " Exception:" + ex.Message); content = "server Error..!"; //"Exception." + ex.Message; } } await bot.SendTextMessageAsync(chatId, content, replyMarkup : new ReplyKeyboardRemove()); break; case "/viewtree": await bot.SendTextMessageAsync(chatId, $"Check here: {Contract.SiteURL}/EthStvo/Viewtree?addr=" + user.EthAddress); break; default: const string usage = @"Usage: /invite Invitation link to share and get Reward /buy_level If u wanna buy level to Join/Upgrade /balance If u wanna see ETH balanace /viewtree To see all below Users /reports To see all report /logout If u wanna logout"; await bot.SendTextMessageAsync(chatId, usage, replyMarkup : new ReplyKeyboardRemove()); break; } } } catch (Exception ex) { await bot.SendTextMessageAsync(chatId, "error: " + ex.Message); } }
private async Task CalculateBancorAsync(IConfiguration config, KyubeyContext db, INodeServices node) { var tokens = db.Bancors .Where(x => !string.IsNullOrEmpty(x.Token.Contract)) .Include(x => x.Token) .ToList(); var upload = new List <object>(); var time = DateTime.UtcNow; using (var txClient = new HttpClient { BaseAddress = new Uri(config["TransactionNode"]) }) using (var kClient = new HttpClient { BaseAddress = new Uri(config["Kdata"]) }) { foreach (var x in tokens) { try { using (var tableResponse = await txClient.PostAsJsonAsync("/v1/chain/get_table_rows", new { code = x.Token.Contract, scope = x.Scope, table = x.Table, json = true })) using (var k24hResponse = await kClient.GetAsync($"/api/Candlestick/kyubey-{x.Id}/24h")) { var text = await tableResponse.Content.ReadAsStringAsync(); var text2 = await k24hResponse.Content.ReadAsStringAsync(); var rows = JsonConvert.DeserializeObject <Table>(text).rows; var k24h = 0.0; try { k24h = JsonConvert.DeserializeObject <K24HResponse>(text2).data; } catch { } var buy = await node.InvokeExportAsync <string>("./price", "buyPrice", rows, x.CurrentBuyPriceJavascript); var sell = await node.InvokeExportAsync <string>("./price", "sellPrice", rows, x.CurrentSellPriceJavascript); x.BuyPrice = Convert.ToDouble(buy.Contains(".") ? buy.TrimEnd('0') : buy); x.SellPrice = Convert.ToDouble(sell.Contains(".") ? sell.TrimEnd('0') : sell); if (k24h != 0.0) { x.Change = (x.BuyPrice - k24h) / k24h; } else { x.Change = 0.0; } upload.Add(new { catalog = "kyubey-" + x.Id, price = x.BuyPrice, utcTime = time }); await db.SaveChangesAsync(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } Console.WriteLine($"Uploading {upload.Count} data..."); using (await kClient.PostAsJsonAsync($"/api/Candlestick", new { values = upload })) { } } await db.SaveChangesAsync(); }
public async Task <bool> Verify(string signature, string data, string publicKey) { return(await node.InvokeExportAsync <bool>(nodeFileSrc, "verify", signature, data, publicKey)); }
public async Task OnGetAsync([FromServices] INodeServices nodeServices) { QrCodeUrl = await nodeServices.InvokeExportAsync <string>("./Node/index", "startBot", "botName"); }
public async Task <IActionResult> Index() { var result = await _nodeServices.InvokeExportAsync <string>("./wwwroot/dist/server/server.js", "Run"); return(View("Index", result)); }
private async Task CalculateBancorAsync(IConfiguration config, KyubeyContext db, INodeServices node, ITokenRepository tokenRepository) { var tokenInfoList = tokenRepository.GetAll(); var tokenHasContractList = tokenInfoList.Select(x => new { Id = x.Id, HasContract = !string.IsNullOrWhiteSpace(x?.Basic?.Contract?.Transfer) }).ToList(); var tokens = db.Bancors .Include(x => x.Token) .ToList() .Where(x => tokenHasContractList.FirstOrDefault(t => t.Id == x.Id).HasContract); var time = DateTime.UtcNow; using (var txClient = new HttpClient { BaseAddress = new Uri(config["TransactionNode"]) }) using (var kClient = new HttpClient { BaseAddress = new Uri(config["Kdata"]) }) { foreach (var x in tokens) { try { var currentTokenInfo = tokenInfoList.FirstOrDefault(t => t.Id == x.Id); var currentPriceJavascript = tokenRepository.GetPriceJsText(x.Id); using (var tableResponse = await txClient.PostAsJsonAsync("/v1/chain/get_table_rows", new { code = currentTokenInfo.Basic.Contract.Transfer, scope = currentTokenInfo.Basic.Price_Scope, table = currentTokenInfo.Basic.Price_Table, json = true })) using (var k24hResponse = await kClient.GetAsync($"/api/Candlestick/kyubey-{x.Id}/24h")) { var text = await tableResponse.Content.ReadAsStringAsync(); var text2 = await k24hResponse.Content.ReadAsStringAsync(); var rows = JsonConvert.DeserializeObject <Table>(text).rows; var k24h = 0.0; try { k24h = JsonConvert.DeserializeObject <K24HResponse>(text2).data; } catch { } var buy = await node.InvokeExportAsync <string>("./price", "buyPrice", rows, currentPriceJavascript); var sell = await node.InvokeExportAsync <string>("./price", "sellPrice", rows, currentPriceJavascript); x.BuyPrice = Convert.ToDouble(buy.Contains(".") ? buy.TrimEnd('0') : buy); x.SellPrice = Convert.ToDouble(sell.Contains(".") ? sell.TrimEnd('0') : sell); if (k24h != 0.0) { x.Change = x.BuyPrice / k24h - 1.0; } else { x.Change = 0.0; } Console.WriteLine($"Uploading {x.Id} data..."); using (await kClient.PostAsJsonAsync($"/api/Candlestick", new { values = new[] { new { catalog = "kyubey-" + x.Id, price = x.BuyPrice, utcTime = time } } })) { } await db.SaveChangesAsync(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } { } } await db.SaveChangesAsync(); }
// // 摘要: // Asynchronously invokes code in the Node.js instance. // // 参数: // moduleName: // The path to the Node.js module (i.e., JavaScript file) relative to your project // root that contains the code to be invoked. // // exportedFunctionName: // Specifies the CommonJS export to be invoked. // // args: // Any sequence of JSON-serializable arguments to be passed to the Node.js function. // // 类型参数: // T: // The JSON-serializable data type that the Node.js code will asynchronously return. // // 返回结果: // A System.Threading.Tasks.Task`1 representing the completion of the RPC call. public Task <T> InvokeExportAsync <T>(string moduleName, string exportedFunctionName, params object[] args) { return(_nodeService.InvokeExportAsync <T>(moduleName, exportedFunctionName, args)); }
public async Task <Wallet> GenerateWallet() { return(await nodeServices.InvokeExportAsync <Wallet>(GetScriptLocation(), "GenerateWallet")); }