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

修改规则链和解析器器相关。

上级 549f3a80
因为 它太大了无法显示 source diff 。你可以改为 查看blob
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
using System.Threading.Tasks;
using IoTSharp.Data;
using IoTSharp.TaskExecutor;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace IoTSharp.TaskExecutor
{
[DisplayName("Air720S解析器")]
public class Air720Sx : ITaskExecutor
{
public Air720Sx()
{
}
public TaskExecutorResult Execute(TaskExecutorParam param)
{
var msg = JsonConvert.DeserializeObject<(string Topic, string Payload, string ClientId)>(param.Param);
var playload = Convert.FromBase64String(msg.Payload);
return new TaskExecutorResult();
}
}
}
......@@ -4,7 +4,7 @@ using System.Dynamic;
using System.Linq;
using System.Threading.Tasks;
namespace IoTSharp.FlowRuleEngine
namespace IoTSharp.TaskExecutor
{
public interface ITaskExecutor
{
......@@ -25,7 +25,7 @@ namespace IoTSharp.FlowRuleEngine
public class TaskExecutorResult
{
public dynamic Result { get; set; }
}
......@@ -35,4 +35,6 @@ namespace IoTSharp.FlowRuleEngine
public string Param { get; set; }
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
</Project>
......@@ -5,16 +5,16 @@ using System.Dynamic;
using System.Linq;
using System.Threading.Tasks;
using IoTSharp.Data;
using IoTSharp.TaskExecutor;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace IoTSharp.FlowRuleEngine.TaskExcutor
namespace IoTSharp.TaskExecutor
{
[DisplayName("用于消息推送的执行器")]
public class MessagePullExecutor : ITaskExecutor
{
private readonly ApplicationDbContext _context;
public MessagePullExecutor()
{
......@@ -28,9 +28,8 @@ namespace IoTSharp.FlowRuleEngine.TaskExcutor
var d = o.Property("temperature");
d.Value = new JValue(d.Value.Value<double>() + 100);
return new TaskExecutorResult() { Result = o.ToObject(typeof(ExpandoObject)) };
var p= JsonConvert.DeserializeObject<MessagePullParam>(param.Param);
p.temperature = p.temperature + 120;
p.temperature += 120;
return new TaskExecutorResult() { Result =p };
}
......
......@@ -55,7 +55,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.Oracle", "IoT
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.Sqlite", "IoTSharp.Data.Sqlite\IoTSharp.Data.Sqlite.csproj", "{C4450C7C-DD38-47A2-90C7-3F774B09CD69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Interpreter", "IoTSharp.Interpreter\IoTSharp.Interpreter.csproj", "{01210118-0A41-4A6D-9B4A-06F5540B139A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Interpreter", "IoTSharp.Interpreter\IoTSharp.Interpreter.csproj", "{01210118-0A41-4A6D-9B4A-06F5540B139A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.TaskExecutor", "IoTSharp.TaskExecutor\IoTSharp.TaskExecutor.csproj", "{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -366,6 +368,26 @@ Global
{01210118-0A41-4A6D-9B4A-06F5540B139A}.Release|x64.Build.0 = Release|Any CPU
{01210118-0A41-4A6D-9B4A-06F5540B139A}.Release|x86.ActiveCfg = Release|Any CPU
{01210118-0A41-4A6D-9B4A-06F5540B139A}.Release|x86.Build.0 = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|ARM.ActiveCfg = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|ARM.Build.0 = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|ARM64.Build.0 = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|x64.ActiveCfg = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|x64.Build.0 = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|x86.ActiveCfg = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Debug|x86.Build.0 = Debug|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|Any CPU.Build.0 = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|ARM.ActiveCfg = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|ARM.Build.0 = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|ARM64.ActiveCfg = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|ARM64.Build.0 = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|x64.ActiveCfg = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|x64.Build.0 = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|x86.ActiveCfg = Release|Any CPU
{01671BDE-398D-423C-B3E4-A05FF0AB7B4F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -24,6 +24,7 @@ using System.Reflection;
using System.Threading.Tasks;
using Dynamitey.DynamicObjects;
using Namotion.Reflection;
using IoTSharp.TaskExecutor;
namespace IoTSharp.Controllers
{
......@@ -34,13 +35,15 @@ namespace IoTSharp.Controllers
{
private ApplicationDbContext _context;
private readonly FlowRuleProcessor _flowRuleProcessor;
private readonly TaskExecutorHelper _helper;
private UserManager<IdentityUser> _userManager;
public RulesController(ApplicationDbContext context, UserManager<IdentityUser> userManager, FlowRuleProcessor flowRuleProcessor)
public RulesController(ApplicationDbContext context, UserManager<IdentityUser> userManager, FlowRuleProcessor flowRuleProcessor, TaskExecutorHelper helper)
{
this._userManager = userManager;
this._context = context;
_flowRuleProcessor = flowRuleProcessor;
_helper = helper;
}
[HttpPost("[action]")]
......@@ -1013,7 +1016,7 @@ namespace IoTSharp.Controllers
}
else
{
return (await this._userManager.FindByIdAsync(dto.Creator.ToString()))?.UserName;
return (await _userManager.FindByIdAsync(dto.Creator.ToString()))?.UserName;
}
}
......@@ -1021,9 +1024,9 @@ namespace IoTSharp.Controllers
[HttpGet("[action]")]
public ApiResult<dynamic> GetFlowOperstions(Guid eventId)
public ApiResult<dynamic> GetFlowOperstions(Guid eventId)
{
return new ApiResult<dynamic>(ApiCode.Success, "OK", _context.FlowOperations.Where(c => c.BaseEvent.EventId == eventId).ToList().OrderBy(c => c.Step).
return new ApiResult<dynamic>(ApiCode.Success, "OK", _context.FlowOperations.Where(c => c.BaseEvent.EventId == eventId).ToList().OrderBy(c => c.Step).
ToList()
.GroupBy(c => c.Step).Select(c => new
{
......@@ -1038,9 +1041,8 @@ namespace IoTSharp.Controllers
[HttpGet("[action]")]
public ApiResult<dynamic> GetExecutor()
{
return new ApiResult<dynamic > (ApiCode.Success, "OK", Assembly.GetExecutingAssembly().GetTypes().Where(c => c.GetInterfaces().Contains(typeof(ITaskExecutor))).Select(c => new { label = c.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName?? c.FullName, value = c.FullName }).ToList());
return new ApiResult<dynamic>(ApiCode.Success, "OK", _helper.GetTaskExecutorList().Select(c => new { label = c.Key, value = c.Value.FullName }).ToList());
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace IoTSharp.Extensions
{
public static class ExecutorExtensions
{
}
}
using IoTSharp.Data;
using IoTSharp.TaskExecutor;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace IoTSharp.FlowRuleEngine
{
public class TaskExecutorHelper
{
Dictionary<string, Type> pairs = null;
Dictionary<string, Type> pairstypename = null;
private IServiceProvider _sp;
private ApplicationDbContext _context;
public TaskExecutorHelper(ILogger<TaskExecutorHelper> logger, IServiceScopeFactory scopeFactor, IOptions<AppSettings> options)
{
_sp = scopeFactor.CreateScope().ServiceProvider;
_context = _sp.GetRequiredService<ApplicationDbContext>();
}
public Dictionary<string, Type> GetTaskExecutorList()
{
if (pairs == null)
{
LoadTypesInfo();
}
return pairs;
}
public object CreateInstance(string name)
{
if (pairs == null)
{
LoadTypesInfo();
}
return Activator.CreateInstance(pairs[name]);
}
public object CreateInstanceByTypeName(string typename)
{
if (pairs == null)
{
LoadTypesInfo();
}
return Activator.CreateInstance(pairstypename[typename]);
}
private void LoadTypesInfo()
{
pairs = new Dictionary<string, Type>();
Assembly.GetEntryAssembly().GetTypes().Where(c => c.GetInterfaces().Contains(typeof(ITaskExecutor))).ToList().ForEach(c =>
{
pairs.Add(c.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName ?? c.FullName, c);
});
typeof(ITaskExecutor).Assembly.GetTypes().Where(c => c.GetInterfaces().Contains(typeof(ITaskExecutor))).ToList().ForEach(c =>
{
pairs.Add(c.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName ?? c.FullName, c);
});
pairstypename = new Dictionary<string, Type>();
pairs.Values.ToList().ForEach(t =>
{
pairstypename.Add(t.FullName, t);
});
}
}
}
......@@ -166,8 +166,7 @@ namespace IoTSharp.Handlers
, TimeSpan.FromMinutes(5));
if (rules.HasValue)
{
var obj = new { e.ApplicationMessage.Topic, Payload = e.ApplicationMessage.ConvertPayloadToString() };
var obj = new { e.ApplicationMessage.Topic, Payload = Convert.ToBase64String(e.ApplicationMessage.Payload), e.ClientId };
rules.Value.ToList().ForEach(async g =>
{
_logger.LogInformation($"{e.ClientId}的数据{e.ApplicationMessage.Topic}通过规则链{g}进行处理。");
......
......@@ -201,6 +201,7 @@
<ProjectReference Include="..\IoTSharp.Data.SqlServer\IoTSharp.Data.SqlServer.csproj" />
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
<ProjectReference Include="..\IoTSharp.Interpreter\IoTSharp.Interpreter.csproj" />
<ProjectReference Include="..\IoTSharp.TaskExecutor\IoTSharp.TaskExecutor.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="ClientApp\" />
......
......@@ -370,6 +370,7 @@ namespace IoTSharp
});
services.AddScriptEngines(Configuration.GetSection("EngineSetting"));
services.AddTransient<FlowRuleProcessor>();
services.AddSingleton<TaskExecutorHelper>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册