提交 c93c72f2 编写于 作者: 麦壳饼's avatar 麦壳饼

调整 models 路径, 统一位置

上级 d88d7d9f
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; }
}
}
......@@ -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<ApiResult<bool>> 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<bool>(ApiCode.Success, "OK", true);
}
else
......
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<FlowRuleProcessor> logger, IServiceScopeFactory scopeFactor, IOptions<AppSettings> options, TaskExecutorHelper helper, IEasyCachingProviderFactory factory)
{
_scopeFactor = scopeFactor;
_logger = logger;
_setting = options.Value;
......@@ -42,11 +41,8 @@ namespace IoTSharp.FlowRuleEngine
_sp = _scopeFactor.CreateScope().ServiceProvider;
}
/// <summary>
///
///
/// </summary>
/// <param name="ruleid"> 规则Id</param>
/// <param name="data">数据</param>
......@@ -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<PythonScriptEngine>())
......@@ -305,9 +282,9 @@ namespace IoTSharp.FlowRuleEngine
}
}
break;
case "sql":
{
using (var pse = _sp.GetRequiredService<SQLEngine>())
{
string result = pse.Do(scriptsrc, taskoperation.Data);
......@@ -316,6 +293,7 @@ namespace IoTSharp.FlowRuleEngine
}
break;
case "lua":
{
using (var lua = _sp.GetRequiredService<LuaScriptEngine>())
......@@ -326,7 +304,6 @@ namespace IoTSharp.FlowRuleEngine
}
break;
case "javascript":
{
using (var js = _sp.GetRequiredService<JavaScriptEngine>())
......@@ -336,6 +313,7 @@ namespace IoTSharp.FlowRuleEngine
}
}
break;
case "csharp":
{
using (var js = _sp.GetRequiredService<CSharpScriptEngine>())
......@@ -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<List<Flow>> 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<ScriptTestResult> 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<PythonScriptEngine>())
......@@ -597,9 +556,9 @@ namespace IoTSharp.FlowRuleEngine
}
}
break;
case "sql":
{
using (var pse = _sp.GetRequiredService<SQLEngine>())
{
string result = pse.Do(scriptsrc, data);
......@@ -608,6 +567,7 @@ namespace IoTSharp.FlowRuleEngine
}
break;
case "lua":
{
using (var lua = _sp.GetRequiredService<LuaScriptEngine>())
......@@ -618,7 +578,6 @@ namespace IoTSharp.FlowRuleEngine
}
break;
case "javascript":
{
using (var js = _sp.GetRequiredService<JavaScriptEngine>())
......@@ -628,6 +587,7 @@ namespace IoTSharp.FlowRuleEngine
}
}
break;
case "csharp":
{
using (var js = _sp.GetRequiredService<CSharpScriptEngine>())
......@@ -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<ConditionTestResult> 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
......@@ -746,15 +746,15 @@
<param name="configure"></param>
</member>
<member name="M:IoTSharp.FlowRuleEngine.FlowRuleProcessor.RunFlowRules(System.Guid,System.Object,System.Guid,IoTSharp.Data.EventType,System.String)">
<summary>
<summary>
</summary>
<param name="ruleid"> 规则Id</param>
<param name="data">数据</param>
<param name="deviceId">创建者(可以是模拟器(测试),可以是设备,在EventType中区分一下)</param>
<param name="type">类型</param>
<param name="bizId">业务Id(第三方唯一Id,用于取回事件以及记录的标识)</param>
<returns> 返回所有节点的记录信息,需要保存则保存</returns>
</summary>
<param name="ruleid"> 规则Id</param>
<param name="data">数据</param>
<param name="deviceId">创建者(可以是模拟器(测试),可以是设备,在EventType中区分一下)</param>
<param name="type">类型</param>
<param name="bizId">业务Id(第三方唯一Id,用于取回事件以及记录的标识)</param>
<returns> 返回所有节点的记录信息,需要保存则保存</returns>
</member>
<member name="T:IoTSharp.Properties.Resources">
<summary>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册