2025-06-12 20:21:50 +08:00
|
|
|
|
|
|
|
|
|
|
using ThingsGateway.Blazor.Diagrams.Core.Geometry;
|
2025-02-10 09:32:02 +08:00
|
|
|
|
|
|
|
|
|
|
using TouchSocket.Core;
|
|
|
|
|
|
|
2025-06-12 20:21:50 +08:00
|
|
|
|
namespace ThingsGateway.Gateway.Application;
|
2025-02-10 09:32:02 +08:00
|
|
|
|
|
2025-06-12 20:21:50 +08:00
|
|
|
|
[CategoryNode(Category = "Actuator", ImgUrl = "_content/ThingsGateway.Gateway.Razor/img/Rpc.svg", Desc = nameof(VariableRpcNode), LocalizerType = typeof(ThingsGateway.Gateway.Application.DefaultDiagram), WidgetType = "ThingsGateway.Gateway.Razor.VariableWidget,ThingsGateway.Gateway.Razor")]
|
2025-03-04 21:09:11 +08:00
|
|
|
|
public class VariableRpcNode : VariableNode, IActuatorNode
|
2025-02-10 09:32:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public VariableRpcNode(string id, Point? position = null) : base(id, position)
|
2025-03-05 11:26:38 +08:00
|
|
|
|
{ Title = "VariableRpcNode"; }
|
2025-02-10 09:32:02 +08:00
|
|
|
|
|
2025-06-23 21:21:27 +08:00
|
|
|
|
async Task<OperResult<NodeOutput>> IActuatorNode.ExecuteAsync(NodeInput input, CancellationToken cancellationToken)
|
2025-02-10 09:32:02 +08:00
|
|
|
|
{
|
2025-06-23 21:21:27 +08:00
|
|
|
|
try
|
2025-02-10 09:32:02 +08:00
|
|
|
|
{
|
2025-06-23 21:21:27 +08:00
|
|
|
|
|
|
|
|
|
|
if ((!DeviceText.IsNullOrWhiteSpace()) && GlobalData.ReadOnlyDevices.TryGetValue(DeviceText, out var device))
|
2025-03-04 21:09:11 +08:00
|
|
|
|
{
|
2025-06-23 21:21:27 +08:00
|
|
|
|
if (device.ReadOnlyVariableRuntimes.TryGetValue(Text, out var value))
|
|
|
|
|
|
{
|
|
|
|
|
|
var data = await value.RpcAsync(input.JToken.ToString(), $"RulesEngine: {RulesEngineName}", cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
if (data.IsSuccess)
|
|
|
|
|
|
Logger?.Trace($" VariableRpcNode - VariableName {Text} : execute success");
|
|
|
|
|
|
else
|
|
|
|
|
|
Logger?.Warning($" VariableRpcNode - VariableName {Text} : {data.ErrorMessage}");
|
|
|
|
|
|
return new OperResult<NodeOutput>() { Content = new NodeOutput() { Value = data } };
|
|
|
|
|
|
}
|
2025-03-04 21:09:11 +08:00
|
|
|
|
}
|
2025-06-23 21:21:27 +08:00
|
|
|
|
Logger?.Warning($" VariableRpcNode - VariableName {Text} : not found");
|
|
|
|
|
|
|
|
|
|
|
|
return new OperResult<NodeOutput>() { Content = new NodeOutput() { } };
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logger?.LogWarning(ex);
|
|
|
|
|
|
return new OperResult<NodeOutput>(ex);
|
2025-02-10 09:32:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|