diff --git a/IoTSharp.TaskAction/Air720Sx.cs b/IoTSharp.TaskAction/Air720Sx.cs deleted file mode 100644 index 300a767074c0ca67c2b496d57e602574234b641d..0000000000000000000000000000000000000000 --- a/IoTSharp.TaskAction/Air720Sx.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Dynamic; -using System.Linq; -using System.Threading.Tasks; -using IoTSharp.Data; -using IoTSharp.TaskAction; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace IoTSharp.TaskAction -{ - [DisplayName("Air720S解析器")] - public class Air720Sx : ITaskAction - { - - public Air720Sx() - { - - } - - public override Task ExecuteAsync(TaskActionInput _input) - { - var msg = _input.DynamicInput; - var playload = System.Text.Encoding.Default.GetString( Convert.FromBase64String(msg.Payload)); - return Task.FromResult( new TaskActionOutput() { Output=playload, DeviceId=_input.DeviceId}); - } - } -} diff --git a/IoTSharp.TaskAction/DeviceActionExcutor.cs b/IoTSharp.TaskAction/DeviceActionExcutor.cs index 94ba141d35b4b3de6a268f74a300d28457065803..052f571c9440a63e0ff56d6c37b4f7e62abf9c43 100644 --- a/IoTSharp.TaskAction/DeviceActionExcutor.cs +++ b/IoTSharp.TaskAction/DeviceActionExcutor.cs @@ -1,25 +1,15 @@ -using System; -using System.Collections.Generic; +using Newtonsoft.Json; +using RestSharp; +using System; using System.ComponentModel; -using System.Linq; using System.Net; -using System.Text; using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using RestSharp; namespace IoTSharp.TaskAction { [DisplayName("用于设备行为推送的执行器")] public class DeviceActionExcutor : ITaskAction { - public DeviceActionExcutor() - { - - - } - public override async Task ExecuteAsync(TaskActionInput input) { var config = JsonConvert.DeserializeObject(input.ExecutorConfig); @@ -32,12 +22,12 @@ namespace IoTSharp.TaskAction request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", contentType); request.AddHeader("cache-control", "no-cache"); - request.AddJsonBody(new{ sosType="1", sosContent= input.Input, usingUserId= "" }); + request.AddJsonBody(new { sosType = "1", sosContent = input.Input, usingUserId = "" }); var response = await restclient.ExecutePostAsync(request); if (response.StatusCode == HttpStatusCode.OK) { var result = JsonConvert.DeserializeObject(response.Content); - if (result is {success: true}) + if (result is { success: true }) { return new TaskActionOutput() { ExecutionInfo = response.Content, ExecutionStatus = result.success, DynamicOutput = input.DynamicInput }; ; } @@ -50,12 +40,10 @@ namespace IoTSharp.TaskAction { return new TaskActionOutput() { ExecutionInfo = $"StatusCode:{response.StatusCode } StatusDescription:{response.StatusDescription} {response.ErrorMessage}", ExecutionStatus = false }; ; } - } - class DeviceActionResult - { - + private class DeviceActionResult + { public bool success { get; set; } public string message { get; set; } public string code { get; set; } @@ -63,11 +51,9 @@ namespace IoTSharp.TaskAction public long timestamp { get; set; } public dynamic result { get; set; } - - } - class ModelExecutorConfig + private class ModelExecutorConfig { public string Url { get; set; } public string BaseUrl { get; set; } @@ -75,7 +61,6 @@ namespace IoTSharp.TaskAction public string Passwoid { get; set; } public string UserName { get; set; } public string Token { get; set; } - } } -} +} \ No newline at end of file diff --git a/IoTSharp.TaskAction/ITaskAction.cs b/IoTSharp.TaskAction/ITaskAction.cs index eb7d088827576e5112fd73aa7c97f3e17f9ddbcf..dce6a16940a51530e900aaf87798d9d185043a7b 100644 --- a/IoTSharp.TaskAction/ITaskAction.cs +++ b/IoTSharp.TaskAction/ITaskAction.cs @@ -8,8 +8,7 @@ namespace IoTSharp.TaskAction { public abstract class ITaskAction { - public abstract Task ExecuteAsync(TaskActionInput _input); - + public abstract Task ExecuteAsync(TaskActionInput _input); public IServiceProvider ServiceProvider { get; set; } } @@ -22,6 +21,7 @@ namespace IoTSharp.TaskAction public Guid DeviceId { get; set; } public bool ExecutionStatus { get; set; } public string ExecutionInfo { get; set; } + public dynamic DynamicOutput { get @@ -54,8 +54,9 @@ namespace IoTSharp.TaskAction private dynamic _DynamicOutput; private string _value; private readonly ExpandoObjectConverter expConverter = new(); - public Guid DeviceId { get; set; } + public Guid DeviceId { get; set; } public String ExecutorConfig { get; set; } + public dynamic DynamicInput { get diff --git a/IoTSharp.TaskAction/MessagePullExcutor.cs b/IoTSharp.TaskAction/MessagePullExcutor.cs index 78765aa6f370c2a86c295256fc843e1c50f556a3..6e76ad4a34e04738eb7d16b45ac55e37e723fd62 100644 --- a/IoTSharp.TaskAction/MessagePullExcutor.cs +++ b/IoTSharp.TaskAction/MessagePullExcutor.cs @@ -1,64 +1,35 @@ -using System; -using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RestSharp; +using System; using System.ComponentModel; -using System.Dynamic; using System.Linq; using System.Net; using System.Threading.Tasks; -using Castle.Components.DictionaryAdapter; -using IoTSharp.Data; -using IoTSharp.TaskAction; -using Microsoft.Extensions.Caching.Memory; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using RestSharp; namespace IoTSharp.TaskAction { [DisplayName("用于消息推送的执行器")] public class MessagePullExecutor : ITaskAction { - - public MessagePullExecutor() - { - - - } - public override Task ExecuteAsync(TaskActionInput input) { try { - // var cache = this.ServiceProvider.GetService(typeof(IMemoryCache)) as IMemoryCache; - - return SendData(input); - + return SendData(input); } catch (Exception ex) { - return Task.FromResult( new TaskActionOutput() { ExecutionInfo = ex.Message, ExecutionStatus = false }); + return Task.FromResult(new TaskActionOutput() { ExecutionInfo = ex.Message, ExecutionStatus = false }); } } - - private void Login(ModelExecutorConfig config) - { - - - - - } - - - private async Task SendData(TaskActionInput input) + private async Task SendData(TaskActionInput input) { try { - if (input.Input.Contains("ValueKind")) { - - JObject o = JsonConvert.DeserializeObject(input.Input) as JObject; var config = JsonConvert.DeserializeObject(input.ExecutorConfig); var dd = o.Properties().Select(c => new ParamObject { keyName = c.Name, value = JPropertyToObject(c.Value.First as JProperty) }).ToList(); @@ -75,7 +46,7 @@ namespace IoTSharp.TaskAction if (response.StatusCode == HttpStatusCode.OK) { var result = JsonConvert.DeserializeObject(response.Content); - if (result is {success: true}) + if (result is { success: true }) { return new TaskActionOutput() { ExecutionInfo = response.Content, ExecutionStatus = result.success, DynamicOutput = input.DynamicInput }; ; } @@ -88,9 +59,6 @@ namespace IoTSharp.TaskAction { return new TaskActionOutput() { ExecutionInfo = response.ErrorMessage, ExecutionStatus = false }; ; } - - - } else { @@ -106,12 +74,12 @@ namespace IoTSharp.TaskAction request.AddHeader("cache-control", "no-cache"); request.AddHeader("Content-Type", "application/json"); request.AddJsonBody(dd); - - var response = await restclient.ExecutePostAsync(request); + + var response = await restclient.ExecutePostAsync(request); if (response.StatusCode == HttpStatusCode.OK) { var result = JsonConvert.DeserializeObject(response.Content); - if (result is {success: true}) + if (result is { success: true }) { return new TaskActionOutput() { ExecutionInfo = response.Content, ExecutionStatus = result.success, DynamicOutput = input.DynamicInput }; ; } @@ -122,14 +90,9 @@ namespace IoTSharp.TaskAction } else { - return new TaskActionOutput() { ExecutionInfo =$"StatusCode:{response.StatusCode } StatusDescription:{response.StatusDescription} {response.ErrorMessage}" , ExecutionStatus = false }; ; + return new TaskActionOutput() { ExecutionInfo = $"StatusCode:{response.StatusCode } StatusDescription:{response.StatusDescription} {response.ErrorMessage}", ExecutionStatus = false }; ; } - } - - - - } catch (Exception ex) { @@ -137,7 +100,6 @@ namespace IoTSharp.TaskAction } } - public static object JPropertyToObject(JProperty property) { object obj = null; @@ -146,30 +108,39 @@ namespace IoTSharp.TaskAction case JTokenType.Integer: obj = property.Value.ToObject(); break; + case JTokenType.Float: obj = property.Value.ToObject(); break; + case JTokenType.String: obj = property.Value.ToObject(); break; + case JTokenType.Boolean: obj = property.Value.ToObject(); break; + case JTokenType.Date: obj = property.Value.ToObject(); break; + case JTokenType.Bytes: obj = property.Value.ToObject(); break; + case JTokenType.Guid: obj = property.Value.ToObject(); break; + case JTokenType.Uri: obj = property.Value.ToObject(); break; + case JTokenType.TimeSpan: obj = property.Value.ToObject(); break; + default: obj = property.Value; break; @@ -177,28 +148,8 @@ namespace IoTSharp.TaskAction return obj; } - class MessagePullParam + private class MessagePullResult { - - - public double param1 { get; set; } - public double param2 { get; set; } - public double param3 { get; set; } - public int param4 { get; set; } - - public long param5 { get; set; } - - - public ParamObject param6 { get; set; } - - public string param9 { get; set; } - } - - - class MessagePullResult - { - - public bool success { get; set; } public string message { get; set; } public string code { get; set; } @@ -206,25 +157,15 @@ namespace IoTSharp.TaskAction public long timestamp { get; set; } public dynamic result { get; set; } - - - } - - - public class LoginParam - { - - } public class ParamObject { - public string keyName { get; set; } public dynamic value { get; set; } } - class ModelExecutorConfig + private class ModelExecutorConfig { public string Url { get; set; } public string BaseUrl { get; set; } @@ -232,7 +173,6 @@ namespace IoTSharp.TaskAction public string Password { get; set; } public string UserName { get; set; } public string Token { get; set; } - } } -} +} \ No newline at end of file diff --git a/IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs b/IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs index d440b933421e44627fed9b25ad81fa81c03c6842..eb46a7b91d7b662c3aa166e3fec4cb774605c39d 100644 --- a/IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs +++ b/IoTSharp.TaskAction/TelemetryArrayPullExcutor.cs @@ -1,165 +1,87 @@ -using System; -using System.Collections.Generic; +using Newtonsoft.Json; +using RestSharp; +using System; using System.ComponentModel; - -using System.Linq; using System.Net; -using System.Text; using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using RestSharp; namespace IoTSharp.TaskAction { - - - [DisplayName("用于遥测数组推送的执行器")] public class TelemetryArrayPullExcutor : ITaskAction { - public TelemetryArrayPullExcutor() { - - } public override Task ExecuteAsync(TaskActionInput input) { try { - // var cache = this.ServiceProvider.GetService(typeof(IMemoryCache)) as IMemoryCache; - return SendData(input); - } catch (Exception ex) { - return Task.FromResult(new TaskActionOutput() {ExecutionInfo = ex.Message, ExecutionStatus = false}); + return Task.FromResult(new TaskActionOutput() { ExecutionInfo = ex.Message, ExecutionStatus = false }); } } - - private void Login(ModelExecutorConfig config) - { - - - - - } - - private async Task SendData(TaskActionInput input) { try { - - - - var config = JsonConvert.DeserializeObject(input.ExecutorConfig); - - var restclient = new RestClient(config.BaseUrl); - restclient.AddDefaultHeader(KnownHeaders.Accept, "*/*"); - var request = - new RestRequest(config.Url + (input.DeviceId == Guid.Empty ? "" : "/" + input.DeviceId)); - request.AddHeader("X-Access-Token", - config.Token); - request.RequestFormat = DataFormat.Json; - request.AddHeader("cache-control", "no-cache"); - request.AddHeader("Content-Type", "application/json"); - request.AddJsonBody(JsonConvert.DeserializeObject(input.Input)); - - var response = await restclient.ExecutePostAsync(request); - if (response.StatusCode == HttpStatusCode.OK) + var config = JsonConvert.DeserializeObject(input.ExecutorConfig); + + var restclient = new RestClient(config.BaseUrl); + restclient.AddDefaultHeader(KnownHeaders.Accept, "*/*"); + var request = + new RestRequest(config.Url + (input.DeviceId == Guid.Empty ? "" : "/" + input.DeviceId)); + request.AddHeader("X-Access-Token", + config.Token); + request.RequestFormat = DataFormat.Json; + request.AddHeader("cache-control", "no-cache"); + request.AddHeader("Content-Type", "application/json"); + request.AddJsonBody(JsonConvert.DeserializeObject(input.Input)); + + var response = await restclient.ExecutePostAsync(request); + if (response.StatusCode == HttpStatusCode.OK) + { + var result = JsonConvert.DeserializeObject(response.Content); + if (result is { success: true }) { - var result = JsonConvert.DeserializeObject(response.Content); - if (result is {success: true}) - { - return new TaskActionOutput() - { - ExecutionInfo = response.Content, ExecutionStatus = result.success, - DynamicOutput = input.DynamicInput - }; - ; - } - else + return new TaskActionOutput() { - return new TaskActionOutput() {ExecutionInfo = response.Content, ExecutionStatus = false}; - ; - } + ExecutionInfo = response.Content, + ExecutionStatus = result.success, + DynamicOutput = input.DynamicInput + }; + ; } else { - return new TaskActionOutput() - { - ExecutionInfo = - $"StatusCode:{response.StatusCode} StatusDescription:{response.StatusDescription} {response.ErrorMessage}", - ExecutionStatus = false - }; - + return new TaskActionOutput() { ExecutionInfo = response.Content, ExecutionStatus = false }; + ; } - - - - - - + } + else + { + return new TaskActionOutput() + { + ExecutionInfo = + $"StatusCode:{response.StatusCode} StatusDescription:{response.StatusDescription} {response.ErrorMessage}", + ExecutionStatus = false + }; + } } catch (Exception ex) { - return new TaskActionOutput() {ExecutionInfo = ex.Message, ExecutionStatus = false}; + return new TaskActionOutput() { ExecutionInfo = ex.Message, ExecutionStatus = false }; ; } - - - - } - public static object JPropertyToObject(JProperty property) + private class MessagePullResult { - object obj = null; - switch (property.Value.Type) - { - case JTokenType.Integer: - obj = property.Value.ToObject(); - break; - case JTokenType.Float: - obj = property.Value.ToObject(); - break; - case JTokenType.String: - obj = property.Value.ToObject(); - break; - case JTokenType.Boolean: - obj = property.Value.ToObject(); - break; - case JTokenType.Date: - obj = property.Value.ToObject(); - break; - case JTokenType.Bytes: - obj = property.Value.ToObject(); - break; - case JTokenType.Guid: - obj = property.Value.ToObject(); - break; - case JTokenType.Uri: - obj = property.Value.ToObject(); - break; - case JTokenType.TimeSpan: - obj = property.Value.ToObject(); - break; - default: - obj = property.Value; - break; - } - return obj; - } - - class MessagePullResult - { - - public bool success { get; set; } public string message { get; set; } public string code { get; set; } @@ -167,25 +89,9 @@ namespace IoTSharp.TaskAction public long timestamp { get; set; } public dynamic result { get; set; } - - - } - - - public class LoginParam - { - - } - public class ParamObject - { - - public string keyName { get; set; } - public dynamic value { get; set; } - } - - class ModelExecutorConfig + private class ModelExecutorConfig { public string Url { get; set; } public string BaseUrl { get; set; } @@ -193,7 +99,6 @@ namespace IoTSharp.TaskAction public string Password { get; set; } public string UserName { get; set; } public string Token { get; set; } - } } -} +} \ No newline at end of file