初步完成MQTT消息的发送
This commit is contained in:
@@ -4,6 +4,7 @@ using DMS.Application.Interfaces;
|
||||
using DMS.Core.Interfaces;
|
||||
using System.Collections.Concurrent;
|
||||
using DMS.Application.DTOs.Events;
|
||||
using DMS.Core.Models;
|
||||
|
||||
namespace DMS.Application.Services;
|
||||
|
||||
@@ -85,6 +86,20 @@ public class DataLoaderService : IDataLoaderService
|
||||
foreach (var variableMqttAliasDto in variableMqttAliasDtos)
|
||||
{
|
||||
_appDataStorageService.VariableMqttAliases.TryAdd(variableMqttAliasDto.Id, variableMqttAliasDto);
|
||||
if (_appDataStorageService.Variables.TryGetValue(variableMqttAliasDto.VariableId, out var variable))
|
||||
{
|
||||
variableMqttAliasDto.Variable = _mapper.Map<Variable>(variable);
|
||||
variable.MqttAliases?.Add(variableMqttAliasDto);
|
||||
}
|
||||
|
||||
if (_appDataStorageService.MqttServers.TryGetValue(variableMqttAliasDto.MqttServerId, out var mqttServer))
|
||||
{
|
||||
variableMqttAliasDto.MqttServer = _mapper.Map<MqttServer>(mqttServer);
|
||||
variableMqttAliasDto.MqttServerName = variableMqttAliasDto.MqttServer.ServerName;
|
||||
mqttServer.VariableAliases?.Add(variableMqttAliasDto);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -238,9 +238,10 @@ namespace DMS.Infrastructure.Services
|
||||
try
|
||||
{
|
||||
var topic = context.MqttServer.PublishTopic;
|
||||
var payload = variableMqtt.Variable.DataValue?.ToString() ?? string.Empty;
|
||||
|
||||
await context.MqttService.PublishAsync(topic, payload);
|
||||
var sendMsg = $"{variableMqtt.Variable.Name}:{variableMqtt.Variable.DataValue}";
|
||||
|
||||
await context.MqttService.PublishAsync(topic, sendMsg);
|
||||
_logger.LogDebug("成功向MQTT服务器 {ServerName} 发布变量 {VariableName} 的数据",
|
||||
context.MqttServer.ServerName, variableMqtt.Variable.Name);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace DMS.WPF.Profiles
|
||||
.ReverseMap();
|
||||
|
||||
CreateMap<MqttServerDto, MqttServerItemViewModel>().ReverseMap();
|
||||
CreateMap<MqttServer, MqttServerItemViewModel>().ReverseMap();
|
||||
CreateMap<UserDto, UserItemViewModel>().ReverseMap();
|
||||
CreateMap<VariableHistoryDto, VariableHistoryItemViewModel>().ReverseMap();
|
||||
CreateMap<VariableDto, VariableItemViewModel>().ReverseMap();
|
||||
|
||||
Reference in New Issue
Block a user