调整MqttRpc提示

This commit is contained in:
Kimdiego2098
2024-01-24 16:15:26 +08:00
parent 6be4dc4aac
commit 18bad2af25
5 changed files with 13 additions and 8 deletions

View File

@@ -12,6 +12,8 @@
#endregion
using Newtonsoft.Json;
namespace ThingsGateway.Foundation;
/// <inheritdoc/>
@@ -116,6 +118,7 @@ public class OperResult : IOperResult
/// <summary>
/// 异常堆栈
/// </summary>
[JsonIgnore]
public Exception? Exception;
/// <summary>

View File

@@ -157,7 +157,8 @@ public partial class MqttClient : BusinessBaseWithCacheIntervalScript<VariableDa
if (!_driverPropertys.DeviceRpcEnable || string.IsNullOrEmpty(args.ClientId))
return;
if (args.ApplicationMessage.Topic != _driverPropertys.RpcWriteTopic)
var t = string.Format(TgMqttRpcClientTopicGenerationStrategy.RpcTopic, _driverPropertys.RpcWriteTopic);
if (MqttTopicFilterComparer.Compare(args.ApplicationMessage.Topic, t) != MqttTopicFilterCompareResult.IsMatch)
return;
var rpcDatas = Encoding.UTF8.GetString(args.ApplicationMessage.PayloadSegment).FromJsonString<Dictionary<string, string>>();
if (rpcDatas == null)
@@ -169,7 +170,7 @@ public partial class MqttClient : BusinessBaseWithCacheIntervalScript<VariableDa
if (isConnect.IsSuccess)
{
var variableMessage = new MqttApplicationMessageBuilder()
.WithTopic($"{args.ApplicationMessage.Topic}/response")
.WithTopic($"{args.ApplicationMessage.Topic}/Response")
.WithPayload(mqttRpcResult.ToJsonString(true)).Build();
await _mqttClient.PublishAsync(variableMessage);
}
@@ -190,7 +191,7 @@ public partial class MqttClient : BusinessBaseWithCacheIntervalScript<VariableDa
if (tag != null)
{
var rpcEnable = tag.GetPropertyValue(DeviceId, nameof(_variablePropertys.VariableRpcEnable))?.Value?.ToBoolean();
if (rpcEnable != true)
if (rpcEnable == false)
{
mqttRpcResult.Add(rpcData.Key, new("权限不足,变量不支持写入"));
}

View File

@@ -80,7 +80,7 @@ public class MqttClientProperty : BusinessPropertyWithCacheIntervalScript
/// <summary>
/// Rpc写入Topic
/// </summary>
[DynamicProperty("Rpc写入Topic", "实际的写入主题为固定通配 {ThingsGateway/+/[RpcWrite]} ,RpcWrite为该属性填入内容+GUID值Response , {ThingsGateway/+/[RpcWrite]/Response}")]
[DynamicProperty("Rpc写入Topic", "实际的写入主题为固定通配 {ThingsGateway.Rpc/+/[RpcWrite]} ,RpcWrite为该属性填入内容+GUID值Response , {ThingsGateway.Rpc/+/[RpcWrite]/Response}")]
public string RpcWriteTopic
{
get

View File

@@ -121,7 +121,8 @@ public partial class MqttServer : BusinessBaseWithCacheIntervalScript<VariableDa
{
if (!_driverPropertys.DeviceRpcEnable || string.IsNullOrEmpty(args.ClientId))
return;
if (args.ApplicationMessage.Topic != _driverPropertys.RpcWriteTopic)
var t = string.Format(TgMqttRpcClientTopicGenerationStrategy.RpcTopic, _driverPropertys.RpcWriteTopic);
if (MqttTopicFilterComparer.Compare(args.ApplicationMessage.Topic, t) != MqttTopicFilterCompareResult.IsMatch)
return;
var rpcDatas = Encoding.UTF8.GetString(args.ApplicationMessage.PayloadSegment).FromJsonString<Dictionary<string, string>>();
if (rpcDatas == null)
@@ -131,7 +132,7 @@ public partial class MqttServer : BusinessBaseWithCacheIntervalScript<VariableDa
try
{
var variableMessage = new MqttApplicationMessageBuilder()
.WithTopic($"{args.ApplicationMessage.Topic}/response")
.WithTopic($"{args.ApplicationMessage.Topic}/Response")
.WithPayload(mqttRpcResult.ToJsonString(true)).Build();
await _mqttServer.InjectApplicationMessage(
new InjectedMqttApplicationMessage(variableMessage));
@@ -152,7 +153,7 @@ public partial class MqttServer : BusinessBaseWithCacheIntervalScript<VariableDa
if (tag != null)
{
var rpcEnable = tag.GetPropertyValue(DeviceId, nameof(_variablePropertys.VariableRpcEnable))?.Value?.ToBoolean();
if (rpcEnable != true)
if (rpcEnable == false)
{
mqttRpcResult.Add(rpcData.Key, new("权限不足,变量不支持写入"));
}

View File

@@ -56,7 +56,7 @@ public class MqttServerProperty : BusinessPropertyWithCacheIntervalScript
/// <summary>
/// Rpc写入Topic
/// </summary>
[DynamicProperty("Rpc写入Topic", "实际的写入主题为固定通配 {ThingsGateway/+/[RpcWrite]} ,RpcWrite为该属性填入内容+GUID值Response , {ThingsGateway/+/[RpcWrite]/Response}")]
[DynamicProperty("Rpc写入Topic", "实际的写入主题为固定通配 {ThingsGateway.Rpc/+/[RpcWrite]} ,RpcWrite为该属性填入内容+GUID值Response , {ThingsGateway.Rpc/+/[RpcWrite]/Response}")]
public string RpcWriteTopic
{
get