diff --git a/IoTSharp/Controllers/Models/IotSharpUser.cs b/IoTSharp/Controllers/Models/IotSharpUser.cs deleted file mode 100644 index a27da1b8f302c40e9a32a6e0b8dc000b13ac0821..0000000000000000000000000000000000000000 --- a/IoTSharp/Controllers/Models/IotSharpUser.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; - -namespace IoTSharp.Controllers.Models -{ - public class IotSharpUser:IdentityUser - { - public int Type { get; set; } - public string CustomerId { get; set; } - public string TenantId { get; set; } - public DateTime CraeteDateTime { get; set; } - } -} diff --git a/IoTSharp/Controllers/SubscriptionController.cs b/IoTSharp/Controllers/SubscriptionController.cs index 75c5e48baa730169209134798480a16a35535cd3..a28cb7d5ee5d3c32cf8666448deb5418d7f9dda5 100644 --- a/IoTSharp/Controllers/SubscriptionController.cs +++ b/IoTSharp/Controllers/SubscriptionController.cs @@ -87,10 +87,9 @@ namespace IoTSharp.Controllers { try { - var profile = this.GetUserProfile(); - SubscriptionEvent se = new SubscriptionEvent + SubscriptionEvent se = new() { - Creator = profile.Id, + Creator = User.GetUserId(), EventName = m.EventName, EventDesc = m.EventDesc, EventNameSpace = m.EventNameSpace, @@ -99,7 +98,7 @@ namespace IoTSharp.Controllers Type = m.Type, CreateDateTime = DateTime.Now, EventStatus = 1, - TenantId = profile.Tenant + TenantId = User.GetTenantId() }; _context.SubscriptionEvents.Add(se); await this._context.SaveChangesAsync(); @@ -114,13 +113,12 @@ namespace IoTSharp.Controllers [HttpGet("[action]")] public async Task> Delete(Guid id) { - var profile = this.GetUserProfile(); - var se = this._context.SubscriptionEvents.SingleOrDefault(c => c.EventId == id); + var se = _context.SubscriptionEvents.SingleOrDefault(c => c.EventId == id); if (se != null) { se.EventStatus = -1; - this._context.SubscriptionEvents.Update(se); - await this._context.SaveChangesAsync(); + _context.SubscriptionEvents.Update(se); + await _context.SaveChangesAsync(); return new ApiResult(ApiCode.Success, "OK", true); } else diff --git a/IoTSharp/FlowRuleEngine/FlowRuleProcessor.cs b/IoTSharp/FlowRuleEngine/FlowRuleProcessor.cs index 1cc7f3efa96594a8ae69a3552f53bb5a4cf304dc..411fca0c4634bbed7b35ae63162d2d3392c11214 100644 --- a/IoTSharp/FlowRuleEngine/FlowRuleProcessor.cs +++ b/IoTSharp/FlowRuleEngine/FlowRuleProcessor.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Dynamic; -using System.Linq; -using System.Threading.Tasks; -using Castle.Components.DictionaryAdapter; +using Castle.Components.DictionaryAdapter; using EasyCaching.Core; using IoTSharp.Data; using IoTSharp.Interpreter; @@ -13,6 +8,11 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Threading.Tasks; namespace IoTSharp.FlowRuleEngine { @@ -31,7 +31,6 @@ namespace IoTSharp.FlowRuleEngine public FlowRuleProcessor(ILogger logger, IServiceScopeFactory scopeFactor, IOptions options, TaskExecutorHelper helper, IEasyCachingProviderFactory factory) { - _scopeFactor = scopeFactor; _logger = logger; _setting = options.Value; @@ -42,11 +41,8 @@ namespace IoTSharp.FlowRuleEngine _sp = _scopeFactor.CreateScope().ServiceProvider; } - - - /// - /// + /// /// /// 规则Id /// 数据 @@ -74,7 +70,6 @@ namespace IoTSharp.FlowRuleEngine }, TimeSpan.FromSeconds(_setting.RuleCachingExpiration)); if (cacheRule.HasValue) { - FlowRule rule = cacheRule.Value.rule; _allFlows = cacheRule.Value._allFlows; _logger.LogInformation($"开始执行规则链{rule?.Name}({ruleid})"); @@ -85,7 +80,7 @@ namespace IoTSharp.FlowRuleEngine EventDesc = $"Event Rule:{rule?.Name}({ruleid}) device is {deviceId}", EventName = $"开始执行规则链{rule?.Name}({ruleid})", MataData = JsonConvert.SerializeObject(data), - // BizData = JsonConvert.SerializeObject(rule), //所有规则修改都会让对应的flow数据和设计文件不一致,最终导致回放失败,在此拷贝一份原始数据 + // BizData = JsonConvert.SerializeObject(rule), //所有规则修改都会让对应的flow数据和设计文件不一致,最终导致回放失败,在此拷贝一份原始数据 FlowRule = rule, Bizid = bizId, Type = type, @@ -109,8 +104,6 @@ namespace IoTSharp.FlowRuleEngine if (start == null) { - - _allflowoperation.Add(new FlowOperation() { OperationId = Guid.NewGuid(), @@ -123,15 +116,12 @@ namespace IoTSharp.FlowRuleEngine OperationDesc = "未能找到启动节点", Step = 1, BaseEvent = @event - }); return _allflowoperation; - } var startoperation = new FlowOperation() { - OperationId = Guid.NewGuid(), bpmnid = start.bpmnid, AddDate = DateTime.Now, @@ -148,7 +138,6 @@ namespace IoTSharp.FlowRuleEngine var nextflows = await ProcessCondition(start.FlowId, data); if (nextflows != null) { - foreach (var item in nextflows) { var flowOperation = new FlowOperation() @@ -176,17 +165,11 @@ namespace IoTSharp.FlowRuleEngine return null; } - - public async Task Process(Guid operationid, object data, Guid deviceId) { - - - var peroperation = _allflowoperation.FirstOrDefault(c => c.OperationId == operationid); if (peroperation != null) { - if (peroperation.Step > this._maximumiteration) { peroperation.OperationDesc = "Maximum iteration depth has been reached"; @@ -220,7 +203,6 @@ namespace IoTSharp.FlowRuleEngine case "bpmn:Task": { - var taskoperation = new FlowOperation() { OperationId = Guid.NewGuid(), @@ -236,13 +218,11 @@ namespace IoTSharp.FlowRuleEngine }; _allflowoperation.Add(taskoperation); - //脚本处理 if (!string.IsNullOrEmpty(flow.NodeProcessScriptType) && (!string.IsNullOrEmpty(flow.NodeProcessScript) || !string.IsNullOrEmpty(flow.NodeProcessClass))) { var scriptsrc = flow.NodeProcessScript; - dynamic obj = null; switch (flow.NodeProcessScriptType) { @@ -250,7 +230,6 @@ namespace IoTSharp.FlowRuleEngine if (!string.IsNullOrEmpty(flow.NodeProcessClass)) { - ITaskAction executor = _helper.CreateInstanceByTypeName(flow.NodeProcessClass); if (executor != null) { @@ -264,12 +243,11 @@ namespace IoTSharp.FlowRuleEngine } ); - _logger.Log(LogLevel.Information, "执行器"+flow.NodeProcessClass+"已完成处理"); + _logger.Log(LogLevel.Information, "执行器" + flow.NodeProcessClass + "已完成处理"); obj = result.DynamicOutput; taskoperation.OperationDesc += "\r\n" + result.ExecutionInfo; - if (!result.ExecutionStatus) + if (!result.ExecutionStatus) { - taskoperation.NodeStatus = 2; _logger.Log(LogLevel.Information, "执行器" + flow.NodeProcessClass + "未能正确处理:" + result.ExecutionInfo); @@ -280,7 +258,6 @@ namespace IoTSharp.FlowRuleEngine { _logger.Log(LogLevel.Information, "执行器" + flow.NodeProcessClass + "未能正确处理:" + ex.Source); - taskoperation.OperationDesc += "\r\n" + ex.Message; taskoperation.NodeStatus = 2; return; @@ -288,7 +265,6 @@ namespace IoTSharp.FlowRuleEngine } else { - _logger.Log(LogLevel.Warning, "脚本执行异常,未能实例化执行器"); taskoperation.OperationDesc += "\r\n" + "脚本执行异常,未能实例化执行器"; taskoperation.NodeStatus = 2; @@ -296,6 +272,7 @@ namespace IoTSharp.FlowRuleEngine } } break; + case "python": { using (var pse = _sp.GetRequiredService()) @@ -305,9 +282,9 @@ namespace IoTSharp.FlowRuleEngine } } break; + case "sql": { - using (var pse = _sp.GetRequiredService()) { string result = pse.Do(scriptsrc, taskoperation.Data); @@ -316,6 +293,7 @@ namespace IoTSharp.FlowRuleEngine } break; + case "lua": { using (var lua = _sp.GetRequiredService()) @@ -326,7 +304,6 @@ namespace IoTSharp.FlowRuleEngine } break; - case "javascript": { using (var js = _sp.GetRequiredService()) @@ -336,6 +313,7 @@ namespace IoTSharp.FlowRuleEngine } } break; + case "csharp": { using (var js = _sp.GetRequiredService()) @@ -402,7 +380,6 @@ namespace IoTSharp.FlowRuleEngine _allflowoperation.Add(flowOperation); await Process(flowOperation.OperationId, data, deviceId); } - } } @@ -414,8 +391,6 @@ namespace IoTSharp.FlowRuleEngine if (end != null) { - - end.BuildFlowOperation(peroperation, flow); end.bpmnid = flow.bpmnid; end.AddDate = DateTime.Now; @@ -448,7 +423,6 @@ namespace IoTSharp.FlowRuleEngine break; - //没有终结点的节点必须留个空标签 case "label": @@ -472,16 +446,12 @@ namespace IoTSharp.FlowRuleEngine default: { - - break; } } } } - - public async Task> ProcessCondition(Guid flowId, dynamic data) { var flow = _allFlows.FirstOrDefault(c => c.FlowId == flowId); @@ -517,17 +487,11 @@ namespace IoTSharp.FlowRuleEngine var nextflow = flows.FirstOrDefault(a => a.bpmnid == item.Rule.SuccessEvent); emptyflow.Add(nextflow); } - } return emptyflow; } - - - - - public async Task TestScript(Guid ruleid, Guid flowId, string data) { var cacheRule = await _caching.GetAsync($"RunFlowRules_{ruleid}", async () => @@ -552,10 +516,8 @@ namespace IoTSharp.FlowRuleEngine if (!string.IsNullOrEmpty(flow?.NodeProcessScriptType) && (!string.IsNullOrEmpty(flow.NodeProcessScript) || !string.IsNullOrEmpty(flow.NodeProcessClass))) { - var scriptsrc = flow.NodeProcessScript; - dynamic obj = null; switch (flow.NodeProcessScriptType) @@ -564,7 +526,6 @@ namespace IoTSharp.FlowRuleEngine if (!string.IsNullOrEmpty(flow.NodeProcessClass)) { - ITaskAction executor = _helper.CreateInstanceByTypeName(flow.NodeProcessClass); if (executor != null) { @@ -574,20 +535,18 @@ namespace IoTSharp.FlowRuleEngine { Input = data, ExecutorConfig = flow.NodeProcessParams, - DeviceId = Guid.Empty + DeviceId = Guid.Empty }); - - obj = result.DynamicOutput; + obj = result.DynamicOutput; } catch (Exception ex) { - } } - } break; + case "python": { using (var pse = _sp.GetRequiredService()) @@ -597,9 +556,9 @@ namespace IoTSharp.FlowRuleEngine } } break; + case "sql": { - using (var pse = _sp.GetRequiredService()) { string result = pse.Do(scriptsrc, data); @@ -608,6 +567,7 @@ namespace IoTSharp.FlowRuleEngine } break; + case "lua": { using (var lua = _sp.GetRequiredService()) @@ -618,7 +578,6 @@ namespace IoTSharp.FlowRuleEngine } break; - case "javascript": { using (var js = _sp.GetRequiredService()) @@ -628,6 +587,7 @@ namespace IoTSharp.FlowRuleEngine } } break; + case "csharp": { using (var js = _sp.GetRequiredService()) @@ -639,20 +599,16 @@ namespace IoTSharp.FlowRuleEngine break; } - if (obj != null) { return new ScriptTestResult() { Data = obj, IsExecuted = true }; } - } } return new ScriptTestResult() { Data = null, IsExecuted = false }; ; - } - public async Task TestCondition(Guid ruleid, Guid flowId, dynamic data) { var cacheRule = await _caching.GetAsync($"RunFlowRules_{ruleid}", async () => @@ -706,21 +662,13 @@ namespace IoTSharp.FlowRuleEngine var nextflow = flows.FirstOrDefault(a => a.bpmnid == item.Rule.SuccessEvent); emptyflow.Add(nextflow); } - } return new ConditionTestResult { Failed = flows.Except(emptyflow).ToList(), Passed = emptyflow }; - - } else { return null; } - - - - } - } -} +} \ No newline at end of file diff --git a/IoTSharp/IoTSharp.xml b/IoTSharp/IoTSharp.xml index d09a43bce07945c8c1be4fe7f10084a72d7e4f01..4f16d0084d76423e647d3c1d0e086ca9d336fb94 100644 --- a/IoTSharp/IoTSharp.xml +++ b/IoTSharp/IoTSharp.xml @@ -746,15 +746,15 @@ - + - - 规则Id - 数据 - 创建者(可以是模拟器(测试),可以是设备,在EventType中区分一下) - 类型 - 业务Id(第三方唯一Id,用于取回事件以及记录的标识) - 返回所有节点的记录信息,需要保存则保存 + + 规则Id + 数据 + 创建者(可以是模拟器(测试),可以是设备,在EventType中区分一下) + 类型 + 业务Id(第三方唯一Id,用于取回事件以及记录的标识) + 返回所有节点的记录信息,需要保存则保存 diff --git a/IoTSharp/Controllers/Models/BaiduTranslateProfile.cs b/IoTSharp/Models/BaiduTranslateProfile.cs similarity index 100% rename from IoTSharp/Controllers/Models/BaiduTranslateProfile.cs rename to IoTSharp/Models/BaiduTranslateProfile.cs diff --git a/IoTSharp/Controllers/Models/FieldData.cs b/IoTSharp/Models/FieldData.cs similarity index 100% rename from IoTSharp/Controllers/Models/FieldData.cs rename to IoTSharp/Models/FieldData.cs diff --git a/IoTSharp/Controllers/Models/IPageParam.cs b/IoTSharp/Models/IPageParam.cs similarity index 100% rename from IoTSharp/Controllers/Models/IPageParam.cs rename to IoTSharp/Models/IPageParam.cs diff --git a/IoTSharp/Controllers/Models/ModelRefreshToken.cs b/IoTSharp/Models/ModelRefreshToken.cs similarity index 100% rename from IoTSharp/Controllers/Models/ModelRefreshToken.cs rename to IoTSharp/Models/ModelRefreshToken.cs diff --git a/IoTSharp/Controllers/Models/ModelRuleBind.cs b/IoTSharp/Models/ModelRuleBind.cs similarity index 100% rename from IoTSharp/Controllers/Models/ModelRuleBind.cs rename to IoTSharp/Models/ModelRuleBind.cs