From 1c0e83591402d5d4e6d812ab5a195ee6184dbe08 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Sun, 10 May 2020 22:19:16 +0800 Subject: [PATCH] 1.0.0.510 Former-commit-id: bd21725dced04f3f9837a7e7ecae9e7159044118 --- projects/Infrastructure/Infrastructure.csproj | 2 +- .../Areas/Admin/Controlls/AjaxController.cs | 21 ++++++++------ .../Services/IoTCenterEventHandler.cs | 28 ++++++++++--------- .../IoTCenter/Views/Shared/_Layout.cshtml | 2 +- .../IoTNode/Services/IoTNodeEventHandler.cs | 19 ++++++------- projects/Version.cs | 2 +- 6 files changed, 39 insertions(+), 35 deletions(-) diff --git a/projects/Infrastructure/Infrastructure.csproj b/projects/Infrastructure/Infrastructure.csproj index ef67ecc6..7f38957a 100644 --- a/projects/Infrastructure/Infrastructure.csproj +++ b/projects/Infrastructure/Infrastructure.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/projects/IoT.Shared/Areas/Admin/Controlls/AjaxController.cs b/projects/IoT.Shared/Areas/Admin/Controlls/AjaxController.cs index 050d4651..ae8f6baf 100644 --- a/projects/IoT.Shared/Areas/Admin/Controlls/AjaxController.cs +++ b/projects/IoT.Shared/Areas/Admin/Controlls/AjaxController.cs @@ -1,15 +1,15 @@ using Application.Domain.Entities; using Cronos; -using CSScriptLib; using Infrastructure.Data; using Infrastructure.Extensions; +using Jint; +using Jint.Native; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; namespace IoT.Shared.Areas.Admin.Controlls @@ -264,12 +264,17 @@ namespace IoT.Shared.Areas.Admin.Controlls try { var data = this._dataRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == dataId); - var methodText = $"bool Valid(string name,string key,{data.Type.ToString().ToLower()} value,string description){{ return {condition};}}"; - Debug.WriteLine(methodText); - dynamic method = CSScript.Evaluator.LoadMethod(methodText); - dynamic value = data.GetValue(); - var result = method.Valid(data.Name, data.Key, value, data.Description); - return new JsonResult(true); + var value = data.Value; + var engine = new Engine().Execute($"function valid(value){{return {condition};}}"); + var result = engine.Invoke("valid", value); + if (result == JsValue.True || result == JsValue.False) + { + return new JsonResult(true); + } + else + { + return new JsonResult($"表达式运算结果无效:{result}"); + } } catch (Exception ex) { diff --git a/projects/IoTCenter/Services/IoTCenterEventHandler.cs b/projects/IoTCenter/Services/IoTCenterEventHandler.cs index 43c83a12..a5c8b08c 100644 --- a/projects/IoTCenter/Services/IoTCenterEventHandler.cs +++ b/projects/IoTCenter/Services/IoTCenterEventHandler.cs @@ -1,11 +1,12 @@ 锘縰sing Application.Domain.Entities; using Application.Models; -using CSScriptLib; using Infrastructure.Data; using Infrastructure.Events; using Infrastructure.Extensions; using IoT.Shared.Services.IoTCenter; using IoTCenter.Application.Domain; +using Jint; +using Jint.Native; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -274,27 +275,27 @@ namespace IoTCenter.Services var data = message.Data; if (tigger.DataId == data.Id) { - var methodText = $"bool Valid(string name,string key,{data.Type.ToString().ToLower()} value,string description){{ return {tigger.Condition};}}"; try { - dynamic method = CSScript.Evaluator.LoadMethod(methodText); - dynamic value = data.GetValue(); - var result = method.Valid(data.Name, data.Key, value, data.Description); - if (result) + var condition = tigger.Condition; + var value = data.Value; + var engine = new Engine().Execute($"function valid(value){{return {condition};}}"); + var result = engine.Invoke("valid", value); + if (result == JsValue.True) { this.TiggerHandle(tigger.Id); } } catch (Exception ex) { - ex.PrintStack(); + this._logger.LogError(ex.ToString()); } } } } catch (Exception ex) { - ex.PrintStack(); + this._logger.LogError(ex.ToString()); } } @@ -392,11 +393,12 @@ namespace IoTCenter.Services public void Handle(NodeClientConnectedEvent message) { var organ = this._organRepo.Table().FirstOrDefault(o => o.Number == message.OrganNumber); - if(organ==null) + if (organ == null) { - organ = new Organ { - Name=message.OrganNumber, - Number= message.OrganNumber, + organ = new Organ + { + Name = message.OrganNumber, + Number = message.OrganNumber, Image = "/images/classroom.png" }; this._organRepo.Add(organ); @@ -407,7 +409,7 @@ namespace IoTCenter.Services var node = this._nodeRepo.Table().FirstOrDefault(o => o.Number == message.NodeNumber); if (node != null) { - this._organNodeRepo.Add(new OrganNode { NodeId=node.Id,OrganId=organ.Id }); + this._organNodeRepo.Add(new OrganNode { NodeId = node.Id, OrganId = organ.Id }); this._organNodeRepo.SaveChanges(); } } diff --git a/projects/IoTCenter/Views/Shared/_Layout.cshtml b/projects/IoTCenter/Views/Shared/_Layout.cshtml index 3e7c229a..3b3adb2f 100644 --- a/projects/IoTCenter/Views/Shared/_Layout.cshtml +++ b/projects/IoTCenter/Views/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ var name = settingSerice.GetSetting("name").Value; var logo = settingSerice.GetSetting("logo").Value; var copyright = settingSerice.GetSetting("copyright").Value; - var iosAppUrl = settingSerice.GetSetting("iosAppUrl").Value; + //var iosAppUrl = settingSerice.GetSetting("iosAppUrl").Value; } diff --git a/projects/IoTNode/Services/IoTNodeEventHandler.cs b/projects/IoTNode/Services/IoTNodeEventHandler.cs index 4b83a7c5..34b7db1a 100644 --- a/projects/IoTNode/Services/IoTNodeEventHandler.cs +++ b/projects/IoTNode/Services/IoTNodeEventHandler.cs @@ -1,14 +1,14 @@ 锘縰sing Application.Domain.Entities; -using CSScriptLib; using Hangfire; using Infrastructure.Application.Entites.Settings; using Infrastructure.Events; -using Infrastructure.Extensions; using IoT.Shared.Services; using IoTNode.DeviceServices.Onvif; +using Jint; +using Jint.Native; +using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; namespace IoTNode.Services { @@ -77,22 +77,19 @@ namespace IoTNode.Services { try { - this._logger.LogInformation($"Debug>call tigger handler when data update at {DateTime.Now.ToLongDateString()} "); foreach (var tigger in this._sceneTiggerService.GetSceneTiggers()) { var data = message.Data; if (tigger.DataId == data.Id) { - this._logger.LogInformation($"Debug>match tigger at {DateTime.Now.ToLongDateString()} "); - var methodText = $"bool Valid(string name,string key,{data.Type.ToString().ToLower()} value,string description){{ return {tigger.Condition};}}"; try { - dynamic method = CSScript.Evaluator.LoadMethod(methodText); - dynamic value = data.GetValue(); - var result = method.Valid(data.Name, data.Key, value, data.Description); - if (result) + var condition = tigger.Condition; + var value = data.Value; + var engine = new Engine().Execute($"function valid(value){{return {condition};}}"); + var result = engine.Invoke("valid", value); + if (result == JsValue.True) { - this._logger.LogInformation($"Debug>match contdation at {DateTime.Now.ToLongDateString()} "); this._job.TiggerHandle(tigger.Id); } } diff --git a/projects/Version.cs b/projects/Version.cs index 0457986e..3b39d504 100644 --- a/projects/Version.cs +++ b/projects/Version.cs @@ -1,4 +1,4 @@ 锘縰sing System.Reflection; [assembly: AssemblyVersion("1.0.0.*")] -[assembly: AssemblyInformationalVersion("1.0.0.509")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("1.0.0.510")] \ No newline at end of file