diff --git a/IoTSharp/ClientApp/angular.json b/IoTSharp/ClientApp/angular.json index ffb8f9be60511d86a23980b1cdc3c94708228769..da549b56ad3bf57b997f7693c4185327a58f730b 100644 --- a/IoTSharp/ClientApp/angular.json +++ b/IoTSharp/ClientApp/angular.json @@ -62,8 +62,8 @@ "budgets": [ { "type": "initial", - "maximumWarning": "4mb", - "maximumError": "7mb" + "maximumWarning": "7mb", + "maximumError": "8mb" }, { "type": "anyComponentStyle", diff --git a/IoTSharp/ClientApp/package.json b/IoTSharp/ClientApp/package.json index 9d3d920e7bd0bd48a036894979f7343977df7a18..a29a1c105ef9edc9258d86c49eaab088a6fbb419 100644 --- a/IoTSharp/ClientApp/package.json +++ b/IoTSharp/ClientApp/package.json @@ -68,6 +68,7 @@ "ajv": "^8.1.0", "angular-baidu-maps": "^11.1.0", "angular-draggable-droppable": "^4.6.0", + "babel-loader": "^7.1.5", "bpmn-js": "^8.1.0", "file-saver": "^2.0.5", "grapesjs": "^0.17.26", diff --git a/IoTSharp/ClientApp/src/app/layout/basic/basic.component.ts b/IoTSharp/ClientApp/src/app/layout/basic/basic.component.ts index 9bd99a18d14434dd715317cbf3a32efa645d27fc..3ca4e814eed33d6dd5be2cc843ef667536d9c55f 100644 --- a/IoTSharp/ClientApp/src/app/layout/basic/basic.component.ts +++ b/IoTSharp/ClientApp/src/app/layout/basic/basic.component.ts @@ -6,7 +6,7 @@ import { environment } from '@env/environment'; @Component({ selector: 'layout-basic', template: ` - + diff --git a/IoTSharp/ClientApp/src/app/routes/device/devicecertificate/devicecertificate.component.html b/IoTSharp/ClientApp/src/app/routes/device/devicecertificate/devicecertificate.component.html index f6de427ca219938dfb1154898278ce1ea1929895..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/IoTSharp/ClientApp/src/app/routes/device/devicecertificate/devicecertificate.component.html +++ b/IoTSharp/ClientApp/src/app/routes/device/devicecertificate/devicecertificate.component.html @@ -1 +0,0 @@ -

devicecertificate works!

diff --git a/IoTSharp/ClientApp/src/app/routes/flow/diagram/diagram.component.html b/IoTSharp/ClientApp/src/app/routes/flow/diagram/diagram.component.html index 7a74d5b6a2c297cf3de96ed110569579b475bbd6..3685f3cc985c2099513f51e56d2e64fc0a8eca84 100644 --- a/IoTSharp/ClientApp/src/app/routes/flow/diagram/diagram.component.html +++ b/IoTSharp/ClientApp/src/app/routes/flow/diagram/diagram.component.html @@ -62,14 +62,15 @@ [ngModelOptions]="{ standalone: true }" (ngModelChange)="flowscripttypeChange($event)" > - - - - - + + + + + + diff --git a/IoTSharp/Controllers/RulesController.cs b/IoTSharp/Controllers/RulesController.cs index 75652efa38cf756eecd0766c1c927b48ed6029bd..5294d9e498eed6c6ba795a3db675cbc681e1cc4c 100644 --- a/IoTSharp/Controllers/RulesController.cs +++ b/IoTSharp/Controllers/RulesController.cs @@ -33,10 +33,10 @@ namespace IoTSharp.Controllers public class RulesController : ControllerBase { private ApplicationDbContext _context; - private readonly FlowRuleProcessor _flowRuleProcessor; + private readonly FlowRuleProcessorV2 _flowRuleProcessor; private UserManager _userManager; - public RulesController(ApplicationDbContext context, UserManager userManager, FlowRuleProcessor flowRuleProcessor) + public RulesController(ApplicationDbContext context, UserManager userManager, FlowRuleProcessorV2 flowRuleProcessor) { this._userManager = userManager; this._context = context; @@ -874,8 +874,8 @@ namespace IoTSharp.Controllers var testabizId = Guid.NewGuid().ToString(); //根据业务保存起来,用来查询执行事件和步骤 // await _flowRuleProcessor.RunFlowRules(ruleid, d, profile.Id, EventType.TestPurpose, testabizId); - FlowRuleProcessorV2 ruleProcessorV2 = new FlowRuleProcessorV2(this._context); - var result= await ruleProcessorV2.RunFlowRules(ruleid, d, profile.Id, EventType.TestPurpose, testabizId); + // FlowRuleProcessorV2 ruleProcessorV2 = new FlowRuleProcessorV2(this._context); + var result= await _flowRuleProcessor.RunFlowRules(ruleid, d, profile.Id, EventType.TestPurpose, testabizId); //应该由事件总线去通知 return new ApiResult(ApiCode.Success, "test complete", result.OrderBy(c => c.Step). diff --git a/IoTSharp/FlowRuleEngine/FlowRuleProcessorV2.cs b/IoTSharp/FlowRuleEngine/FlowRuleProcessorV2.cs index 9caf53e109852279e46e92d35ea4b2d0c7810e7d..7e7ed29148d73b2c68cbb1e8155d6b27ab1a1d4e 100644 --- a/IoTSharp/FlowRuleEngine/FlowRuleProcessorV2.cs +++ b/IoTSharp/FlowRuleEngine/FlowRuleProcessorV2.cs @@ -17,20 +17,21 @@ namespace IoTSharp.FlowRuleEngine { private readonly IServiceProvider _sp; private readonly ApplicationDbContext _context; - private readonly ILogger _logger; + private readonly ILogger _logger; private readonly AppSettings _setting; private List _allFlows = new List(); private List _allflowoperation = new List(); public FlowRuleProcessorV2( - ApplicationDbContext context) + ApplicationDbContext context, ILogger logger, IServiceScopeFactory scopeFactor, IOptions options) { - + _sp = scopeFactor.CreateScope().ServiceProvider; _context = context; - + _logger = logger; + _setting = options.Value; } - + /// /// @@ -40,7 +41,7 @@ namespace IoTSharp.FlowRuleEngine /// 创建者(可以是模拟器(测试),可以是设备,在EventType中区分一下) /// 类型 /// 业务Id(第三方唯一Id,用于取回事件以及记录的标识) - /// + /// 返回所有节点的记录信息,需要保存则保存 public async Task> RunFlowRules(Guid ruleid, object data, Guid creator, EventType type, string BizId) { @@ -56,7 +57,7 @@ namespace IoTSharp.FlowRuleEngine MataData = JsonConvert.SerializeObject(data), FlowRule = rule, Bizid = BizId, - Type = EventType.TestPurpose, + Type = type, EventStaus = 1 }; _context.BaseEvents.Add(_event); @@ -67,7 +68,7 @@ namespace IoTSharp.FlowRuleEngine var startoperation = new FlowOperation() { - OperationId = Guid.NewGuid(), + OperationId = Guid.NewGuid(), bpmnid = start.bpmnid, AddDate = DateTime.Now, FlowRule = start.FlowRule, @@ -86,7 +87,8 @@ namespace IoTSharp.FlowRuleEngine foreach (var item in nextflows) { var flowOperation = new FlowOperation() - { OperationId = Guid.NewGuid(), + { + OperationId = Guid.NewGuid(), AddDate = DateTime.Now, FlowRule = item.FlowRule, Flow = item, @@ -161,7 +163,7 @@ namespace IoTSharp.FlowRuleEngine BaseEvent = peroperation.BaseEvent }; _allflowoperation.Add(taskoperation); - + //脚本处理 if (!string.IsNullOrEmpty(flow.NodeProcessScriptType) && !string.IsNullOrEmpty(flow.NodeProcessScript)) @@ -175,11 +177,111 @@ namespace IoTSharp.FlowRuleEngine break; case "python": { + + dynamic obj = null; using (var pse = _sp.GetRequiredService()) { obj = pse.Do(scriptsrc, taskoperation.Data); } + + if (obj != null) + { + var next = await ProcessCondition(taskoperation.Flow.FlowId, obj); + foreach (var item in next) + { + var flowOperation = new FlowOperation() + { + OperationId = Guid.NewGuid(), + AddDate = DateTime.Now, + FlowRule = item.FlowRule, + Flow = item, + Data = JsonConvert.SerializeObject(data), + NodeStatus = 1, + OperationDesc = "执行条件(" + (string.IsNullOrEmpty(item.Conditionexpression) + ? "空条件" + : item.Conditionexpression) + ")", + Step = taskoperation.Step++, + bpmnid = item.bpmnid, + BaseEvent = taskoperation.BaseEvent + }; + _allflowoperation.Add(flowOperation); + await Process(flowOperation.OperationId, obj); + } + + } + else + { + taskoperation.OperationDesc = "脚本执行异常"; + taskoperation.NodeStatus = 2; + } + } + break; + case "sql": + { + dynamic obj = null; + using (var pse = _sp.GetRequiredService()) + { + obj = pse.Do(scriptsrc, taskoperation.Data); + } + + var next = await ProcessCondition(taskoperation.Flow.FlowId, obj); + + + if (obj!=null) + { + foreach (var item in next) + { + + var flowOperation = new FlowOperation() + { + OperationId = Guid.NewGuid(), + AddDate = DateTime.Now, + FlowRule = item.FlowRule, + Flow = item, + Data = JsonConvert.SerializeObject(data), + NodeStatus = 1, + OperationDesc = "执行条件(" + (string.IsNullOrEmpty(item.Conditionexpression) + ? "空条件" + : item.Conditionexpression) + ")", + Step = taskoperation.Step++, + bpmnid = item.bpmnid, + BaseEvent = taskoperation.BaseEvent + }; + _allflowoperation.Add(flowOperation); + + await Process(flowOperation.OperationId, obj); + } + + + } + else + { + taskoperation.OperationDesc = "脚本执行异常"; + taskoperation.NodeStatus = 2; + } + + + + } + + break; + case "lua": + { + dynamic obj = null; + + using (var lua = _sp.GetRequiredService()) + { + obj = lua.Do(scriptsrc, taskoperation.Data); + } + + + if (obj != null) + { + + + + var next = await ProcessCondition(taskoperation.Flow.FlowId, obj); foreach (var item in next) { @@ -203,42 +305,65 @@ namespace IoTSharp.FlowRuleEngine await Process(flowOperation.OperationId, obj); } + } + else + { + + taskoperation.OperationDesc = "脚本执行异常"; + taskoperation.NodeStatus = 2; + } + } + + break; - case "sql": - break; + + + case "javascript": { ExpandoObject obj = null; using (var js = _sp.GetRequiredService()) { - string result = js.Do(@"var output=input.Temperature;output = output + 100; return { Temperature:output};", taskoperation.Data); + string result = js.Do(scriptsrc, taskoperation.Data); obj = JsonConvert.DeserializeObject(result); } - var next = await ProcessCondition(taskoperation.Flow.FlowId, obj); - - foreach (var item in next) + if (obj != null) { - var flowOperation = new FlowOperation() + + var next = await ProcessCondition(taskoperation.Flow.FlowId, obj); + + foreach (var item in next) { - OperationId = Guid.NewGuid(), - AddDate = DateTime.Now, - FlowRule = item.FlowRule, - Flow = item, - Data = JsonConvert.SerializeObject(obj), - NodeStatus = 1, - OperationDesc = "执行条件(" + (string.IsNullOrEmpty(item.Conditionexpression) - ? "空条件" - : item.Conditionexpression) + ")", - Step = ++taskoperation.Step, - bpmnid = item.bpmnid, - BaseEvent = taskoperation.BaseEvent - }; - _allflowoperation.Add(flowOperation); - await Process(flowOperation.OperationId, obj); + var flowOperation = new FlowOperation() + { + OperationId = Guid.NewGuid(), + AddDate = DateTime.Now, + FlowRule = item.FlowRule, + Flow = item, + Data = JsonConvert.SerializeObject(obj), + NodeStatus = 1, + OperationDesc = "执行条件(" + + (string.IsNullOrEmpty(item.Conditionexpression) + ? "空条件" + : item.Conditionexpression) + ")", + Step = ++taskoperation.Step, + bpmnid = item.bpmnid, + BaseEvent = taskoperation.BaseEvent + }; + _allflowoperation.Add(flowOperation); + await Process(flowOperation.OperationId, obj); + } + } + else + { + + taskoperation.OperationDesc = "脚本执行异常"; + taskoperation.NodeStatus = 2; + } } break; @@ -266,7 +391,7 @@ namespace IoTSharp.FlowRuleEngine BaseEvent = taskoperation.BaseEvent }; _allflowoperation.Add(flowOperation); - + @@ -362,7 +487,7 @@ namespace IoTSharp.FlowRuleEngine end.BaseEvent = peroperation.BaseEvent; _allflowoperation.Add(end); } - + break; //case "bpmn:StartEvent": @@ -434,7 +559,7 @@ namespace IoTSharp.FlowRuleEngine // break; // // - //没有终结点的节点必须 + //没有终结点的节点必须留个空标签 case "label": break; @@ -457,7 +582,7 @@ namespace IoTSharp.FlowRuleEngine default: { - + break; } diff --git a/IoTSharp/Handlers/EventBusHandler.cs b/IoTSharp/Handlers/EventBusHandler.cs index 177965dd4b1ed37ff512515e69940061d02a7139..9aced18e1e50974e19840d4accbc361d6060c329 100644 --- a/IoTSharp/Handlers/EventBusHandler.cs +++ b/IoTSharp/Handlers/EventBusHandler.cs @@ -37,11 +37,11 @@ namespace IoTSharp.Handlers readonly ILogger _logger; private readonly IServiceScopeFactory _scopeFactor; private readonly IStorage _storage; - private readonly FlowRuleProcessor _flowRuleProcessor; + private readonly FlowRuleProcessorV2 _flowRuleProcessor; private readonly IEasyCachingProvider _caching; public EventBusHandler(ILogger logger, IServiceScopeFactory scopeFactor - , IOptions options, IStorage storage, FlowRuleProcessor flowRuleProcessor, IEasyCachingProviderFactory factory + , IOptions options, IStorage storage, FlowRuleProcessorV2 flowRuleProcessor, IEasyCachingProviderFactory factory ) { _appSettings = options.Value; diff --git a/IoTSharp/Handlers/MQTTServerHandler.cs b/IoTSharp/Handlers/MQTTServerHandler.cs index a420c80d26e3863ac291d1776ad19fd2c3d50aeb..82af12dd7bb7406bfd8c5f49c6a864ea501c0666 100644 --- a/IoTSharp/Handlers/MQTTServerHandler.cs +++ b/IoTSharp/Handlers/MQTTServerHandler.cs @@ -31,11 +31,11 @@ namespace IoTSharp.Handlers private readonly IEasyCachingProviderFactory _factory; readonly IMqttServerEx _serverEx; private readonly ICapPublisher _queue; - private readonly FlowRuleProcessor _flowRuleProcessor; + private readonly FlowRuleProcessorV2 _flowRuleProcessor; private readonly IEasyCachingProvider _caching; readonly MqttClientSetting _mcsetting; public MQTTServerHandler(ILogger logger, IServiceScopeFactory scopeFactor, IMqttServerEx serverEx - , IOptions options, ICapPublisher queue, IEasyCachingProviderFactory factory, FlowRuleProcessor flowRuleProcessor + , IOptions options, ICapPublisher queue, IEasyCachingProviderFactory factory, FlowRuleProcessorV2 flowRuleProcessor ) { _mcsetting = options.Value.MqttClient; diff --git a/IoTSharp/IoTSharp.xml b/IoTSharp/IoTSharp.xml index 8d6e62484b190ab43a5edf21971ccef954270200..459ca21f9500047b5ff867deb295c8a69b0e2f0a 100644 --- a/IoTSharp/IoTSharp.xml +++ b/IoTSharp/IoTSharp.xml @@ -595,7 +595,7 @@ 创建者(可以是模拟器(测试),可以是设备,在EventType中区分一下) 类型 业务Id(第三方唯一Id,用于取回事件以及记录的标识) - + 返回所有节点的记录信息,需要保存则保存 diff --git a/IoTSharp/Startup.cs b/IoTSharp/Startup.cs index db09c93299c92b3243f21c3b3750bed669e48da6..77ec5e26ef352622a687720252cf7f26dad5b684 100644 --- a/IoTSharp/Startup.cs +++ b/IoTSharp/Startup.cs @@ -378,7 +378,7 @@ namespace IoTSharp configuration.RootPath = "ClientApp/dist"; }); services.AddScriptEngines(Configuration.GetSection("EngineSetting")); - services.AddTransient(); + services.AddTransient(); }