添加脚本demo
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<PluginVersion>10.5.12</PluginVersion>
|
||||
<ProPluginVersion>10.5.12</ProPluginVersion>
|
||||
<PluginVersion>10.5.13</PluginVersion>
|
||||
<ProPluginVersion>10.5.13</ProPluginVersion>
|
||||
<AuthenticationVersion>2.1.7</AuthenticationVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@@ -562,6 +562,8 @@ public abstract class DeviceBase : DisposableObject, IDevice
|
||||
finally
|
||||
{
|
||||
waitLock.Release();
|
||||
if (waitData.WaitResult != null)
|
||||
waitData.WaitResult.Sign = sign;
|
||||
clientChannel.WaitHandlePool.Destroy(waitData);
|
||||
Channel.ChannelReceivedWaitDict.TryRemove(sign, out _);
|
||||
}
|
||||
|
@@ -1,32 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
|
||||
// 此代码版权(除特别声明外的代码)归作者本人Diego所有
|
||||
// 源代码使用协议遵循本仓库的开源协议及附加协议
|
||||
// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
|
||||
// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
|
||||
// 使用文档:https://thingsgateway.cn/
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
namespace ThingsGateway.Gateway.Application;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
public class BusinessPropertyWithCacheIntervalDBScript : BusinessPropertyWithCacheInterval
|
||||
{
|
||||
/// <summary>
|
||||
/// 表定义实体脚本
|
||||
/// </summary>
|
||||
[DynamicProperty]
|
||||
[AutoGenerateColumn(ComponentType = typeof(Textarea), Rows = 3)]
|
||||
public string? BigTextScriptTableModel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据脚本
|
||||
/// </summary>
|
||||
[AutoGenerateColumn(ComponentType = typeof(Textarea), Rows = 3)]
|
||||
public string? BigTextScriptDataModel { get; set; }
|
||||
}
|
@@ -26,7 +26,7 @@ namespace ThingsGateway.Gateway.Application;
|
||||
public class DeviceRuntime : Device, IDisposable
|
||||
{
|
||||
protected volatile DeviceStatusEnum _deviceStatus = DeviceStatusEnum.Default;
|
||||
|
||||
|
||||
private string? _lastErrorMessage;
|
||||
|
||||
/// <summary>
|
||||
|
@@ -129,7 +129,6 @@ public partial class PropertyComponent : IPropertyUIBase
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var op = new DialogOption()
|
||||
{
|
||||
IsScrolling = true,
|
||||
@@ -144,6 +143,147 @@ public partial class PropertyComponent : IPropertyUIBase
|
||||
{
|
||||
{nameof(ScriptCheck.Data),data },
|
||||
{nameof(ScriptCheck.Script),script },
|
||||
{nameof(ScriptCheck.OnGetDemo),()=>
|
||||
{
|
||||
return
|
||||
pname == nameof(BusinessPropertyWithCacheIntervalScript.BigTextScriptDeviceModel)?
|
||||
"""
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
using System.Dynamic;
|
||||
using TouchSocket.Core;
|
||||
public class S1 : IDynamicModel
|
||||
{
|
||||
public IEnumerable<dynamic> GetList(IEnumerable<object> datas)
|
||||
{
|
||||
List<ExpandoObject> deviceObjs = new List<ExpandoObject>();
|
||||
foreach (var v in datas)
|
||||
{
|
||||
var device = (DeviceBasicData)v;
|
||||
var expando = new ExpandoObject();
|
||||
var deviceObj = new ExpandoObject();
|
||||
|
||||
deviceObj.TryAdd(nameof(Device.Description), device.Description);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.ActiveTime), device.ActiveTime);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.DeviceStatus), device.DeviceStatus.ToString());
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.LastErrorMessage), device.LastErrorMessage);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.PluginName), device.PluginName);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark1), device.Remark1);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark2), device.Remark2);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark3), device.Remark3);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark4), device.Remark4);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark5), device.Remark5);
|
||||
|
||||
|
||||
expando.TryAdd(nameof(Device.Name), deviceObj);
|
||||
|
||||
}
|
||||
return deviceObjs;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
:
|
||||
|
||||
pname == nameof(BusinessPropertyWithCacheIntervalScript.BigTextScriptVariableModel)?
|
||||
|
||||
"""
|
||||
using System.Dynamic;
|
||||
using ThingsGateway.Foundation;
|
||||
using TouchSocket.Core;
|
||||
public class S2 : IDynamicModel
|
||||
{
|
||||
public IEnumerable<dynamic> GetList(IEnumerable<object> datas)
|
||||
{
|
||||
|
||||
List<ExpandoObject> deviceObjs = new List<ExpandoObject>();
|
||||
//按设备名称分组
|
||||
var groups = datas.Where(a => !string.IsNullOrEmpty(((VariableBasicData)a).DeviceName)).GroupBy(a => ((VariableBasicData)a).DeviceName, a => ((VariableBasicData)a));
|
||||
foreach (var group in groups)
|
||||
{
|
||||
//按采集时间分组
|
||||
var data = group.GroupBy(a => a.CollectTime.DateTimeToUnixTimestamp());
|
||||
var deviceObj = new ExpandoObject();
|
||||
List<ExpandoObject> expandos = new List<ExpandoObject>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
var expando = new ExpandoObject();
|
||||
expando.TryAdd("ts", item.Key);
|
||||
var variableObj = new ExpandoObject();
|
||||
foreach (var tag in item)
|
||||
{
|
||||
variableObj.TryAdd(tag.Name, tag.Value);
|
||||
}
|
||||
expando.TryAdd("values", variableObj);
|
||||
|
||||
expandos.Add(expando);
|
||||
}
|
||||
deviceObj.TryAdd(group.Key, expandos);
|
||||
deviceObjs.Add(deviceObj);
|
||||
}
|
||||
|
||||
return deviceObjs;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
:
|
||||
|
||||
pname == nameof(BusinessPropertyWithCacheIntervalScript.BigTextScriptAlarmModel)?
|
||||
|
||||
"""
|
||||
using System.Dynamic;
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
using TouchSocket.Core;
|
||||
public class DeviceScript : IDynamicModel
|
||||
{
|
||||
public IEnumerable<dynamic> GetList(IEnumerable<object> datas)
|
||||
{
|
||||
|
||||
List<ExpandoObject> deviceObjs = new List<ExpandoObject>();
|
||||
//按设备名称分组
|
||||
var groups = datas.Where(a => !string.IsNullOrEmpty(((AlarmVariable)a).DeviceName)).GroupBy(a => ((AlarmVariable)a).DeviceName, a => ((AlarmVariable)a));
|
||||
foreach (var group in groups)
|
||||
{
|
||||
//按采集时间分组
|
||||
var data = group.GroupBy(a => a.AlarmTime.DateTimeToUnixTimestamp());
|
||||
var deviceObj = new ExpandoObject();
|
||||
List<ExpandoObject> expandos = new List<ExpandoObject>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
var expando = new ExpandoObject();
|
||||
expando.TryAdd("ts", item.Key);
|
||||
var variableObj = new ExpandoObject();
|
||||
foreach (var tag in item)
|
||||
{
|
||||
var alarmObj = new ExpandoObject();
|
||||
alarmObj.TryAdd(nameof(tag.AlarmCode), tag.AlarmCode);
|
||||
alarmObj.TryAdd(nameof(tag.AlarmText), tag.AlarmText);
|
||||
alarmObj.TryAdd(nameof(tag.AlarmType), tag.AlarmType);
|
||||
alarmObj.TryAdd(nameof(tag.AlarmLimit), tag.AlarmLimit);
|
||||
alarmObj.TryAdd(nameof(tag.EventTime), tag.EventTime);
|
||||
alarmObj.TryAdd(nameof(tag.EventType), tag.EventType);
|
||||
|
||||
variableObj.TryAdd(tag.Name, alarmObj);
|
||||
}
|
||||
expando.TryAdd("alarms", variableObj);
|
||||
|
||||
expandos.Add(expando);
|
||||
}
|
||||
deviceObj.TryAdd(group.Key, expandos);
|
||||
deviceObjs.Add(deviceObj);
|
||||
}
|
||||
|
||||
return deviceObjs;
|
||||
}
|
||||
}
|
||||
"""
|
||||
:
|
||||
""
|
||||
;
|
||||
}
|
||||
},
|
||||
{nameof(ScriptCheck.ScriptChanged),EventCallback.Factory.Create<string>(this, v =>
|
||||
{
|
||||
if (pname == nameof(BusinessPropertyWithCacheIntervalScript.BigTextScriptAlarmModel))
|
||||
@@ -171,3 +311,7 @@ public partial class PropertyComponent : IPropertyUIBase
|
||||
[Inject]
|
||||
private DialogService DialogService { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -18,6 +18,8 @@
|
||||
<Alert Icon="fa-solid fa-circle-check" Color="Color.Success">@(new MarkupString("获取变量类实体,可用方法 <code>GlobalData.GetVariable(\"设备名称1\",\"变量名称1\")</code> "))</Alert>
|
||||
<Alert Icon="fa-solid fa-circle-check" Color="Color.Success">@(new MarkupString("详细说明查看文档对应内容页面"))</Alert>
|
||||
|
||||
<Button IsAsync OnClick="GetDemo" class="mt-3" Text="Demo" />
|
||||
|
||||
</div>
|
||||
<div class="col-6 col-md-6">
|
||||
<BootstrapLabel Value=@Localizer["Input"] ShowLabelTooltip="true" />
|
||||
|
@@ -8,6 +8,8 @@
|
||||
// QQ群:605534569
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ThingsGateway.Gateway.Application;
|
||||
using ThingsGateway.NewLife.Json.Extension;
|
||||
|
||||
@@ -56,4 +58,13 @@ public partial class ScriptCheck
|
||||
}
|
||||
[Inject]
|
||||
private IStringLocalizer<DeviceEditComponent> Localizer { get; set; }
|
||||
|
||||
private async Task GetDemo(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
|
||||
{
|
||||
Script = OnGetDemo?.Invoke();
|
||||
await Change(Script);
|
||||
}
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
public Func<string> OnGetDemo { get; set; }
|
||||
}
|
||||
|
@@ -9,7 +9,64 @@ namespace ThingsGateway.RulesEngine;
|
||||
[CategoryNode(Category = "Actuator", ImgUrl = "_content/ThingsGateway.RulesEngine/img/CSharpScript.svg", Desc = nameof(ExecuteScriptNode), LocalizerType = typeof(ThingsGateway.RulesEngine._Imports), WidgetType = typeof(CSharpScriptWidget))]
|
||||
public class ExecuteScriptNode : TextNode, IActuatorNode, IExexcuteExpressionsBase, IDisposable
|
||||
{
|
||||
public ExecuteScriptNode(string id, Point? position = null) : base(id, position) { Title = "ExecuteScriptNode"; Placeholder = "ExecuteScriptNode.Placeholder"; }
|
||||
public ExecuteScriptNode(string id, Point? position = null) : base(id, position)
|
||||
{
|
||||
Title = "ExecuteScriptNode"; Placeholder = "ExecuteScriptNode.Placeholder";
|
||||
Text =
|
||||
"""
|
||||
using ThingsGateway.RulesEngine;
|
||||
using ThingsGateway.Foundation;
|
||||
using TouchSocket.Core;
|
||||
using System.Text;
|
||||
|
||||
public class TestEx : IExexcuteExpressions
|
||||
{
|
||||
|
||||
public TouchSocket.Core.ILog Logger { get; set; }
|
||||
|
||||
public async System.Threading.Tasks.Task<NodeOutput> ExecuteAsync(NodeInput input, System.Threading.CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
|
||||
//想上传mqtt,可以自己写mqtt上传代码,或者通过mqtt插件的公开方法上传
|
||||
|
||||
//直接获取mqttclient插件类型的第一个设备
|
||||
var driver = GlobalData.ReadOnlyChannels.FirstOrDefault(a => a.Value.PluginName == "ThingsGateway.Plugin.Mqtt.MqttClient").Value?.ReadDeviceRuntimes?.FirstOrDefault().Value?.Driver;
|
||||
if (driver != null)
|
||||
{
|
||||
//找到对应的MqttClient插件设备
|
||||
var mqttClient = (ThingsGateway.Plugin.Mqtt.MqttClient)driver;
|
||||
if (mqttClient == null)
|
||||
throw new("mqttClient NOT FOUND");
|
||||
var result = await mqttClient.MqttUpAsync("test", Encoding.UTF8.GetBytes("test"),1, default);// 主题 和 负载
|
||||
if (!result.IsSuccess)
|
||||
throw new(result.ErrorMessage);
|
||||
return new NodeOutput() { Value = result };
|
||||
}
|
||||
throw new("mqttClient NOT FOUND");
|
||||
|
||||
|
||||
//通过设备名称找出mqttClient插件
|
||||
//var driver = GlobalData.ReadOnlyDevices.FirstOrDefault(a => a.Value.Name == "mqttDevice1").Value?.Driver;
|
||||
//if (driver != null)
|
||||
//{
|
||||
// //找到对应的MqttClient插件设备
|
||||
// var mqttClient = (ThingsGateway.Plugin.Mqtt.MqttClient)driver;
|
||||
// if (mqttClient == null)
|
||||
// throw new("mqttClient NOT FOUND");
|
||||
// var result = await mqttClient.MqttUpAsync("test", "test", default);// 主题 和 负载
|
||||
// if (!result.IsSuccess)
|
||||
// throw new(result.ErrorMessage);
|
||||
// return new NodeOutput() { Value = result };
|
||||
//}
|
||||
//throw new("mqttClient NOT FOUND");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
""";
|
||||
|
||||
}
|
||||
|
||||
private string text;
|
||||
|
||||
|
@@ -11,7 +11,14 @@ namespace ThingsGateway.RulesEngine;
|
||||
[CategoryNode(Category = "Expression", ImgUrl = "_content/ThingsGateway.RulesEngine/img/CSharpScript.svg", Desc = nameof(ConditionNode), LocalizerType = typeof(ThingsGateway.RulesEngine._Imports), WidgetType = typeof(CSharpScriptWidget))]
|
||||
public class ConditionNode : TextNode, IConditionNode
|
||||
{
|
||||
public ConditionNode(string id, Point? position = null) : base(id, position) { Title = "ConditionNode"; Placeholder = "ConditionNode.Placeholder"; }
|
||||
public ConditionNode(string id, Point? position = null) : base(id, position)
|
||||
{
|
||||
Title = "ConditionNode"; Placeholder = "ConditionNode.Placeholder";
|
||||
Text = "return true;";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Task<bool> IConditionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
|
@@ -8,7 +8,12 @@ namespace ThingsGateway.RulesEngine;
|
||||
[CategoryNode(Category = "Expression", ImgUrl = "_content/ThingsGateway.RulesEngine/img/CSharpScript.svg", Desc = nameof(DataNode), LocalizerType = typeof(ThingsGateway.RulesEngine._Imports), WidgetType = typeof(CSharpScriptWidget))]
|
||||
public class DataNode : TextNode, IExpressionNode
|
||||
{
|
||||
public DataNode(string id, Point? position = null) : base(id, position) { Title = "DataNode"; Placeholder = "DataNode.Placeholder"; }
|
||||
public DataNode(string id, Point? position = null) : base(id, position)
|
||||
{
|
||||
Title = "DataNode"; Placeholder = "DataNode.Placeholder";
|
||||
Text = "return 1;";
|
||||
|
||||
}
|
||||
|
||||
Task<NodeOutput> IExpressionNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
|
@@ -401,7 +401,7 @@ public partial class SiemensS7Master : DeviceBase
|
||||
var result2 = await GetResponsedDataAsync(new S7Send(ISO_CR), channel, Timeout).ConfigureAwait(false);
|
||||
if (!result2.IsSuccess)
|
||||
{
|
||||
Logger?.LogWarning(SiemensS7Resource.Localizer["HandshakeError1", channel.ToString(), result2.ErrorMessage]);
|
||||
Logger?.LogWarning(SiemensS7Resource.Localizer["HandshakeError1", channel.ToString(), result2]);
|
||||
await channel.CloseAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
@@ -409,7 +409,7 @@ public partial class SiemensS7Master : DeviceBase
|
||||
catch (OperationCanceledException) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogWarning(SiemensS7Resource.Localizer["HandshakeError1", channel.ToString(), ex.Message]);
|
||||
Logger?.LogWarning(SiemensS7Resource.Localizer["HandshakeError1", channel.ToString(), ex]);
|
||||
await channel.CloseAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
@@ -418,7 +418,12 @@ public partial class SiemensS7Master : DeviceBase
|
||||
var result2 = await GetResponsedDataAsync(new S7Send(S7_PN), channel, Timeout).ConfigureAwait(false);
|
||||
if (!result2.IsSuccess)
|
||||
{
|
||||
Logger?.LogWarning(SiemensS7Resource.Localizer["HandshakeError2", channel.ToString(), result2.ErrorMessage]);
|
||||
Logger?.LogWarning(SiemensS7Resource.Localizer["HandshakeError2", channel.ToString(), result2]);
|
||||
await channel.CloseAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
if (result2.Content == null)
|
||||
{
|
||||
await channel.CloseAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
@@ -429,7 +434,7 @@ public partial class SiemensS7Master : DeviceBase
|
||||
catch (OperationCanceledException) { }
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger?.LogWarning(SiemensS7Resource.Localizer["HandshakeError2", channel.ToString(), ex.Message]);
|
||||
Logger?.LogWarning(SiemensS7Resource.Localizer["HandshakeError2", channel.ToString(), ex]);
|
||||
await channel.CloseAsync().ConfigureAwait(false);
|
||||
return true;
|
||||
}
|
||||
|
@@ -25,11 +25,20 @@
|
||||
<div class="col-12 col-md-12">
|
||||
<BootstrapLabel Value=@SqlDBProducerPropertyLocalizer["BigTextScriptHistoryTable"] ShowLabelTooltip="true" />
|
||||
<CodeEditor @bind-Value=@businessProperty.BigTextScriptHistoryTable Language="csharp" Theme="vs-dark" />
|
||||
|
||||
<div class="ms-2 d-flex justify-content-center align-items-center">
|
||||
<Button IsDisabled=@(!CanWrite) OnClick="()=>CheckScript(businessProperty,nameof(businessProperty.BigTextScriptHistoryTable))">
|
||||
@RazorLocalizer["Check"]
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-md-12">
|
||||
<BootstrapLabel Value=@SqlDBProducerPropertyLocalizer["BigTextScriptRealTable"] ShowLabelTooltip="true" />
|
||||
<CodeEditor @bind-Value=@businessProperty.BigTextScriptRealTable Language="csharp" Theme="vs-dark" />
|
||||
<div class="ms-2 d-flex justify-content-center align-items-center">
|
||||
<Button IsDisabled=@(!CanWrite) OnClick="()=>CheckScript(businessProperty,nameof(businessProperty.BigTextScriptRealTable))">
|
||||
@RazorLocalizer["Check"]
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</EditTemplate>
|
||||
</EditorItem>
|
||||
|
@@ -8,17 +8,22 @@
|
||||
// QQ群:605534569
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
#pragma warning disable CA2007 // 考虑对等待的任务调用 ConfigureAwait
|
||||
using BootstrapBlazor.Components;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
using ThingsGateway.Gateway.Razor;
|
||||
using ThingsGateway.Plugin.SqlDB;
|
||||
using ThingsGateway.Razor;
|
||||
|
||||
namespace ThingsGateway.Debug
|
||||
{
|
||||
public partial class SqlDBProducerPropertyRazor : IPropertyUIBase
|
||||
{
|
||||
[Inject]
|
||||
IStringLocalizer<ThingsGateway.Razor._Imports> RazorLocalizer { get; set; }
|
||||
|
||||
|
||||
[Parameter, EditorRequired]
|
||||
@@ -39,6 +44,144 @@ namespace ThingsGateway.Debug
|
||||
return base.OnParametersSetAsync();
|
||||
}
|
||||
|
||||
private async Task CheckScript(SqlDBProducerProperty businessProperty, string pname)
|
||||
{
|
||||
IEnumerable<object> data = null;
|
||||
string script = null;
|
||||
{
|
||||
data = new List<VariableBasicData>() { new() {
|
||||
Name = "testName",
|
||||
DeviceName = "testDevice",
|
||||
Value = "1",
|
||||
ChangeTime = DateTime.Now,
|
||||
CollectTime = DateTime.Now,
|
||||
Remark1="1",
|
||||
Remark2="2",
|
||||
Remark3="3",
|
||||
Remark4="4",
|
||||
Remark5="5",
|
||||
} ,
|
||||
new() {
|
||||
Name = "testName2",
|
||||
DeviceName = "testDevice",
|
||||
Value = "1",
|
||||
ChangeTime = DateTime.Now,
|
||||
CollectTime = DateTime.Now,
|
||||
Remark1="1",
|
||||
Remark2="2",
|
||||
Remark3="3",
|
||||
Remark4="4",
|
||||
Remark5="5",
|
||||
} };
|
||||
script = pname == businessProperty.BigTextScriptHistoryTable ? businessProperty.BigTextScriptHistoryTable : businessProperty.BigTextScriptRealTable;
|
||||
|
||||
}
|
||||
|
||||
|
||||
var op = new DialogOption()
|
||||
{
|
||||
IsScrolling = true,
|
||||
Title = RazorLocalizer["Check"],
|
||||
ShowFooter = false,
|
||||
ShowCloseButton = false,
|
||||
Size = Size.ExtraExtraLarge,
|
||||
FullScreenSize = FullScreenSize.None
|
||||
};
|
||||
|
||||
op.Component = BootstrapDynamicComponent.CreateComponent<ScriptCheck>(new Dictionary<string, object?>
|
||||
{
|
||||
{nameof(ScriptCheck.Data),data },
|
||||
{nameof(ScriptCheck.Script),script },
|
||||
{nameof(ScriptCheck.OnGetDemo),()=>
|
||||
{
|
||||
return
|
||||
pname == nameof(SqlDBProducerProperty.BigTextScriptHistoryTable)?
|
||||
""""
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
using System.Dynamic;
|
||||
|
||||
using TouchSocket.Core;
|
||||
public class S1 : DynamicSQLBase
|
||||
{
|
||||
|
||||
public override async Task DBInit(ISqlSugarClient db, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var sql = $"""
|
||||
|
||||
""";
|
||||
await db.Ado.ExecuteCommandAsync(sql, default, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task DBInsertable(ISqlSugarClient db, IEnumerable<object> datas, CancellationToken cancellationToken)
|
||||
{
|
||||
var sql = $"""
|
||||
|
||||
""";
|
||||
await db.Ado.ExecuteCommandAsync(sql, default, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
""""
|
||||
:
|
||||
|
||||
pname == nameof(SqlDBProducerProperty.BigTextScriptRealTable)?
|
||||
|
||||
""""
|
||||
|
||||
using System.Dynamic;
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
|
||||
using TouchSocket.Core;
|
||||
public class S1 : DynamicSQLBase
|
||||
{
|
||||
|
||||
public override async Task DBInit(ISqlSugarClient db, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var sql = $"""
|
||||
|
||||
""";
|
||||
await db.Ado.ExecuteCommandAsync(sql, default, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
public override async Task DBInsertable(ISqlSugarClient db, IEnumerable<object> datas, CancellationToken cancellationToken)
|
||||
{
|
||||
var sql = $"""
|
||||
|
||||
""";
|
||||
await db.Ado.ExecuteCommandAsync(sql, default, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
""""
|
||||
:
|
||||
""
|
||||
;
|
||||
}
|
||||
},
|
||||
{nameof(ScriptCheck.ScriptChanged),EventCallback.Factory.Create<string>(this, v =>
|
||||
{
|
||||
if (pname == nameof(SqlDBProducerProperty.BigTextScriptHistoryTable))
|
||||
{
|
||||
businessProperty.BigTextScriptHistoryTable=v;
|
||||
|
||||
}
|
||||
}
|
||||
else if (pname == nameof(SqlDBProducerProperty.BigTextScriptRealTable))
|
||||
{
|
||||
businessProperty.BigTextScriptRealTable=v;
|
||||
}
|
||||
|
||||
}) },
|
||||
|
||||
});
|
||||
await DialogService.Show(op);
|
||||
|
||||
}
|
||||
[Inject]
|
||||
DialogService DialogService { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -46,7 +46,6 @@ namespace ThingsGateway.Plugin.Mqtt
|
||||
if (mqttClientProperty.TLS == true)
|
||||
{
|
||||
{
|
||||
|
||||
var filePath = Path.Combine("PluginFile", Id, nameof(mqttClientProperty.CAFile));
|
||||
if (!Directory.Exists(filePath))//如果不存在就创建文件夹
|
||||
Directory.CreateDirectory(filePath);
|
||||
@@ -230,7 +229,6 @@ namespace ThingsGateway.Plugin.Mqtt
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var op = new DialogOption()
|
||||
{
|
||||
IsScrolling = true,
|
||||
@@ -245,6 +243,142 @@ namespace ThingsGateway.Plugin.Mqtt
|
||||
{
|
||||
{nameof(ScriptCheck.Data),data },
|
||||
{nameof(ScriptCheck.Script),script },
|
||||
{nameof(ScriptCheck.OnGetDemo),()=>
|
||||
{
|
||||
return
|
||||
pname == nameof(BusinessPropertyWithCacheIntervalScript.BigTextScriptDeviceModel)?
|
||||
"""
|
||||
|
||||
using TouchSocket.Core;
|
||||
public class S1 : IDynamicModel
|
||||
{
|
||||
public IEnumerable<dynamic> GetList(IEnumerable<object> datas)
|
||||
{
|
||||
List<ExpandoObject> deviceObjs = new List<ExpandoObject>();
|
||||
foreach (var v in datas)
|
||||
{
|
||||
var device = (DeviceBasicData)v;
|
||||
var expando = new ExpandoObject();
|
||||
var deviceObj = new ExpandoObject();
|
||||
|
||||
deviceObj.TryAdd(nameof(Device.Description), device.Description);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.ActiveTime), device.ActiveTime);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.DeviceStatus), device.DeviceStatus.ToString());
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.LastErrorMessage), device.LastErrorMessage);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.PluginName), device.PluginName);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark1), device.Remark1);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark2), device.Remark2);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark3), device.Remark3);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark4), device.Remark4);
|
||||
deviceObj.TryAdd(nameof(DeviceBasicData.Remark5), device.Remark5);
|
||||
|
||||
|
||||
expando.TryAdd(nameof(Device.Name), deviceObj);
|
||||
|
||||
}
|
||||
return deviceObjs;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
:
|
||||
|
||||
pname == nameof(BusinessPropertyWithCacheIntervalScript.BigTextScriptVariableModel)?
|
||||
|
||||
"""
|
||||
|
||||
using TouchSocket.Core;
|
||||
public class S2 : IDynamicModel
|
||||
{
|
||||
public IEnumerable<dynamic> GetList(IEnumerable<object> datas)
|
||||
{
|
||||
|
||||
List<ExpandoObject> deviceObjs = new List<ExpandoObject>();
|
||||
//按设备名称分组
|
||||
var groups = datas.Where(a => !string.IsNullOrEmpty(((VariableBasicData)a).DeviceName)).GroupBy(a => ((VariableBasicData)a).DeviceName, a => ((VariableBasicData)a));
|
||||
foreach (var group in groups)
|
||||
{
|
||||
//按采集时间分组
|
||||
var data = group.GroupBy(a => a.CollectTime.DateTimeToUnixTimestamp());
|
||||
var deviceObj = new ExpandoObject();
|
||||
List<ExpandoObject> expandos = new List<ExpandoObject>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
var expando = new ExpandoObject();
|
||||
expando.TryAdd("ts", item.Key);
|
||||
var variableObj = new ExpandoObject();
|
||||
foreach (var tag in item)
|
||||
{
|
||||
variableObj.TryAdd(tag.Name, tag.Value);
|
||||
}
|
||||
expando.TryAdd("values", variableObj);
|
||||
|
||||
expandos.Add(expando);
|
||||
}
|
||||
deviceObj.TryAdd(group.Key, expandos);
|
||||
deviceObjs.Add(deviceObj);
|
||||
}
|
||||
|
||||
return deviceObjs;
|
||||
}
|
||||
}
|
||||
|
||||
"""
|
||||
:
|
||||
|
||||
pname == nameof(BusinessPropertyWithCacheIntervalScript.BigTextScriptAlarmModel)?
|
||||
|
||||
"""
|
||||
|
||||
using TouchSocket.Core;
|
||||
public class DeviceScript : IDynamicModel
|
||||
{
|
||||
public IEnumerable<dynamic> GetList(IEnumerable<object> datas)
|
||||
{
|
||||
|
||||
List<ExpandoObject> deviceObjs = new List<ExpandoObject>();
|
||||
//按设备名称分组
|
||||
var groups = datas.Where(a => !string.IsNullOrEmpty(((AlarmVariable)a).DeviceName)).GroupBy(a => ((AlarmVariable)a).DeviceName, a => ((AlarmVariable)a));
|
||||
foreach (var group in groups)
|
||||
{
|
||||
//按采集时间分组
|
||||
var data = group.GroupBy(a => a.AlarmTime.DateTimeToUnixTimestamp());
|
||||
var deviceObj = new ExpandoObject();
|
||||
List<ExpandoObject> expandos = new List<ExpandoObject>();
|
||||
foreach (var item in data)
|
||||
{
|
||||
var expando = new ExpandoObject();
|
||||
expando.TryAdd("ts", item.Key);
|
||||
var variableObj = new ExpandoObject();
|
||||
foreach (var tag in item)
|
||||
{
|
||||
var alarmObj = new ExpandoObject();
|
||||
alarmObj.TryAdd(nameof(tag.AlarmCode), tag.AlarmCode);
|
||||
alarmObj.TryAdd(nameof(tag.AlarmText), tag.AlarmText);
|
||||
alarmObj.TryAdd(nameof(tag.AlarmType), tag.AlarmType);
|
||||
alarmObj.TryAdd(nameof(tag.AlarmLimit), tag.AlarmLimit);
|
||||
alarmObj.TryAdd(nameof(tag.EventTime), tag.EventTime);
|
||||
alarmObj.TryAdd(nameof(tag.EventType), tag.EventType);
|
||||
|
||||
variableObj.TryAdd(tag.Name, alarmObj);
|
||||
}
|
||||
expando.TryAdd("alarms", variableObj);
|
||||
|
||||
expandos.Add(expando);
|
||||
}
|
||||
deviceObj.TryAdd(group.Key, expandos);
|
||||
deviceObjs.Add(deviceObj);
|
||||
}
|
||||
|
||||
return deviceObjs;
|
||||
}
|
||||
}
|
||||
"""
|
||||
:
|
||||
""
|
||||
;
|
||||
}
|
||||
},
|
||||
{nameof(ScriptCheck.ScriptChanged),EventCallback.Factory.Create<string>(this, v =>
|
||||
{
|
||||
if (pname == nameof(BusinessPropertyWithCacheIntervalScript.BigTextScriptAlarmModel))
|
||||
@@ -269,6 +403,7 @@ namespace ThingsGateway.Plugin.Mqtt
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Inject]
|
||||
private DialogService DialogService { get; set; }
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>10.5.12</Version>
|
||||
<Version>10.5.13</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Reference in New Issue
Block a user